Working with relay init
This commit is contained in:
parent
b63f8bd15a
commit
cb075bbb7e
|
@ -2,6 +2,7 @@ package commands
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -73,13 +74,7 @@ func init() {
|
|||
RelayCmd.AddCommand(RelayInitCmd)
|
||||
}
|
||||
|
||||
func relayInitCmd(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println("not implemented")
|
||||
return nil
|
||||
}
|
||||
|
||||
func relayStartCmd(cmd *cobra.Command, args []string) error {
|
||||
|
||||
go loop(chain1AddrFlag, chain2AddrFlag, chain1IDFlag, chain2IDFlag)
|
||||
go loop(chain2AddrFlag, chain1AddrFlag, chain2IDFlag, chain1IDFlag)
|
||||
|
||||
|
@ -87,7 +82,36 @@ func relayStartCmd(cmd *cobra.Command, args []string) error {
|
|||
// TODO: Cleanup
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func relayInitCmd(cmd *cobra.Command, args []string) error {
|
||||
err := registerChain(chain1IDFlag, chain1AddrFlag, chain2IDFlag, genesisFile2Flag, fromFileFlag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = registerChain(chain2IDFlag, chain2AddrFlag, chain1IDFlag, genesisFile1Flag, fromFileFlag)
|
||||
return err
|
||||
}
|
||||
|
||||
func registerChain(chainID, node, registerChainID, registerGenesis, keyFile string) error {
|
||||
genesisBytes, err := ioutil.ReadFile(registerGenesis)
|
||||
if err != nil {
|
||||
return errors.Errorf("Error reading genesis file %v: %v\n", registerGenesis, err)
|
||||
}
|
||||
|
||||
ibcTx := ibc.IBCRegisterChainTx{
|
||||
ibc.BlockchainGenesis{
|
||||
ChainID: registerChainID,
|
||||
Genesis: string(genesisBytes),
|
||||
},
|
||||
}
|
||||
|
||||
privKey, err := LoadKey(keyFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
relay := newRelayer(privKey, chainID, node)
|
||||
return relay.appTx(ibcTx)
|
||||
}
|
||||
|
||||
func loop(addr1, addr2, id1, id2 string) {
|
||||
|
|
|
@ -108,7 +108,7 @@ test01SendIBCTx() {
|
|||
# start the relay and wait a few blocks...
|
||||
# (already sent a tx on chain1, so use higher sequence)
|
||||
startRelay 2 1
|
||||
if [ $? != 0 ]; then echo "can't start relay!"; return 1; fi
|
||||
if [ $? != 0 ]; then echo "can't start relay"; cat ${BASE_DIR_1}/../relay.log; return 1; fi
|
||||
|
||||
# give it a little time, then make sure the money arrived
|
||||
echo "waiting for relay..."
|
||||
|
@ -148,21 +148,14 @@ startRelay() {
|
|||
txSucceeded $? "$RES"
|
||||
if [ $? != 0 ]; then echo "can't pay chain2!"; return 1; fi
|
||||
|
||||
# now we need to register the chains
|
||||
# TODO: do this with basecli!!!!
|
||||
basecoin tx ibc --amount 10mycoin --from=$RELAY_KEY --chain_id=$CHAIN_ID_2 \
|
||||
--node=tcp://localhost:${PORT_2} \
|
||||
register --ibc_chain_id=$CHAIN_ID_1 --genesis=$BASE_DIR_1/server/genesis.json \
|
||||
>/dev/null
|
||||
if [ $? != 0 ]; then echo "can't register chain1 on chain 2"; return 1; fi
|
||||
# initialize the relay (register both chains)
|
||||
${SERVER_EXE} relay init --chain1-id=$CHAIN_ID_1 --chain2-id=$CHAIN_ID_2 \
|
||||
--chain1-addr=tcp://localhost:${PORT_1} --chain2-addr=tcp://localhost:${PORT_2} \
|
||||
--genesis1=${BASE_DIR_1}/server/genesis.json --genesis2=${BASE_DIR_2}/server/genesis.json \
|
||||
--home=${BASE_DIR_1}/server --from=$RELAY_KEY > ${BASE_DIR_1}/../relay.log &
|
||||
if [ $? != 0 ]; then echo "can't initialize relays"; cat ${BASE_DIR_1}/../relay.log; return 1; fi
|
||||
|
||||
basecoin tx ibc --amount 10mycoin --from=$RELAY_KEY --chain_id=$CHAIN_ID_1 \
|
||||
--node=tcp://localhost:${PORT_1} \
|
||||
register --ibc_chain_id=$CHAIN_ID_2 --genesis=$BASE_DIR_2/server/genesis.json \
|
||||
>/dev/null
|
||||
if [ $? != 0 ]; then echo "can't register chain2 on chain 1"; return 1; fi
|
||||
|
||||
# now start the relay! (this remains a server command)
|
||||
# now start the relay (constantly send packets)
|
||||
# TODO: bucky, why does this die if I don't provide home???
|
||||
# It doesn't use the --from flag????
|
||||
${SERVER_EXE} relay start --chain1-id=$CHAIN_ID_1 --chain2-id=$CHAIN_ID_2 \
|
||||
|
|
Loading…
Reference in New Issue