From c409455150250e2e559648d6bd7cd17d17325401 Mon Sep 17 00:00:00 2001 From: Adrian Brink Date: Thu, 15 Mar 2018 14:54:44 +0100 Subject: [PATCH] IBC module --- Gopkg.toml | 5 ----- docs/spec/ibc/mvp1.md | 17 +++++++++++------ x/ibc/mapper.go | 3 +-- x/ibc/types.go | 23 ++++++++++++++++++++--- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Gopkg.toml b/Gopkg.toml index 1cbd701e2..6e5913e26 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -24,7 +24,6 @@ # go-tests = true # unused-packages = true - [[constraint]] name = "github.com/bgentry/speakeasy" version = "0.1.0" @@ -41,10 +40,6 @@ name = "github.com/pkg/errors" version = "0.8.0" -# [[constraint]] -# branch = "master" -# name = "github.com/rigelrozanski/common" - [[constraint]] name = "github.com/spf13/cobra" version = "0.0.1" diff --git a/docs/spec/ibc/mvp1.md b/docs/spec/ibc/mvp1.md index 50fc38bd8..7901e3ba8 100644 --- a/docs/spec/ibc/mvp1.md +++ b/docs/spec/ibc/mvp1.md @@ -1,14 +1,17 @@ # IBC Spec -*This is a living document and should be edited as the IBC spec and implementation change* +*This is a living document and should be edited as the IBC spec and +implementation change* ## MVP1 -The initial implementation of IBC will include just enough for simple coin transfers between chains, with safety features such as ACK messages being added later. +The initial implementation of IBC will include just enough for simple coin +transfers between chains, with safety features such as ACK messages being added +later. ### IBC Module -```golang +```go // User facing API type IBCPacket struct { @@ -47,12 +50,14 @@ type EgressKey struct { DestChain string Index int64 } - ``` -`egressKey` stores the outgoing `IBCTransfer`s as a list. Its getter takes an `EgressKey` and returns the length if `egressKey.Index == -1`, an element if `egressKey.Index > 0`. +`egressKey` stores the outgoing `IBCTransfer`s as a list. Its getter takes an +`EgressKey` and returns the length if `egressKey.Index == -1`, an element if +`egressKey.Index > 0`. -`ingressKey` stores the last income `IBCTransfer`'s sequence. Its getter takes an `IngressKey`. +`ingressKey` stores the latest income `IBCTransfer`'s sequence. It's getter +takes an `IngressKey`. ## Relayer diff --git a/x/ibc/mapper.go b/x/ibc/mapper.go index e03582322..4dd473963 100644 --- a/x/ibc/mapper.go +++ b/x/ibc/mapper.go @@ -10,8 +10,7 @@ import ( type IBCMapper struct { ibcKey sdk.StoreKey - - cdc *wire.Codec + cdc *wire.Codec } func NewIBCMapper(ibcKey sdk.StoreKey) IBCMapper { diff --git a/x/ibc/types.go b/x/ibc/types.go index 9156bd02a..cf1e472e7 100644 --- a/x/ibc/types.go +++ b/x/ibc/types.go @@ -6,6 +6,11 @@ import ( wire "github.com/cosmos/cosmos-sdk/wire" ) +// ------------------------------ +// IBCPacket + +// IBCPacket defines a piece of data that can be send between two separate +// blockchains. type IBCPacket struct { SrcAddr sdk.Address DestAddr sdk.Address @@ -14,10 +19,10 @@ type IBCPacket struct { DestChain string } -func newCodec() *wire.Codec { - return wire.NewCodec() -} +// ---------------------------------- +// IBCTransferMsg +// IBCTransferMsg defines how another module can send an IBCPacket. type IBCTransferMsg struct { IBCPacket } @@ -48,6 +53,11 @@ func (msg IBCTransferMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.SrcAddr} } +// ---------------------------------- +// IBCReceiveMsg + +// IBCReceiveMsg defines the message that a relayer uses to post an IBCPacket +// to the destination chain. type IBCReceiveMsg struct { IBCPacket Relayer sdk.Address @@ -79,3 +89,10 @@ func (msg IBCReceiveMsg) ValidateBasic() sdk.Error { func (msg IBCReceiveMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.Relayer} } + +// ------------------------- +// Helpers + +func newCodec() *wire.Codec { + return wire.NewCodec() +}