commit
519d0b7d00
|
@ -1,25 +1,157 @@
|
|||
# IBC CLI Usage
|
||||
# IBC Doubble Hubble
|
||||
|
||||
## initialize
|
||||
## Remove remaining data
|
||||
|
||||
```bash
|
||||
basecoind init # copy the recover key
|
||||
basecli keys add keyname --recover
|
||||
basecoind start
|
||||
```console
|
||||
> rm -r ~/.chain1
|
||||
> rm -r ~/.chain2
|
||||
> rm -r ~/.basecli
|
||||
```
|
||||
|
||||
## transfer
|
||||
## Initialize both chains
|
||||
|
||||
`transfer` sends coins from one chain to another(or itself).
|
||||
```console
|
||||
> basecoind init --home ~/.chain1
|
||||
I[04-02|14:03:33.704] Generated private validator module=main path=/home/mossid/.chain1/config/priv_validator.json
|
||||
I[04-02|14:03:33.705] Generated genesis file module=main path=/home/mossid/.chain1/config/genesis.json
|
||||
{
|
||||
"secret": "crunch ignore trigger neither differ dance cheap brick situate floor luxury citizen husband decline arrow abandon",
|
||||
"account": "C69FEB398A29AAB1B3C4F07DE22208F35E711BCC",
|
||||
"validator": {
|
||||
"pub_key": {
|
||||
"type": "ed25519",
|
||||
"data": "8C9917D5E982E221F5A1450103102B44BBFC1E8768126C606246CB37B5794F4D"
|
||||
},
|
||||
"power": 10,
|
||||
"name": ""
|
||||
},
|
||||
"node_id": "3ac8e6242315fd62143dc3e52c161edaaa6b1a64",
|
||||
"chain_id": "test-chain-ZajMfr"
|
||||
}
|
||||
> ADDR1=C69FEB398A29AAB1B3C4F07DE22208F35E711BCC
|
||||
> ID1=test-chain-ZajMfr
|
||||
> NODE1=tcp://0.0.0.0:36657
|
||||
> basecli keys add key1 --recover
|
||||
Enter a passphrase for your key:
|
||||
Repeat the passphrase:
|
||||
Enter your recovery seed phrase:
|
||||
crunch ignore trigger neither differ dance cheap brick situate floor luxury citizen husband decline arrow abandon
|
||||
key1 C69FEB398A29AAB1B3C4F07DE22208F35E711BCC
|
||||
|
||||
|
||||
> basecoind init --home ~/.chain2
|
||||
I[04-02|14:09:14.453] Generated private validator module=main path=/home/mossid/.chain2/config/priv_validator.json
|
||||
I[04-02|14:09:14.453] Generated genesis file module=main path=/home/mossid/.chain2/config/genesis.json
|
||||
{
|
||||
"secret": "age guide awesome month female left oxygen soccer define high grocery work desert dinner arena abandon",
|
||||
"account": "DC26002735D3AA9573707CFA6D77C12349E49868",
|
||||
"validator": {
|
||||
"pub_key": {
|
||||
"type": "ed25519",
|
||||
"data": "A94FE4B9AD763D301F4DD5A2766009812495FB7A79F1275FB8A5AF09B44FD5F3"
|
||||
},
|
||||
"power": 10,
|
||||
"name": ""
|
||||
},
|
||||
"node_id": "ad26831330e1c72b85276d53c20f0680e6fd4cf5"
|
||||
"chain_id": "test-chain-4XHTPn"
|
||||
}
|
||||
> ADDR2=DC26002735D3AA9573707CFA6D77C12349E49868
|
||||
> ID2=test-chain-4XHTPn
|
||||
> NODE2=tcp://0.0.0.0:46657
|
||||
> basecli keys add key2 --recover
|
||||
Enter a passphrase for your key:
|
||||
Repeat the passphrase:
|
||||
Enter your recovery seed phrase:
|
||||
age guide awesome month female left oxygen soccer define high grocery work desert dinner arena abandon
|
||||
key2 DC26002735D3AA9573707CFA6D77C12349E49868
|
||||
|
||||
|
||||
> basecoind start --home ~/.chain1 --address tcp://0.0.0.0:36658 --rpc.laddr tcp://0.0.0.0:36657 --p2p.laddr tcp://0.0.0.0:36656
|
||||
...
|
||||
|
||||
> basecoind start --home ~/.chain2 # --address tcp://0.0.0.0:46658 --rpc.laddr tcp://0.0.0.0:46657 --p2p.laddr tcp://0.0.0.0:46656
|
||||
...
|
||||
```
|
||||
## Check balance
|
||||
|
||||
```console
|
||||
> basecli account $ADDR1 --node $NODE1
|
||||
{
|
||||
"address": "C69FEB398A29AAB1B3C4F07DE22208F35E711BCC",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "mycoin",
|
||||
"amount": 9007199254740992
|
||||
}
|
||||
],
|
||||
"public_key": null,
|
||||
"sequence": 0,
|
||||
"name": ""
|
||||
}
|
||||
|
||||
> basecli account $ADDR2 --node $NODE2
|
||||
{
|
||||
"address": "DC26002735D3AA9573707CFA6D77C12349E49868",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "mycoin",
|
||||
"amount": 9007199254740992
|
||||
}
|
||||
],
|
||||
"public_key": null,
|
||||
"sequence": 0,
|
||||
"name": ""
|
||||
}
|
||||
|
||||
```bash
|
||||
basecli transfer --name keyname --to address_of_destination --amount 10mycoin --chain test-chain-AAAAAA --chain-id AAAAAA
|
||||
```
|
||||
|
||||
The id of the chain can be found in `$HOME/.basecoind/config/genesis.json`
|
||||
## Transfer coins (addr1:chain1 -> addr2:chain2)
|
||||
|
||||
```console
|
||||
> basecli transfer --name key1 --to $ADDR2 --amount 10mycoin --chain $ID2 --chain-id $ID1 --node $NODE1
|
||||
Password to sign with 'key1':
|
||||
Committed at block 1022. Hash: E16019DCC4AA08CA70AFCFBC96028ABCC51B6AD0
|
||||
> basecli account $ADDR1 --node $NODE1
|
||||
{
|
||||
"address": "C69FEB398A29AAB1B3C4F07DE22208F35E711BCC",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "mycoin",
|
||||
"amount": 9007199254740982
|
||||
}
|
||||
],
|
||||
"public_key": {
|
||||
"type": "ed25519",
|
||||
"data": "9828FF1780A066A0D93D840737566B697035448D6C880807322BED8919348B2B"
|
||||
},
|
||||
"sequence": 1,
|
||||
"name": ""
|
||||
}
|
||||
```
|
||||
|
||||
## Relay IBC packets
|
||||
|
||||
```console
|
||||
> basecli relay --name key2 --from-chain-id $ID1 --from-chain-node $NODE1 --to-chain-id $ID2 --to-chain-node $NODE2 --chain-id $ID2
|
||||
Password to sign with 'key2':
|
||||
I[04-03|16:18:59.984] Detected IBC packet number=0
|
||||
I[04-03|16:19:00.869] Relayed IBC packet number=0
|
||||
> basecli account $ADDR2 --node $NODE2
|
||||
{
|
||||
"address": "DC26002735D3AA9573707CFA6D77C12349E49868",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "mycoin",
|
||||
"amount": 9007199254741002
|
||||
}
|
||||
],
|
||||
"public_key": {
|
||||
"type": "ed25519",
|
||||
"data": "F52B4FA545F4E9BFE5D7AF1DD2236899FDEF905F9B3057C38D7C01BF1B8EB52E"
|
||||
},
|
||||
"sequence": 1,
|
||||
"name": ""
|
||||
}
|
||||
|
||||
## relay
|
||||
|
||||
```bash
|
||||
basecli relay --name keyname --from-chain-id test-chain-AAAAAA --from-chain-node=tcp://0.0.0.0:46657 --to-chain-id test-chain-AAAAAA --to-chain-node=tcp://0.0.0.0:46657
|
||||
```
|
||||
|
|
|
@ -77,7 +77,7 @@ func buildMsg(from sdk.Address) (sdk.Msg, error) {
|
|||
}
|
||||
to := sdk.Address(bz)
|
||||
|
||||
packet := ibc.NewIBCPacket(from, to, coins, client.FlagChainID,
|
||||
packet := ibc.NewIBCPacket(from, to, coins, viper.GetString(client.FlagChainID),
|
||||
viper.GetString(flagChain))
|
||||
|
||||
msg := ibc.IBCTransferMsg{
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/builder"
|
||||
|
||||
|
@ -30,6 +32,8 @@ type relayCommander struct {
|
|||
decoder sdk.AccountDecoder
|
||||
mainStore string
|
||||
ibcStore string
|
||||
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func IBCRelayCmd(cdc *wire.Codec) *cobra.Command {
|
||||
|
@ -38,6 +42,8 @@ func IBCRelayCmd(cdc *wire.Codec) *cobra.Command {
|
|||
decoder: authcmd.GetAccountDecoder(cdc),
|
||||
ibcStore: "ibc",
|
||||
mainStore: "main",
|
||||
|
||||
logger: log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
|
@ -86,27 +92,26 @@ func (c relayCommander) loop(fromChainID, fromChainNode, toChainID, toChainNode
|
|||
}
|
||||
|
||||
ingressKey := ibc.IngressSequenceKey(fromChainID)
|
||||
|
||||
processedbz, err := query(toChainNode, ingressKey, c.ibcStore)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var processed int64
|
||||
if processedbz == nil {
|
||||
processed = 0
|
||||
} else if err = c.cdc.UnmarshalBinary(processedbz, &processed); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
OUTER:
|
||||
for {
|
||||
time.Sleep(time.Second)
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
processedbz, err := query(toChainNode, ingressKey, c.ibcStore)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var processed int64
|
||||
if processedbz == nil {
|
||||
processed = 0
|
||||
} else if err = c.cdc.UnmarshalBinary(processedbz, &processed); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
lengthKey := ibc.EgressLengthKey(toChainID)
|
||||
egressLengthbz, err := query(fromChainNode, lengthKey, c.ibcStore)
|
||||
if err != nil {
|
||||
fmt.Printf("Error querying outgoing packet list length: '%s'\n", err)
|
||||
c.logger.Error("Error querying outgoing packet list length", "err", err)
|
||||
continue OUTER
|
||||
}
|
||||
var egressLength int64
|
||||
|
@ -115,25 +120,30 @@ OUTER:
|
|||
} else if err = c.cdc.UnmarshalBinary(egressLengthbz, &egressLength); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("egressLength queried: %d\n", egressLength)
|
||||
if egressLength > processed {
|
||||
c.logger.Info("Detected IBC packet", "number", egressLength-1)
|
||||
}
|
||||
|
||||
seq := c.getSequence(toChainNode)
|
||||
|
||||
for i := processed; i < egressLength; i++ {
|
||||
egressbz, err := query(fromChainNode, ibc.EgressKey(toChainID, i), c.ibcStore)
|
||||
if err != nil {
|
||||
fmt.Printf("Error querying egress packet: '%s'\n", err)
|
||||
c.logger.Error("Error querying egress packet", "err", err)
|
||||
continue OUTER
|
||||
}
|
||||
|
||||
viper.Set(client.FlagSequence, seq)
|
||||
seq++
|
||||
|
||||
err = c.broadcastTx(toChainNode, c.refine(egressbz, i, passphrase))
|
||||
if err != nil {
|
||||
fmt.Printf("Error broadcasting ingress packet: '%s'\n", err)
|
||||
c.logger.Error("Error broadcasting ingress packet", "err", err)
|
||||
continue OUTER
|
||||
}
|
||||
|
||||
fmt.Printf("Relayed packet: %d\n", i)
|
||||
c.logger.Info("Relayed IBC packet", "number", i)
|
||||
}
|
||||
|
||||
processed = egressLength
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,8 +158,6 @@ func query(node string, key []byte, storeName string) (res []byte, err error) {
|
|||
func (c relayCommander) broadcastTx(node string, tx []byte) error {
|
||||
orig := viper.GetString(client.FlagNode)
|
||||
viper.Set(client.FlagNode, node)
|
||||
seq := c.getSequence(node) + 1
|
||||
viper.Set(client.FlagSequence, seq)
|
||||
_, err := builder.BroadcastTx(tx)
|
||||
viper.Set(client.FlagNode, orig)
|
||||
return err
|
||||
|
@ -160,6 +168,7 @@ func (c relayCommander) getSequence(node string) int64 {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
account, err := c.decoder(res)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -168,6 +177,10 @@ func (c relayCommander) getSequence(node string) int64 {
|
|||
return account.GetSequence()
|
||||
}
|
||||
|
||||
func setSequence(seq int64) {
|
||||
viper.Set(client.FlagSequence, seq)
|
||||
}
|
||||
|
||||
func (c relayCommander) refine(bz []byte, sequence int64, passphrase string) []byte {
|
||||
var packet ibc.IBCPacket
|
||||
if err := c.cdc.UnmarshalBinary(bz, &packet); err != nil {
|
||||
|
|
Loading…
Reference in New Issue