Skip to content

Commit 242e516

Browse files
izyakizyak
and
izyak
authored
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 <test@test.test>
1 parent 0802184 commit 242e516

File tree

16 files changed

+216
-142
lines changed

16 files changed

+216
-142
lines changed

cmd/keys.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
const (
3333
flagCoinType = "coin-type"
3434
flagAlgo = "signing-algorithm"
35+
flagPassword = "password"
3536
defaultCoinType uint32 = sdk.CoinType
3637
)
3738

@@ -97,6 +98,11 @@ $ %s k a cosmoshub testkey`, appName, appName, appName)),
9798
return err
9899
}
99100

101+
password, err := cmdFlags.GetString(flagPassword)
102+
if err != nil {
103+
return err
104+
}
105+
100106
if algo == "" {
101107
if ccp, ok := chain.ChainProvider.(*cosmos.CosmosProvider); ok {
102108
algo = ccp.PCfg.SigningAlgorithm
@@ -105,7 +111,7 @@ $ %s k a cosmoshub testkey`, appName, appName, appName)),
105111
}
106112
}
107113

108-
ko, err := chain.ChainProvider.AddKey(keyName, uint32(coinType), algo)
114+
ko, err := chain.ChainProvider.AddKey(keyName, uint32(coinType), algo, password)
109115
if err != nil {
110116
return fmt.Errorf("failed to add key: %w", err)
111117
}
@@ -121,6 +127,7 @@ $ %s k a cosmoshub testkey`, appName, appName, appName)),
121127
}
122128
cmd.Flags().Int32(flagCoinType, -1, "coin type number for HD derivation")
123129
cmd.Flags().String(flagAlgo, "", "signing algorithm for key (secp256k1, sr25519)")
130+
cmd.Flags().String(flagPassword, "x", "icon keystore password")
124131

125132
return cmd
126133
}

examples/config_IBC_ICON.yaml

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ chains:
77
archway:
88
type: wasm
99
value:
10-
key-directory: /home/user/.relayer/keys/localnet
10+
key-directory: /home/user/.relayer/keys
1111
key: relayWallet
1212
chain-id: localnet
1313
rpc-addr: http://localhost:26657
@@ -24,24 +24,24 @@ chains:
2424
extra-codecs: []
2525
coin-type: 0
2626
broadcast-mode: batch
27-
ibc-handler-address: archway14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sy85n2u
27+
ibc-handler-address: archway1pvrwmjuusn9wh34j7y520g8gumuy9xtl3gvprlljfdpwju3x7ucszwhc7n
2828
first-retry-block-after: 0
2929
start-height: 0
30-
block-interval: 6000
30+
block-interval: 3000
3131
icon:
3232
type: icon
3333
value:
34-
key: ""
34+
key-directory: /home/user/.relayer/keys
3535
chain-id: ibc-icon
3636
rpc-addr: http://localhost:9082/api/v3/
3737
timeout: 30s
38-
keystore: /home/user/keystore/godWallet.json
38+
keystore: godWallet
3939
password: gochain
4040
icon-network-id: 3
4141
btp-network-id: 1
4242
btp-network-type-id: 1
4343
start-height: 0
44-
ibc-handler-address: cxa1daa337788364a72644860a5097e3eef7a5d416
44+
ibc-handler-address: cxbeb5929616e0dbd2fec1e6e950ab09e45e6fb25a
4545
first-retry-block-after: 0
4646
block-interval: 2000
4747
paths:
@@ -56,4 +56,4 @@ paths:
5656
connection-id: connection-0
5757
src-channel-filter:
5858
rule: ""
59-
channel-list: []
59+
channel-list: []
+16-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
2-
"type": "icon",
3-
"value": {
4-
"chain-id": "ibc-icon",
5-
"rpc-addr": "http://localhost:9082/api/v3/",
6-
"timeout": "30s",
7-
"keystore":"/Users/viveksharmapoudel/keystore/godWallet.json",
8-
"password":"gochain",
9-
"btp-network-id":2,
10-
"icon-network-id":3,
11-
"start-height":0,
12-
"ibc-handler-address":"cxfffe383e4780084e48e477935099b03193d952fe",
13-
"block-interval":2000,
14-
"first-retry-block-after":8
15-
}
2+
"type": "icon",
3+
"value": {
4+
"key-directory": "/home/user/.relayer/keys",
5+
"chain-id": "ibc-icon",
6+
"rpc-addr": "http://localhost:9082/api/v3/",
7+
"timeout": "30s",
8+
"keystore": "godWallet",
9+
"password": "gochain",
10+
"icon-network-id": 3,
11+
"btp-network-id": 2,
12+
"btp-network-type-id": 1,
13+
"start-height": 0,
14+
"ibc-handler-address": "cxbeb5929616e0dbd2fec1e6e950ab09e45e6fb25a",
15+
"first-retry-block-after": 0,
16+
"block-interval": 2000
17+
}
1618
}
+15-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
{
22
"type": "wasm",
33
"value": {
4-
"key": "default",
5-
"chain-id": "test-1",
6-
"rpc-addr": "https://rpc.constantine-2.archway.tech:443",
7-
"key-directory":"/Users/viveksharmapoudel/.relayer/keys/test-1",
8-
"grpc-addr": "",
9-
"account-prefix": "neutron",
4+
"key-directory": "/home/user/.relayer/keys",
5+
"key": "relayWallet",
6+
"chain-id": "localnet",
7+
"rpc-addr": "http://localhost:26657",
8+
"account-prefix": "archway",
109
"keyring-backend": "test",
1110
"gas-adjustment": 1.5,
12-
"gas-prices": "0.02uconst",
11+
"gas-prices": "0.025stake",
12+
"min-gas-amount": 1000000,
1313
"debug": true,
1414
"timeout": "20s",
15+
"block-timeout": "",
1516
"output-format": "json",
1617
"sign-mode": "direct",
17-
"ibc-handler-address":"neutron1fde8lfydxgwg6p7xe9ugx5a6ysj37zfvn9m9z5rxt4mqvdcneczsczq2a4",
18+
"extra-codecs": [],
19+
"coin-type": 0,
1820
"broadcast-mode": "batch",
19-
"block-timeout": "",
20-
"start-height":0,
21-
"block-interval": 6000
21+
"ibc-handler-address": "archway1pvrwmjuusn9wh34j7y520g8gumuy9xtl3gvprlljfdpwju3x7ucszwhc7n",
22+
"first-retry-block-after": 0,
23+
"start-height": 0,
24+
"block-interval": 3000
2225
}
23-
}
24-
25-
26+
}

examples/demo/configs/paths/icon-archway.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"chain-id": "ibc-icon"
44
},
55
"dst": {
6-
"chain-id": "constantine-2"
6+
"chain-id": "localnet"
77
},
88
"src-channel-filter": {
99
"rule": null,

relayer/chain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (c *Chain) CreateTestKey() error {
149149
if c.ChainProvider.KeyExists(c.ChainProvider.Key()) {
150150
return fmt.Errorf("key {%s} exists for chain {%s}", c.ChainProvider.Key(), c.ChainID())
151151
}
152-
_, err := c.ChainProvider.AddKey(c.ChainProvider.Key(), defaultCoinType, defaultAlgo)
152+
_, err := c.ChainProvider.AddKey(c.ChainProvider.Key(), defaultCoinType, defaultAlgo, "")
153153
return err
154154
}
155155

relayer/chains/cosmos/keys.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (cc *CosmosProvider) KeystoreCreated(path string) bool {
6161

6262
// AddKey generates a new mnemonic which is then converted to a private key and BIP-39 HD Path and persists it to the keystore.
6363
// It fails if there is an existing key with the same address.
64-
func (cc *CosmosProvider) AddKey(name string, coinType uint32, signingAlgorithm string) (output *provider.KeyOutput, err error) {
64+
func (cc *CosmosProvider) AddKey(name string, coinType uint32, signingAlgorithm string, password string) (output *provider.KeyOutput, err error) {
6565
ko, err := cc.KeyAddOrRestore(name, coinType, signingAlgorithm)
6666
if err != nil {
6767
return nil, err

0 commit comments

Comments
 (0)