Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
mossid committed Apr 2, 2018
1 parent ba9eb6d commit 606f516
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 32 deletions.
161 changes: 147 additions & 14 deletions x/ibc/commands/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,158 @@
# 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

```bash
basecli transfer --name keyname --to address_of_destination --amount 10mycoin --chain test-chain-AAAAAA --chain-id AAAAAA

> 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": ""
}

```

## 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": ""
}
```

The id of the chain can be found in `$HOME/.basecoind/config/genesis.json`
## Relay IBC packets

```console
> basecli relay --name key2 --from-chain-id $ID1 --from-chain-node $NODE1 --to-chain-id $ID2 --to-chain-node $ID2 --chain-id $ID2
Password to sign with 'key2':
IBC packet #0 detected
Relayed IBC packet #0

## relay
> basecli account $ADDR2 --node $NODE2
{
"address": "DC26002735D3AA9573707CFA6D77C12349E49868",
"coins": [
{
"denom": "mycoin",
"amount": 9007199254741002
}
],
"public_key": {
"type": "ed25519",
"data": "F52B4FA545F4E9BFE5D7AF1DD2236899FDEF905F9B3057C38D7C01BF1B8EB52E"
},
"sequence": 1,
"name": ""
}

```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
```
2 changes: 1 addition & 1 deletion x/ibc/commands/ibctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
36 changes: 19 additions & 17 deletions x/ibc/commands/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,21 @@ 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)
Expand All @@ -115,7 +114,9 @@ OUTER:
} else if err = c.cdc.UnmarshalBinary(egressLengthbz, &egressLength); err != nil {
panic(err)
}
fmt.Printf("egressLength queried: %d\n", egressLength)
if egressLength > processed {
fmt.Printf("IBC packet #%d detected\n", egressLength-1)
}

for i := processed; i < egressLength; i++ {
egressbz, err := query(fromChainNode, ibc.EgressKey(toChainID, i), c.ibcStore)
Expand All @@ -130,7 +131,7 @@ OUTER:
continue OUTER
}

fmt.Printf("Relayed packet: %d\n", i)
fmt.Printf("Relayed IBC packet #%d\n", i)
}

processed = egressLength
Expand All @@ -148,7 +149,7 @@ 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
seq := c.getSequence(node)
viper.Set(client.FlagSequence, seq)
_, err := builder.BroadcastTx(tx)
viper.Set(client.FlagNode, orig)
Expand All @@ -160,6 +161,7 @@ func (c relayCommander) getSequence(node string) int64 {
if err != nil {
panic(err)
}

account, err := c.decoder(res)
if err != nil {
panic(err)
Expand Down

0 comments on commit 606f516

Please sign in to comment.