diff --git a/modules/ibc/handler.go b/modules/ibc/handler.go index 380fd88dd..91eb3478a 100644 --- a/modules/ibc/handler.go +++ b/modules/ibc/handler.go @@ -173,7 +173,7 @@ func (h Handler) createPacket(ctx basecoin.Context, store state.KVStore, // start making the packet to send packet := Packet{ - DestChain: t.DestChain, + DestChain: dest, Tx: t.Tx, Permissions: make([]basecoin.Actor, len(t.Permissions)), } @@ -188,6 +188,9 @@ func (h Handler) createPacket(ctx basecoin.Context, store state.KVStore, } // now add it to the output queue.... - // TODO: where to store, also set the sequence.... + q := OutputQueue(store, dest) + packet.Sequence = q.Tail() + q.Push(packet.Bytes()) + return res, nil } diff --git a/modules/ibc/store.go b/modules/ibc/store.go index 2aa34c492..810377d89 100644 --- a/modules/ibc/store.go +++ b/modules/ibc/store.go @@ -12,8 +12,12 @@ const ( // we otherwise use the chainid as prefix, so this must not be an // alpha-numeric byte prefixChains = "**" + + prefixInput = "i" + prefixOutput = "o" ) +// this is used for the global handler info var ( handlerKey = []byte{0x2} ) @@ -77,7 +81,7 @@ func (c ChainSet) Register(chainID string, ourHeight uint64, theirHeight int) er // send off to another chain. type Packet struct { DestChain string `json:"dest_chain"` - Sequence int `json:"sequence"` + Sequence uint64 `json:"sequence"` Permissions []basecoin.Actor `json:"permissions"` Tx basecoin.Tx `json:"tx"` } @@ -86,3 +90,17 @@ type Packet struct { func (p Packet) Bytes() []byte { return wire.BinaryBytes(p) } + +// InputQueue returns the queue of input packets from this chain +func InputQueue(store state.KVStore, chainID string) *state.Queue { + ch := stack.PrefixedStore(chainID, store) + space := stack.PrefixedStore(prefixInput, ch) + return state.NewQueue(space) +} + +// OutputQueue returns the queue of output packets destined for this chain +func OutputQueue(store state.KVStore, chainID string) *state.Queue { + ch := stack.PrefixedStore(chainID, store) + space := stack.PrefixedStore(prefixOutput, ch) + return state.NewQueue(space) +}