diff --git a/docs/spec/ibc/mvp1.md b/docs/spec/ibc/mvp1.md index 3cfaf88ce..50fc38bd8 100644 --- a/docs/spec/ibc/mvp1.md +++ b/docs/spec/ibc/mvp1.md @@ -12,9 +12,10 @@ The initial implementation of IBC will include just enough for simple coin trans // User facing API type IBCPacket struct { - DestAddr sdk.Address - Coins sdk.Coins - SrcChain string + SrcAddr sdk.Address + DestAddr sdk.Address + Coins sdk.Coins + SrcChain string DestChain string } @@ -26,6 +27,8 @@ type IBCTransferMsg struct { // Implements sdk.Msg type IBCReceiveMsg struct { IBCPacket + Relayer sdk.Address + Sequence int64 } // Internal API diff --git a/docs/spec/ibc/mvp2.md b/docs/spec/ibc/mvp2.md index 6cada51cc..f8ae465c3 100644 --- a/docs/spec/ibc/mvp2.md +++ b/docs/spec/ibc/mvp2.md @@ -35,6 +35,8 @@ type IBCTransferMsg struct { // Implements sdk.Msg type IBCReceiveMsg struct { Packet + Relayer sdk.Address + Sequence int64 } // Internal API diff --git a/x/ibc/handler.go b/x/ibc/handler.go new file mode 100644 index 000000000..a96ffe35c --- /dev/null +++ b/x/ibc/handler.go @@ -0,0 +1,25 @@ +package ibc + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func NewHandler(ibcm IBCMapper) sdk.Handler { + return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { + switch msg := msg.(type) { + case IBCTransferMsg: + return handleIBCTransferMsg(ctx, ibcm, msg) + case IBCReceiveMsg: + return handleIBCReceiveMsg(ctx, ibcm, msg) + } + } +} + +func handleIBCTransferMsg(ctx sdk.Context, ibcm IBCMapper, msg IBCTransferMsg) sdk.Result { + ibcm.PushPacket(ctx, msg.IBCPacket) + return sdk.Result{} +} + +func handleIBCReceiveMsg(ctx sdk.Context, ibcm IBCMapper, msg IBCReceiveMsg) sdk.Result { + seq := ibc.IngressSequence(packet.SrcChain) +} diff --git a/x/ibc/mapper.go b/x/ibc/mapper.go new file mode 100644 index 000000000..f91f500a5 --- /dev/null +++ b/x/ibc/mapper.go @@ -0,0 +1,25 @@ +package ibc + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type IBCMapper struct { + ibcKey sdk.StoreKey +} + +func NewIBCMapper(ibcKey sdk.StoreKey) IBCMapper { + return IBCMapper{ + ibcKey: ibcKey, + } +} + +func GetIngressKey(srcChain string) []byte { + return []byte(fmt.Sprintf("%s", srcChain)) +} + +func GetEgressKey(destChain string, index int64) []byte { + return []byte(fmt.Sprintf("%s/%d", destChain, index)) +} diff --git a/x/ibc/types.go b/x/ibc/types.go new file mode 100644 index 000000000..753e46848 --- /dev/null +++ b/x/ibc/types.go @@ -0,0 +1,54 @@ +package ibc + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + wire "github.com/cosmos/cosmos-sdk/wire" +) + +type IBCPacket struct { + SrcAddr sdk.Address + DestAddr sdk.Address + Coins sdk.Coins + SrcChain string + DestChain string +} + +func newCodec() *wire.Codec { + return wire.NewCodec() +} + +type IBCTransferMsg struct { + IBCPacket +} + +func (msg IBCTransferMsg) Type() string { + return "ibctransfer" +} + +func (msg IBCTransferMsg) Get(key interface{}) interface{} { + return nil +} + +func (msg IBCTransferMsg) GetSignBytes() []byte { + cdc := newCodec() + bz, err := cdc.MarshalBinary(msg) + if err != nil { + panic(err) + } + return bz +} + +func (msg IBCTransferMsg) ValidateBasic() sdk.Error { + return msg.Coins.ValidateBasic() +} + +// x/bank/tx.go SendMsg.GetSigners() +func (msg IBCTransferMsg) GetSigners() []sdk.Address { + addrs := []sdk.Address{msg.SrcAddr} +} + +type IBCReceiveMsg struct { + IBCPacket + Relayer sdk.Address +}