cosmos-sdk/modules/ibc/tx.go

131 lines
3.6 KiB
Go
Raw Normal View History

2017-07-13 10:22:05 -07:00
package ibc
import (
"github.com/tendermint/light-client/certifiers"
merkle "github.com/tendermint/merkleeyes/iavl"
"github.com/tendermint/basecoin"
)
// nolint
const (
// 0x3? series for ibc
ByteRegisterChain = byte(0x30)
ByteUpdateChain = byte(0x31)
2017-07-16 13:46:21 -07:00
ByteCreatePacket = byte(0x32)
BytePostPacket = byte(0x33)
2017-07-13 10:22:05 -07:00
TypeRegisterChain = NameIBC + "/register"
TypeUpdateChain = NameIBC + "/update"
2017-07-16 13:46:21 -07:00
TypeCreatePacket = NameIBC + "/create"
TypePostPacket = NameIBC + "/post"
2017-07-13 10:22:05 -07:00
)
func init() {
basecoin.TxMapper.
RegisterImplementation(RegisterChainTx{}, TypeRegisterChain, ByteRegisterChain).
RegisterImplementation(UpdateChainTx{}, TypeUpdateChain, ByteUpdateChain).
2017-07-16 13:46:21 -07:00
RegisterImplementation(CreatePacketTx{}, TypeCreatePacket, ByteCreatePacket).
RegisterImplementation(PostPacketTx{}, TypePostPacket, BytePostPacket)
2017-07-13 10:22:05 -07:00
}
// RegisterChainTx allows you to register a new chain on this blockchain
type RegisterChainTx struct {
Seed certifiers.Seed `json:"seed"`
}
// ChainID helps get the chain this tx refers to
func (r RegisterChainTx) ChainID() string {
return r.Seed.Header.ChainID
}
// ValidateBasic makes sure this is consistent, without checking the sigs
func (r RegisterChainTx) ValidateBasic() error {
2017-07-18 07:05:36 -07:00
err := r.Seed.ValidateBasic(r.ChainID())
if err != nil {
err = ErrInvalidCommit(err)
}
return err
2017-07-13 10:22:05 -07:00
}
// Wrap - used to satisfy TxInner
func (r RegisterChainTx) Wrap() basecoin.Tx {
return basecoin.Tx{r}
}
// UpdateChainTx updates the state of this chain
type UpdateChainTx struct {
Seed certifiers.Seed `json:"seed"`
}
// ChainID helps get the chain this tx refers to
func (u UpdateChainTx) ChainID() string {
return u.Seed.Header.ChainID
}
// ValidateBasic makes sure this is consistent, without checking the sigs
func (u UpdateChainTx) ValidateBasic() error {
2017-07-18 07:05:36 -07:00
err := u.Seed.ValidateBasic(u.ChainID())
if err != nil {
err = ErrInvalidCommit(err)
}
return err
2017-07-13 10:22:05 -07:00
}
// Wrap - used to satisfy TxInner
func (u UpdateChainTx) Wrap() basecoin.Tx {
return basecoin.Tx{u}
}
2017-07-16 13:46:21 -07:00
// CreatePacketTx is meant to be called by IPC, another module...
2017-07-13 10:22:05 -07:00
//
// this is the tx that will be sent to another app and the permissions it
// comes with (which must be a subset of the permissions on the current tx)
//
2017-07-16 13:46:21 -07:00
// If must have the special `AllowIBC` permission from the app
// that can send this packet (so only coins can request SendTx packet)
type CreatePacketTx struct {
2017-07-18 08:16:28 -07:00
DestChain string `json:"dest_chain"`
Permissions basecoin.Actors `json:"permissions"`
Tx basecoin.Tx `json:"tx"`
2017-07-13 10:22:05 -07:00
}
// ValidateBasic makes sure this is consistent - used to satisfy TxInner
2017-07-16 13:46:21 -07:00
func (p CreatePacketTx) ValidateBasic() error {
2017-07-13 10:22:05 -07:00
if p.DestChain == "" {
2017-07-19 08:28:43 -07:00
return ErrWrongDestChain(p.DestChain)
2017-07-13 10:22:05 -07:00
}
return nil
}
// Wrap - used to satisfy TxInner
2017-07-16 13:46:21 -07:00
func (p CreatePacketTx) Wrap() basecoin.Tx {
2017-07-13 10:22:05 -07:00
return basecoin.Tx{p}
}
2017-07-16 13:46:21 -07:00
// PostPacketTx takes a wrapped packet from another chain and
2017-07-13 10:22:05 -07:00
// TODO!!!
2017-07-16 13:46:21 -07:00
// also think... which chains can relay packets???
// right now, enforce that these packets are only sent directly,
// not routed over the hub. add routing later.
type PostPacketTx struct {
// make sure we have this header...
2017-07-13 10:22:05 -07:00
FromChainID string // The immediate source of the packet, not always Packet.SrcChainID
FromChainHeight uint64 // The block height in which Packet was committed, to check Proof
2017-07-16 13:46:21 -07:00
// this proof must match the header and the packet.Bytes()
Proof *merkle.IAVLProof
2017-07-18 05:27:53 -07:00
Key []byte
2017-07-16 13:46:21 -07:00
Packet Packet
2017-07-13 10:22:05 -07:00
}
// ValidateBasic makes sure this is consistent - used to satisfy TxInner
2017-07-16 13:46:21 -07:00
func (p PostPacketTx) ValidateBasic() error {
2017-07-13 10:22:05 -07:00
// TODO
return nil
}
// Wrap - used to satisfy TxInner
2017-07-16 13:46:21 -07:00
func (p PostPacketTx) Wrap() basecoin.Tx {
2017-07-13 10:22:05 -07:00
return basecoin.Tx{p}
}