Skip to content

Commit

Permalink
feat: icon txn result (#78)
Browse files Browse the repository at this point in the history
* feat: Add method to get ports

* feat: Fix get txn result for icon

* fix: Do not get result for update client on goroutine

* fix: refractor and handle for channelclose init message

---------

Co-authored-by: izyak <[email protected]>
Co-authored-by: viveksharmapoudel <[email protected]>
  • Loading branch information
3 people authored and izyak committed Sep 7, 2023
1 parent 0d167ad commit 8893f5e
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 128 deletions.
2 changes: 0 additions & 2 deletions relayer/chains/icon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func (c *Client) WaitForResults(ctx context.Context, thp *types.TransactionHashP
return
}
retryCounter++
//c.log.Debugf("GetTransactionResult Attempt: %d", retryCounter)
txr, err = c.GetTransactionResult(thp)
if err != nil {
switch re := err.(type) {
Expand All @@ -162,7 +161,6 @@ func (c *Client) WaitForResults(ctx context.Context, thp *types.TransactionHashP
}
}
}
//c.log.Debugf("GetTransactionResult hash:%v, txr:%+v, err:%+v", thp.Hash, txr, err)
return
}
}
Expand Down
33 changes: 33 additions & 0 deletions relayer/chains/icon/client_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package icon

import (
"context"
"fmt"
"io/ioutil"
"path/filepath"
"testing"
"time"

Expand All @@ -22,6 +24,28 @@ func NewTestClient() *Client {
return NewClient(uri, l)
}

func GetLisbonIconProvider(network_id int, contractAddress string) *IconProvider {

absPath, _ := filepath.Abs("../../../env/godWallet.json")

pcfg := IconProviderConfig{
Keystore: absPath,
ChainID: "icon",
Password: "gochain",
ICONNetworkID: 2,
BTPNetworkID: int64(network_id),
BTPNetworkTypeID: 1,
IbcHandlerAddress: contractAddress,
RPCAddr: "https://lisbon.net.solidwallet.io/api/v3",
Timeout: "20s",
}
log, _ := zap.NewProduction()
p, _ := pcfg.NewProvider(log, "", false, "icon")

iconProvider, _ := p.(*IconProvider)
return iconProvider
}

func getTestWallet() (module.Wallet, error) {

keyStore_file := "../../../env/godWallet.json"
Expand Down Expand Up @@ -51,6 +75,15 @@ func TestClientSetup(t *testing.T) {
assert.Equal(t, types.HexInt("0x1"), res.Status)
}

func TestSendMessageToMempool(t *testing.T) {
c := GetLisbonIconProvider(1, "cx6e24351b49133f2337a01c968cb864958ffadce8")
ctx := context.Background()
msg := c.NewIconMessage(map[string]interface{}{}, "sendEvent")
resp, _, err := c.SendMessage(ctx, msg, "memo")
assert.NoError(t, err)
assert.Equal(t, resp.Code, uint32(1))
}

func TestTransaction(t *testing.T) {

c := NewTestClient()
Expand Down
9 changes: 6 additions & 3 deletions relayer/chains/icon/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ var BtpHeaderRequiredEvents map[string]struct{} = map[string]struct{}{
EventTypeConnectionOpenTry: {},
EventTypeConnectionOpenAck: {},

EventTypeChannelOpenInit: {},
EventTypeChannelOpenTry: {},
EventTypeChannelOpenAck: {},
EventTypeChannelOpenInit: {},
EventTypeChannelOpenTry: {},
EventTypeChannelOpenAck: {},
EventTypeChannelCloseInit: {},
}

var MonitorEvents []string = []string{
Expand All @@ -122,6 +123,8 @@ var MonitorEvents []string = []string{
EventTypeChannelOpenTry,
EventTypeChannelOpenAck,
EventTypeChannelOpenConfirm,
EventTypeChannelCloseInit,
EventTypeChannelCloseConfirm,

//no BTP block produced
EventTypeRecvPacket,
Expand Down
1 change: 1 addition & 0 deletions relayer/chains/icon/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ const (
MethodGetNextChannelSequence = "getNextChannelSequence"
MethodGetNextConnectionSequence = "getNextConnectionSequence"


MethodGetAllPorts = "getAllPorts"
)
2 changes: 1 addition & 1 deletion relayer/chains/icon/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (icp *IconProvider) NewIconMessage(msg interface{}, method string) provider
Method: method,
}

icp.log.Debug("Icon Message ", zap.String("Method name", method), zap.Any("Value ", msg))
icp.log.Debug("Icon Message ", zap.String("method", method), zap.Any("message ", msg))

return im
}
27 changes: 0 additions & 27 deletions relayer/chains/icon/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,33 +451,6 @@ func (icp *IconProvider) MsgSubmitMisbehaviour(clientID string, misbehaviour ibc
return nil, fmt.Errorf("Not implemented")
}

func (icp *IconProvider) SendMessagesToMempool(
ctx context.Context,
msgs []provider.RelayerMessage,
memo string,
asyncCtx context.Context,
asyncCallback func(*provider.RelayerTxResponse, error),
) error {
if len(msgs) == 0 {
icp.log.Info("Length of Messages is empty ")
return nil
}

for _, msg := range msgs {
if msg != nil {
res, bool, err := icp.SendMessage(ctx, msg, memo)
if err != nil {
return err
}
if !bool {
return fmt.Errorf("Transaction Failed, Transaction Hash: %x", res.TxHash)
}
}
}

return nil
}

func (icp *IconProvider) ChainName() string {
return icp.PCfg.ChainName
}
Expand Down
5 changes: 5 additions & 0 deletions relayer/chains/icon/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,11 @@ func (icp *IconProvider) QueryChannels(ctx context.Context) ([]*chantypes.Identi
continue
}

if _channel == "" {
icp.log.Debug("channel not present for ", zap.String("Channel id ", channelId), zap.String("port id ", portId))
continue
}

var channel chantypes.Channel
_, err = HexBytesToProtoUnmarshal(_channel, &channel)
if err != nil {
Expand Down
Loading

0 comments on commit 8893f5e

Please sign in to comment.