support SendTx to other chains via IBC
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/go-crypto"
|
||||
"github.com/tendermint/go-wire"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
@@ -49,3 +50,26 @@ type AccountGetterSetter interface {
|
||||
GetAccount(addr []byte) *Account
|
||||
SetAccount(addr []byte, acc *Account)
|
||||
}
|
||||
|
||||
func AccountKey(addr []byte) []byte {
|
||||
return append([]byte("base/a/"), addr...)
|
||||
}
|
||||
|
||||
func GetAccount(store KVStore, addr []byte) *Account {
|
||||
data := store.Get(AccountKey(addr))
|
||||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
var acc *Account
|
||||
err := wire.ReadBinaryBytes(data, &acc)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Error reading account %X error: %v",
|
||||
data, err.Error()))
|
||||
}
|
||||
return acc
|
||||
}
|
||||
|
||||
func SetAccount(store KVStore, addr []byte, acc *Account) {
|
||||
accBytes := wire.BinaryBytes(acc)
|
||||
store.Set(AccountKey(addr), accBytes)
|
||||
}
|
||||
|
||||
+26
-3
@@ -116,10 +116,33 @@ type TxOutput struct {
|
||||
Coins Coins `json:"coins"` //
|
||||
}
|
||||
|
||||
func (txOut TxOutput) ValidateBasic() abci.Result {
|
||||
if len(txOut.Address) != 20 {
|
||||
return abci.ErrBaseInvalidOutput.AppendLog("Invalid address length")
|
||||
// An output destined for another chain may be formatted as `chainID/address`.
|
||||
// ChainAndAddress returns the chainID prefix and the address.
|
||||
// If there is no chainID prefix, the first returned value is nil.
|
||||
func (txOut TxOutput) ChainAndAddress() ([]byte, []byte, abci.Result) {
|
||||
var chainPrefix []byte
|
||||
address := txOut.Address
|
||||
if len(address) > 20 {
|
||||
spl := bytes.Split(address, []byte("/"))
|
||||
if len(spl) < 2 {
|
||||
return nil, nil, abci.ErrBaseInvalidOutput.AppendLog("Invalid address format")
|
||||
}
|
||||
chainPrefix = spl[0]
|
||||
address = bytes.Join(spl[1:], nil)
|
||||
}
|
||||
|
||||
if len(address) != 20 {
|
||||
return nil, nil, abci.ErrBaseInvalidOutput.AppendLog("Invalid address length")
|
||||
}
|
||||
return chainPrefix, address, abci.OK
|
||||
}
|
||||
|
||||
func (txOut TxOutput) ValidateBasic() abci.Result {
|
||||
_, _, r := txOut.ChainAndAddress()
|
||||
if r.IsErr() {
|
||||
return r
|
||||
}
|
||||
|
||||
if !txOut.Coins.IsValid() {
|
||||
return abci.ErrBaseInvalidOutput.AppendLog(Fmt("Invalid coins %v", txOut.Coins))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user