[cmd] support SendTx to other chains via IBC
This commit is contained in:
parent
444b96dfe7
commit
7f2d25c593
@ -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++ {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user