structure

This commit is contained in:
mossid 2018-03-14 13:11:33 +01:00
parent 5ebdff2e5e
commit 1cb795ba73
5 changed files with 112 additions and 3 deletions

View File

@ -12,9 +12,10 @@ The initial implementation of IBC will include just enough for simple coin trans
// User facing API // User facing API
type IBCPacket struct { type IBCPacket struct {
DestAddr sdk.Address SrcAddr sdk.Address
Coins sdk.Coins DestAddr sdk.Address
SrcChain string Coins sdk.Coins
SrcChain string
DestChain string DestChain string
} }
@ -26,6 +27,8 @@ type IBCTransferMsg struct {
// Implements sdk.Msg // Implements sdk.Msg
type IBCReceiveMsg struct { type IBCReceiveMsg struct {
IBCPacket IBCPacket
Relayer sdk.Address
Sequence int64
} }
// Internal API // Internal API

View File

@ -35,6 +35,8 @@ type IBCTransferMsg struct {
// Implements sdk.Msg // Implements sdk.Msg
type IBCReceiveMsg struct { type IBCReceiveMsg struct {
Packet Packet
Relayer sdk.Address
Sequence int64
} }
// Internal API // Internal API

25
x/ibc/handler.go Normal file
View File

@ -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)
}

25
x/ibc/mapper.go Normal file
View File

@ -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))
}

54
x/ibc/types.go Normal file
View File

@ -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
}