From 242e516b8cd38c8e00db0097b40fd10533104303 Mon Sep 17 00:00:00 2001 From: izyak <76203436+izyak@users.noreply.github.com> Date: Mon, 14 Aug 2023 10:24:42 +0545 Subject: [PATCH] feat: icon key refactor (#140) * fix: change way of handling keystore on icon * feat: wallet and deletion * fix: handle keys delete on icon * chore: config sample files updated --------- Co-authored-by: izyak --- cmd/keys.go | 9 +- examples/config_IBC_ICON.yaml | 14 +- examples/demo/configs/chains/ibc-icon.json | 30 ++-- examples/demo/configs/chains/ibc-wasm.json | 29 ++-- examples/demo/configs/paths/icon-archway.json | 2 +- relayer/chain.go | 2 +- relayer/chains/cosmos/keys.go | 2 +- relayer/chains/icon/keys.go | 144 ++++++++++++------ relayer/chains/icon/keys_test.go | 57 +++---- relayer/chains/icon/provider.go | 49 +++--- relayer/chains/icon/query.go | 2 +- relayer/chains/icon/tx.go | 10 +- relayer/chains/mock/mock_chain_processor.go | 2 +- relayer/chains/penumbra/keys.go | 2 +- relayer/chains/wasm/keys.go | 2 +- relayer/provider/provider.go | 2 +- 16 files changed, 216 insertions(+), 142 deletions(-) diff --git a/cmd/keys.go b/cmd/keys.go index 0ddd447d4..3f7380141 100644 --- a/cmd/keys.go +++ b/cmd/keys.go @@ -32,6 +32,7 @@ import ( const ( flagCoinType = "coin-type" flagAlgo = "signing-algorithm" + flagPassword = "password" defaultCoinType uint32 = sdk.CoinType ) @@ -97,6 +98,11 @@ $ %s k a cosmoshub testkey`, appName, appName, appName)), return err } + password, err := cmdFlags.GetString(flagPassword) + if err != nil { + return err + } + if algo == "" { if ccp, ok := chain.ChainProvider.(*cosmos.CosmosProvider); ok { algo = ccp.PCfg.SigningAlgorithm @@ -105,7 +111,7 @@ $ %s k a cosmoshub testkey`, appName, appName, appName)), } } - ko, err := chain.ChainProvider.AddKey(keyName, uint32(coinType), algo) + ko, err := chain.ChainProvider.AddKey(keyName, uint32(coinType), algo, password) if err != nil { return fmt.Errorf("failed to add key: %w", err) } @@ -121,6 +127,7 @@ $ %s k a cosmoshub testkey`, appName, appName, appName)), } cmd.Flags().Int32(flagCoinType, -1, "coin type number for HD derivation") cmd.Flags().String(flagAlgo, "", "signing algorithm for key (secp256k1, sr25519)") + cmd.Flags().String(flagPassword, "x", "icon keystore password") return cmd } diff --git a/examples/config_IBC_ICON.yaml b/examples/config_IBC_ICON.yaml index f6a917792..d0f69c19b 100644 --- a/examples/config_IBC_ICON.yaml +++ b/examples/config_IBC_ICON.yaml @@ -7,7 +7,7 @@ chains: archway: type: wasm value: - key-directory: /home/user/.relayer/keys/localnet + key-directory: /home/user/.relayer/keys key: relayWallet chain-id: localnet rpc-addr: http://localhost:26657 @@ -24,24 +24,24 @@ chains: extra-codecs: [] coin-type: 0 broadcast-mode: batch - ibc-handler-address: archway14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sy85n2u + ibc-handler-address: archway1pvrwmjuusn9wh34j7y520g8gumuy9xtl3gvprlljfdpwju3x7ucszwhc7n first-retry-block-after: 0 start-height: 0 - block-interval: 6000 + block-interval: 3000 icon: type: icon value: - key: "" + key-directory: /home/user/.relayer/keys chain-id: ibc-icon rpc-addr: http://localhost:9082/api/v3/ timeout: 30s - keystore: /home/user/keystore/godWallet.json + keystore: godWallet password: gochain icon-network-id: 3 btp-network-id: 1 btp-network-type-id: 1 start-height: 0 - ibc-handler-address: cxa1daa337788364a72644860a5097e3eef7a5d416 + ibc-handler-address: cxbeb5929616e0dbd2fec1e6e950ab09e45e6fb25a first-retry-block-after: 0 block-interval: 2000 paths: @@ -56,4 +56,4 @@ paths: connection-id: connection-0 src-channel-filter: rule: "" - channel-list: [] \ No newline at end of file + channel-list: [] diff --git a/examples/demo/configs/chains/ibc-icon.json b/examples/demo/configs/chains/ibc-icon.json index 851e0a78e..b607006e1 100644 --- a/examples/demo/configs/chains/ibc-icon.json +++ b/examples/demo/configs/chains/ibc-icon.json @@ -1,16 +1,18 @@ { - "type": "icon", - "value": { - "chain-id": "ibc-icon", - "rpc-addr": "http://localhost:9082/api/v3/", - "timeout": "30s", - "keystore":"/Users/viveksharmapoudel/keystore/godWallet.json", - "password":"gochain", - "btp-network-id":2, - "icon-network-id":3, - "start-height":0, - "ibc-handler-address":"cxfffe383e4780084e48e477935099b03193d952fe", - "block-interval":2000, - "first-retry-block-after":8 - } + "type": "icon", + "value": { + "key-directory": "/home/user/.relayer/keys", + "chain-id": "ibc-icon", + "rpc-addr": "http://localhost:9082/api/v3/", + "timeout": "30s", + "keystore": "godWallet", + "password": "gochain", + "icon-network-id": 3, + "btp-network-id": 2, + "btp-network-type-id": 1, + "start-height": 0, + "ibc-handler-address": "cxbeb5929616e0dbd2fec1e6e950ab09e45e6fb25a", + "first-retry-block-after": 0, + "block-interval": 2000 + } } \ No newline at end of file diff --git a/examples/demo/configs/chains/ibc-wasm.json b/examples/demo/configs/chains/ibc-wasm.json index b4f19e508..d0f6bbe3a 100644 --- a/examples/demo/configs/chains/ibc-wasm.json +++ b/examples/demo/configs/chains/ibc-wasm.json @@ -1,25 +1,26 @@ { "type": "wasm", "value": { - "key": "default", - "chain-id": "test-1", - "rpc-addr": "https://rpc.constantine-2.archway.tech:443", - "key-directory":"/Users/viveksharmapoudel/.relayer/keys/test-1", - "grpc-addr": "", - "account-prefix": "neutron", + "key-directory": "/home/user/.relayer/keys", + "key": "relayWallet", + "chain-id": "localnet", + "rpc-addr": "http://localhost:26657", + "account-prefix": "archway", "keyring-backend": "test", "gas-adjustment": 1.5, - "gas-prices": "0.02uconst", + "gas-prices": "0.025stake", + "min-gas-amount": 1000000, "debug": true, "timeout": "20s", + "block-timeout": "", "output-format": "json", "sign-mode": "direct", - "ibc-handler-address":"neutron1fde8lfydxgwg6p7xe9ugx5a6ysj37zfvn9m9z5rxt4mqvdcneczsczq2a4", + "extra-codecs": [], + "coin-type": 0, "broadcast-mode": "batch", - "block-timeout": "", - "start-height":0, - "block-interval": 6000 + "ibc-handler-address": "archway1pvrwmjuusn9wh34j7y520g8gumuy9xtl3gvprlljfdpwju3x7ucszwhc7n", + "first-retry-block-after": 0, + "start-height": 0, + "block-interval": 3000 } -} - - +} \ No newline at end of file diff --git a/examples/demo/configs/paths/icon-archway.json b/examples/demo/configs/paths/icon-archway.json index 51d4d7f0c..9a12e583a 100644 --- a/examples/demo/configs/paths/icon-archway.json +++ b/examples/demo/configs/paths/icon-archway.json @@ -3,7 +3,7 @@ "chain-id": "ibc-icon" }, "dst": { - "chain-id": "constantine-2" + "chain-id": "localnet" }, "src-channel-filter": { "rule": null, diff --git a/relayer/chain.go b/relayer/chain.go index bb0195fb8..d7948786a 100644 --- a/relayer/chain.go +++ b/relayer/chain.go @@ -149,7 +149,7 @@ func (c *Chain) CreateTestKey() error { if c.ChainProvider.KeyExists(c.ChainProvider.Key()) { return fmt.Errorf("key {%s} exists for chain {%s}", c.ChainProvider.Key(), c.ChainID()) } - _, err := c.ChainProvider.AddKey(c.ChainProvider.Key(), defaultCoinType, defaultAlgo) + _, err := c.ChainProvider.AddKey(c.ChainProvider.Key(), defaultCoinType, defaultAlgo, "") return err } diff --git a/relayer/chains/cosmos/keys.go b/relayer/chains/cosmos/keys.go index 0ccdd0938..6cd4a60bf 100644 --- a/relayer/chains/cosmos/keys.go +++ b/relayer/chains/cosmos/keys.go @@ -61,7 +61,7 @@ func (cc *CosmosProvider) KeystoreCreated(path string) bool { // AddKey generates a new mnemonic which is then converted to a private key and BIP-39 HD Path and persists it to the keystore. // It fails if there is an existing key with the same address. -func (cc *CosmosProvider) AddKey(name string, coinType uint32, signingAlgorithm string) (output *provider.KeyOutput, err error) { +func (cc *CosmosProvider) AddKey(name string, coinType uint32, signingAlgorithm string, password string) (output *provider.KeyOutput, err error) { ko, err := cc.KeyAddOrRestore(name, coinType, signingAlgorithm) if err != nil { return nil, err diff --git a/relayer/chains/icon/keys.go b/relayer/chains/icon/keys.go index 9bfda64a6..878422c61 100644 --- a/relayer/chains/icon/keys.go +++ b/relayer/chains/icon/keys.go @@ -1,9 +1,12 @@ package icon import ( + "encoding/json" "fmt" "log" "os" + "path" + "strings" "github.com/cosmos/relayer/v2/relayer/provider" glcrypto "github.com/icon-project/goloop/common/crypto" @@ -12,7 +15,7 @@ import ( ) func (cp *IconProvider) CreateKeystore(path string) error { - _, e := generateKeystoreWithPassword(path, []byte("gochain")) + _, e := cp.generateKeystoreWithPassword(path, "gochain") return e } @@ -20,50 +23,82 @@ func (cp *IconProvider) KeystoreCreated(path string) bool { return false } -func (cp *IconProvider) AddKey(name string, coinType uint32, signingAlgorithm string) (output *provider.KeyOutput, err error) { - return nil, fmt.Errorf("Not implemented on icon") +func (cp *IconProvider) AddKey(name string, coinType uint32, signingAlgorithm string, password string) (output *provider.KeyOutput, err error) { + w, err := cp.generateKeystoreWithPassword(name, password) + if err != nil { + return nil, err + } + return &provider.KeyOutput{ + Address: w.Address().String(), + Mnemonic: "", + }, nil } func (cp *IconProvider) RestoreKey(name, mnemonic string, coinType uint32, signingAlgorithm string) (address string, err error) { - return "", fmt.Errorf("Not implemented on icon") + return "", fmt.Errorf("not implemented on icon") } func (cp *IconProvider) ShowAddress(name string) (address string, err error) { - return cp.wallet.Address().String(), nil + dirPath := path.Join(cp.PCfg.KeyDirectory, cp.ChainId(), fmt.Sprintf("%s.json", name)) + return getAddrFromKeystore(dirPath) } func (cp *IconProvider) ListAddresses() (map[string]string, error) { - return nil, fmt.Errorf("Not implemented on icon") + dirPath := path.Join(cp.PCfg.KeyDirectory, cp.ChainId()) + dirEntry, err := os.ReadDir(dirPath) + if err != nil { + return nil, err + } + + addrMap := make(map[string]string) + for _, file := range dirEntry { + if !file.IsDir() && strings.HasSuffix(file.Name(), ".json") { + ksFile := path.Join(dirPath, file.Name()) + addr, err := getAddrFromKeystore(ksFile) + if err != nil { + continue + } + addrMap[strings.TrimSuffix(file.Name(), ".json")] = addr + } + } + return addrMap, nil } func (cp *IconProvider) DeleteKey(name string) error { ok := cp.KeyExists(name) if !ok { - return fmt.Errorf("Wallet does not exist") + return fmt.Errorf("wallet does not exist") } - cp.wallet = nil - return nil + + dirPath := path.Join(cp.PCfg.KeyDirectory, cp.ChainId(), fmt.Sprintf("%s.json", name)) + _, err := os.Stat(dirPath) + if err == nil { + if err := os.Remove(dirPath); err != nil { + return err + } + return nil + } + return fmt.Errorf("fail to delete wallet") } func (cp *IconProvider) KeyExists(name string) bool { - return cp.wallet != nil + walletPath := path.Join(cp.PCfg.KeyDirectory, cp.ChainId(), fmt.Sprintf("%s.json", name)) + _, err := os.ReadFile(walletPath) + if err != nil && os.IsNotExist(err) { + return false + } else if err != nil { + panic("key does not exist") + } + return true } func (cp *IconProvider) ExportPrivKeyArmor(keyName string) (armor string, err error) { - return "", fmt.Errorf("Not implemented on icon") -} - -func (cp *IconProvider) AddIconKey(name string, password []byte) (module.Wallet, error) { - w, err := generateKeystoreWithPassword(name, password) - if err != nil { - return nil, err - } - cp.AddWallet(w) - return w, nil + return "", fmt.Errorf("not implemented on icon") } -func (cp *IconProvider) RestoreIconKeyStore(path string, password []byte) (module.Wallet, error) { - ksByte, err := os.ReadFile(path) +func (cp *IconProvider) RestoreIconKeyStore(name string, password []byte) (module.Wallet, error) { + walletPath := path.Join(cp.PCfg.KeyDirectory, cp.ChainId(), fmt.Sprintf("%s.json", name)) + ksByte, err := os.ReadFile(walletPath) if err != nil { return nil, err } @@ -71,11 +106,11 @@ func (cp *IconProvider) RestoreIconKeyStore(path string, password []byte) (modul if err != nil { return nil, err } - cp.AddWallet(w) return w, nil } -func (cp *IconProvider) RestoreIconPrivateKey(pk []byte) (module.Wallet, error) { +// This method does not save keystore +func (cp *IconProvider) RestoreFromPrivateKey(name string, pk []byte) (module.Wallet, error) { pKey, err := glcrypto.ParsePrivateKey(pk) if err != nil { return nil, err @@ -84,37 +119,58 @@ func (cp *IconProvider) RestoreIconPrivateKey(pk []byte) (module.Wallet, error) if err != nil { return nil, err } - cp.AddWallet(w) return w, nil } -func (cp *IconProvider) KeyExistsIcon() bool { - return cp.wallet != nil +func (cp *IconProvider) generateKeystoreWithPassword(name string, password string) (module.Wallet, error) { + w := wallet.New() + ks, err := wallet.KeyStoreFromWallet(w, []byte(password)) + if err != nil { + log.Panicf("Failed to generate keystore. Err %+v", err) + return nil, err + } + + if err := cp.saveWallet(name, ks); err != nil { + return nil, err + } + + return w, nil } -func (cp *IconProvider) DeleteKeyIcon() error { - ok := cp.KeyExistsIcon() - if !ok { - return fmt.Errorf("Wallet does not exist") +func (cp *IconProvider) saveWallet(name string, ks []byte) error { + dirPath := path.Join(cp.PCfg.KeyDirectory, cp.ChainId()) + _, err := os.Stat(dirPath) + if os.IsNotExist(err) { + err := os.MkdirAll(dirPath, 0755) + if err != nil { + panic(err) + } + } else if err != nil { + return err + } + if err := os.WriteFile(fmt.Sprintf("%s/%s.json", dirPath, name), ks, 0600); err != nil { + log.Panicf("Fail to write keystore err=%+v", err) + return err } - cp.wallet = nil return nil } -func (cp *IconProvider) ShowAddressIcon() (address string, err error) { - ok := cp.KeyExistsIcon() - if !ok { - return "", fmt.Errorf("Wallet does not exist") - } - return cp.wallet.Address().String(), nil +type OnlyAddr struct { + Address string `json:"address"` } -func generateKeystoreWithPassword(path string, password []byte) (module.Wallet, error) { - w := wallet.New() - _, err := wallet.KeyStoreFromWallet(w, password) +func getAddrFromKeystore(keystorePath string) (string, error) { + + ksFile, err := os.ReadFile(keystorePath) if err != nil { - log.Panicf("Failed to generate keystore. Err %+v", err) - return nil, err + return "", err } - return w, nil + + var a OnlyAddr + err = json.Unmarshal(ksFile, &a) + if err != nil { + return "", err + } + return a.Address, nil + } diff --git a/relayer/chains/icon/keys_test.go b/relayer/chains/icon/keys_test.go index 9b35e2ee6..108f14242 100644 --- a/relayer/chains/icon/keys_test.go +++ b/relayer/chains/icon/keys_test.go @@ -1,7 +1,6 @@ package icon import ( - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -23,36 +22,40 @@ func TestCreateKeystore(t *testing.T) { } func TestAddIconKeyStore(t *testing.T) { - kwName := "testWallet.json" + kwName := "testWallet" p := &IconProvider{ client: NewClient(ENDPOINT, &zap.Logger{}), + PCfg: &IconProviderConfig{ + KeyDirectory: "../../../env", + ChainID: "ibc-icon", + }, } - w, err := p.AddIconKey(kwName, []byte("gochain")) + w, err := p.AddKey(kwName, 0, "", "gochain") require.NoError(t, err, "err creating keystore with password") - assert.Equal(t, w.Address(), p.wallet.Address()) - assert.Equal(t, w, p.wallet) -} - -func TestRestoreIconKeyStore(t *testing.T) { + addr, err := p.ShowAddress(kwName) + assert.NoError(t, err) - kwName := "../../../env/godWallet.json" - - pcfg := &IconProviderConfig{ - Keystore: kwName, - Password: "gochain", - Timeout: "20s", - ChainName: "icon", - StartHeight: 10, - IbcHandlerAddress: "cxb6b5791be0b5ef67063b3c10b840fb81514db2fd", - BlockInterval: 2000, - } - p, err := pcfg.NewProvider(zap.NewNop(), "not_correct", false, "icon") - require.NoError(t, err) - iconp := p.(*IconProvider) - fmt.Println(iconp) - w, err := iconp.RestoreIconKeyStore(kwName, []byte("gochain")) - require.NoError(t, err) - - assert.Equal(t, w, iconp.wallet) + // assert.Equal(t, w.Address, p.wallet.Address()) + assert.Equal(t, w.Address, addr) } + +// func TestRestoreIconKeyStore(t *testing.T) { + +// pcfg := &IconProviderConfig{ +// KeyDirectory: "../../../env", +// Keystore: "testWallet", +// Password: "gochain", +// Timeout: "20s", +// ChainName: "icon", +// StartHeight: 10, +// IbcHandlerAddress: "cxb6b5791be0b5ef67063b3c10b840fb81514db2fd", +// BlockInterval: 2000, +// } +// p, err := pcfg.NewProvider(zap.NewNop(), "not_correct", false, "icon") +// require.NoError(t, err) +// iconp := p.(*IconProvider) +// _, err = iconp.RestoreIconKeyStore("testWallet", []byte("gochain")) +// require.NoError(t, err) + +// } diff --git a/relayer/chains/icon/provider.go b/relayer/chains/icon/provider.go index 4cec9c55d..9d1ad4508 100644 --- a/relayer/chains/icon/provider.go +++ b/relayer/chains/icon/provider.go @@ -4,7 +4,6 @@ import ( "context" "encoding/base64" "fmt" - "os" "sync" "time" @@ -14,7 +13,6 @@ import ( "github.com/cosmos/relayer/v2/relayer/processor" "github.com/cosmos/relayer/v2/relayer/provider" "github.com/icon-project/IBC-Integration/libraries/go/common/icon" - "github.com/icon-project/goloop/common/wallet" "github.com/icon-project/goloop/module" "go.uber.org/zap" @@ -48,8 +46,12 @@ var ( NOT_IMPLEMENTED = " :: Not implemented for ICON" ) +/* + * The provider assumes the key is in + * KeyDirectory/Keystore.json + */ type IconProviderConfig struct { - Key string `json:"key" yaml:"key"` + KeyDirectory string `json:"key-directory" yaml:"key-directory"` ChainName string `json:"-" yaml:"-"` ChainID string `json:"chain-id" yaml:"chain-id"` RPCAddr string `json:"rpc-addr" yaml:"rpc-addr"` @@ -96,40 +98,22 @@ func (pp *IconProviderConfig) GetFirstRetryBlockAfter() uint64 { func (pp *IconProviderConfig) NewProvider(log *zap.Logger, homepath string, debug bool, chainName string) (provider.ChainProvider, error) { pp.ChainName = chainName - if _, err := os.Stat(pp.Keystore); err != nil { - return nil, err - } if err := pp.Validate(); err != nil { return nil, err } - ksByte, err := os.ReadFile(pp.Keystore) - if err != nil { - return nil, err - } - - wallet, err := wallet.NewFromKeyStore(ksByte, []byte(pp.Password)) - if err != nil { - return nil, err - } - codec := MakeCodec(ModuleBasics, []string{}) return &IconProvider{ log: log.With(zap.String("chain_id", pp.ChainID)), client: NewClient(pp.getRPCAddr(), log), PCfg: pp, - wallet: wallet, StartHeight: uint64(pp.StartHeight), codec: codec, }, nil } -func (icp *IconProvider) AddWallet(w module.Wallet) { - icp.wallet = w -} - func (pp IconProviderConfig) getRPCAddr() string { return pp.RPCAddr } @@ -143,7 +127,6 @@ type IconProvider struct { PCfg *IconProviderConfig txMu sync.Mutex client *Client - wallet module.Wallet metrics *processor.PrometheusMetrics codec Codec StartHeight uint64 @@ -208,6 +191,20 @@ func (h IconIBCHeader) ShouldUpdateWithZeroMessage() bool { //ChainProvider Methods func (icp *IconProvider) Init(ctx context.Context) error { + // if _, err := os.Stat(icp.PCfg.Keystore); err != nil { + // return err + // } + + // ksByte, err := os.ReadFile(icp.PCfg.Keystore) + // if err != nil { + // return err + // } + + // wallet, err := wallet.NewFromKeyStore(ksByte, []byte(icp.PCfg.Password)) + // if err != nil { + // return err + // } + // icp.AddWallet(wallet) return nil } @@ -438,11 +435,15 @@ func (icp *IconProvider) CommitmentPrefix() commitmenttypes.MerklePrefix { } func (icp *IconProvider) Key() string { - return "" + return icp.PCfg.Keystore +} + +func (icp *IconProvider) Wallet() (module.Wallet, error) { + return icp.RestoreIconKeyStore(icp.PCfg.Keystore, []byte(icp.PCfg.Password)) } func (icp *IconProvider) Address() (string, error) { - return icp.wallet.Address().String(), nil + return icp.ShowAddress(icp.PCfg.Keystore) } func (icp *IconProvider) Timeout() string { diff --git a/relayer/chains/icon/query.go b/relayer/chains/icon/query.go index 7ace0469c..ce6b892f1 100644 --- a/relayer/chains/icon/query.go +++ b/relayer/chains/icon/query.go @@ -57,7 +57,7 @@ func (icp *IconProvider) prepareCallParams(methodName string, param map[string]i } callParam := &types.CallParam{ - FromAddress: types.NewAddress(icp.wallet.Address().Bytes()), + FromAddress: types.Address(fmt.Sprintf("hx%s", strings.Repeat("0", 40))), ToAddress: types.Address(icp.PCfg.IbcHandlerAddress), DataType: "call", Data: callData, diff --git a/relayer/chains/icon/tx.go b/relayer/chains/icon/tx.go index 9744bef03..21bd2452c 100644 --- a/relayer/chains/icon/tx.go +++ b/relayer/chains/icon/tx.go @@ -708,9 +708,13 @@ func (icp *IconProvider) SendIconTransaction( asyncCtx context.Context, asyncCallback func(*provider.RelayerTxResponse, error)) error { m := msg.(*IconMessage) + wallet, err := icp.Wallet() + if err != nil { + return err + } txParam := &types.TransactionParam{ Version: types.NewHexInt(types.JsonrpcApiVersion), - FromAddress: types.Address(icp.wallet.Address().String()), + FromAddress: types.Address(wallet.Address().String()), ToAddress: types.Address(icp.PCfg.IbcHandlerAddress), NetworkID: types.NewHexInt(icp.PCfg.ICONNetworkID), StepLimit: types.NewHexInt(int64(defaultStepLimit)), @@ -721,10 +725,10 @@ func (icp *IconProvider) SendIconTransaction( }, } - if err := icp.client.SignTransaction(icp.wallet, txParam); err != nil { + if err := icp.client.SignTransaction(wallet, txParam); err != nil { return err } - _, err := icp.client.SendTransaction(txParam) + _, err = icp.client.SendTransaction(txParam) if err != nil { return err } diff --git a/relayer/chains/mock/mock_chain_processor.go b/relayer/chains/mock/mock_chain_processor.go index 001de0831..b311c687a 100644 --- a/relayer/chains/mock/mock_chain_processor.go +++ b/relayer/chains/mock/mock_chain_processor.go @@ -50,7 +50,7 @@ func NewMockChainProcessor(ctx context.Context, log *zap.Logger, chainID string, } chainProvider, _ := chainProviderCfg.NewProvider(zap.NewNop(), "/tmp", true, "mock-chain-name-"+chainID) _ = chainProvider.Init(ctx) - _, _ = chainProvider.AddKey(chainProvider.Key(), 118, string(hd.Secp256k1Type)) + _, _ = chainProvider.AddKey(chainProvider.Key(), 118, string(hd.Secp256k1Type), "") return &MockChainProcessor{ log: log, chainID: chainID, diff --git a/relayer/chains/penumbra/keys.go b/relayer/chains/penumbra/keys.go index aa09fa7b1..d08efe96d 100644 --- a/relayer/chains/penumbra/keys.go +++ b/relayer/chains/penumbra/keys.go @@ -58,7 +58,7 @@ func (cc *PenumbraProvider) KeystoreCreated(path string) bool { // AddKey generates a new mnemonic which is then converted to a private key and BIP-39 HD Path and persists it to the keystore. // It fails if there is an existing key with the same address. -func (cc *PenumbraProvider) AddKey(name string, coinType uint32, signingAlgorithm string) (output *provider.KeyOutput, err error) { +func (cc *PenumbraProvider) AddKey(name string, coinType uint32, signingAlgorithm string, password string) (output *provider.KeyOutput, err error) { ko, err := cc.KeyAddOrRestore(name, coinType) if err != nil { return nil, err diff --git a/relayer/chains/wasm/keys.go b/relayer/chains/wasm/keys.go index d0f8b4832..c7b8e2991 100644 --- a/relayer/chains/wasm/keys.go +++ b/relayer/chains/wasm/keys.go @@ -58,7 +58,7 @@ func (cc *WasmProvider) KeystoreCreated(path string) bool { // AddKey generates a new mnemonic which is then converted to a private key and BIP-39 HD Path and persists it to the keystore. // It fails if there is an existing key with the same address. -func (cc *WasmProvider) AddKey(name string, coinType uint32, signingAlgorithm string) (output *provider.KeyOutput, err error) { +func (cc *WasmProvider) AddKey(name string, coinType uint32, signingAlgorithm string, password string) (output *provider.KeyOutput, err error) { ko, err := cc.KeyAddOrRestore(name, coinType) if err != nil { return nil, err diff --git a/relayer/provider/provider.go b/relayer/provider/provider.go index 56099ba59..a548eae24 100644 --- a/relayer/provider/provider.go +++ b/relayer/provider/provider.go @@ -220,7 +220,7 @@ func (r RelayerTxResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { type KeyProvider interface { CreateKeystore(path string) error KeystoreCreated(path string) bool - AddKey(name string, coinType uint32, signingAlgorithm string) (output *KeyOutput, err error) + AddKey(name string, coinType uint32, signingAlgorithm string, password string) (output *KeyOutput, err error) RestoreKey(name, mnemonic string, coinType uint32, signingAlgorithm string) (address string, err error) ShowAddress(name string) (address string, err error) ListAddresses() (map[string]string, error)