[cmd] support SendTx to other chains via IBC

This commit is contained in:
Ethan Buchman 2017-05-21 22:40:48 -04:00
parent 444b96dfe7
commit 7f2d25c593
3 changed files with 27 additions and 2 deletions

View File

@ -90,6 +90,11 @@ OUTER:
logger.Error("Error parsing sequence number from query", "query.Value", query.Value, "error", err.Error())
continue OUTER
}
seq -= 1 // seq is the packet count. -1 because 0-indexed
if nextSeq <= int(seq) {
logger.Info("Got new packets", "last-sequence", nextSeq-1, "new-sequence", seq)
}
// get all packets since the last one we relayed
for ; nextSeq <= int(seq); nextSeq++ {

View File

@ -3,6 +3,7 @@ package commands
import (
"encoding/hex"
"fmt"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -81,12 +82,29 @@ func init() {
func sendTxCmd(cmd *cobra.Command, args []string) error {
var toHex string
var chainPrefix string
spl := strings.Split(toFlag, "/")
switch len(spl) {
case 1:
toHex = spl[0]
case 2:
chainPrefix = spl[0]
toHex = spl[1]
default:
return errors.Errorf("To address has too many slashes")
}
// convert destination address to bytes
to, err := hex.DecodeString(StripHex(toFlag))
to, err := hex.DecodeString(StripHex(toHex))
if err != nil {
return errors.Errorf("To address is invalid hex: %v\n", err)
}
if chainPrefix != "" {
to = []byte(chainPrefix + "/" + string(to))
}
// load the priv key
privKey, err := LoadKey(fromFlag)
if err != nil {

View File

@ -69,7 +69,9 @@ func NewPacket(src, dst string, seq uint64, payload Payload) Packet {
}
}
// GetSequenceNumber gets the sequence number for packets being sent from the src chain to the dst chain
// GetSequenceNumber gets the sequence number for packets being sent from the src chain to the dst chain.
// The sequence number counts how many packets have been sent.
// The next packet must include the latest sequence number.
func GetSequenceNumber(store types.KVStore, src, dst string) uint64 {
sequenceKey := toKey(_IBC, _EGRESS, src, dst)
seqBytes := store.Get(sequenceKey)