Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mossid committed Jun 13, 2019
1 parent 7445bfd commit d7d32e5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion x/ibc/03-connection/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (obj Object) ID() string {
return obj.id
}

func (obj Object) Client(ctx sdk.Context) client.Client {
func (obj Object) Client(ctx sdk.Context) client.ConsensusState {
return obj.client.Value(ctx)
}

Expand Down
45 changes: 23 additions & 22 deletions x/ibc/04-channel/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/mapping"
"github.com/cosmos/cosmos-sdk/store/state"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
Expand All @@ -13,7 +13,7 @@ import (

// Manager is unrestricted
type Manager struct {
protocol mapping.Mapping
protocol state.Mapping

connection connection.Manager

Expand All @@ -26,9 +26,9 @@ type CounterpartyManager struct {
connection connection.CounterpartyManager
}

func NewManager(protocol mapping.Base, connection connection.Manager) Manager {
func NewManager(protocol state.Base, connection connection.Manager) Manager {
return Manager{
protocol: mapping.NewMapping(protocol, []byte("/connection/")),
protocol: state.NewMapping(protocol, []byte("/connection/")),
connection: connection,
counterparty: NewCounterpartyManager(protocol.Cdc()),
}
Expand All @@ -49,13 +49,13 @@ func (man Manager) object(connid, chanid string) Object {
return Object{
chanid: chanid,
channel: man.protocol.Value([]byte(key)),
state: mapping.NewEnum(man.protocol.Value([]byte(key + "/state"))),
nexttimeout: mapping.NewInteger(man.protocol.Value([]byte(key+"/timeout")), mapping.Dec),
state: state.NewEnum(man.protocol.Value([]byte(key + "/state"))),
nexttimeout: state.NewInteger(man.protocol.Value([]byte(key+"/timeout")), state.Dec),

// TODO: remove length functionality from mapping.Indeer(will be handled manually)
seqsend: mapping.NewInteger(man.protocol.Value([]byte(key+"/nextSequenceSend")), mapping.Dec),
seqrecv: mapping.NewInteger(man.protocol.Value([]byte(key+"/nextSequenceRecv")), mapping.Dec),
packets: mapping.NewIndexer(man.protocol.Prefix([]byte(key+"/packets/")), mapping.Dec),
// TODO: remove length functionality from state.Indeer(will be handled manually)
seqsend: state.NewInteger(man.protocol.Value([]byte(key+"/nextSequenceSend")), state.Dec),
seqrecv: state.NewInteger(man.protocol.Value([]byte(key+"/nextSequenceRecv")), state.Dec),
packets: state.NewIndexer(man.protocol.Prefix([]byte(key+"/packets/")), state.Dec),
}
}

Expand All @@ -65,11 +65,11 @@ func (man CounterpartyManager) object(connid, chanid string) CounterObject {
chanid: chanid,
channel: man.protocol.Value([]byte(key)),
state: commitment.NewEnum(man.protocol.Value([]byte(key + "/state"))),
nexttimeout: commitment.NewInteger(man.protocol.Value([]byte(key+"/timeout")), mapping.Dec),
nexttimeout: commitment.NewInteger(man.protocol.Value([]byte(key+"/timeout")), state.Dec),

seqsend: commitment.NewInteger(man.protocol.Value([]byte(key+"/nextSequenceSend")), mapping.Dec),
seqrecv: commitment.NewInteger(man.protocol.Value([]byte(key+"/nextSequenceRecv")), mapping.Dec),
packets: commitment.NewIndexer(man.protocol.Prefix([]byte(key+"/packets")), mapping.Dec),
seqsend: commitment.NewInteger(man.protocol.Value([]byte(key+"/nextSequenceSend")), state.Dec),
seqrecv: commitment.NewInteger(man.protocol.Value([]byte(key+"/nextSequenceRecv")), state.Dec),
packets: commitment.NewIndexer(man.protocol.Prefix([]byte(key+"/packets")), state.Dec),
}
}

Expand Down Expand Up @@ -161,13 +161,13 @@ func (man ModuleManager) Query(ctx sdk.Context, connid, chanid string) (Object,

type Object struct {
chanid string
channel mapping.Value
state mapping.Enum
nexttimeout mapping.Integer
channel state.Value
state state.Enum
nexttimeout state.Integer

seqsend mapping.Integer
seqrecv mapping.Integer
packets mapping.Indexer
seqsend state.Integer
seqrecv state.Integer
packets state.Indexer

connection connection.Object

Expand Down Expand Up @@ -227,6 +227,7 @@ func (obj Object) OpenInit(ctx sdk.Context) error {
return nil
}

/*
func (obj Object) OpenTry(ctx sdk.Context, timeoutHeight, nextTimeoutHeight uint64) error {
if !obj.state.Transit(ctx, Idle, OpenTry) {
return errors.New("opentry on non-idle channel")
Expand All @@ -239,7 +240,7 @@ func (obj Object) OpenTry(ctx sdk.Context, timeoutHeight, nextTimeoutHeight uint
// XXX
}

*/
func (obj Object) Send(ctx sdk.Context, packet Packet) error {
if obj.state.Get(ctx) != Open {
return errors.New("send on non-open channel")
Expand All @@ -249,7 +250,7 @@ func (obj Object) Send(ctx sdk.Context, packet Packet) error {
return errors.New("send on non-open connection")
}

if uint64(obj.connection.Client(ctx).GetBase().GetHeight()) >= packet.Timeout() {
if uint64(obj.connection.Client(ctx).GetHeight()) >= packet.Timeout() {
return errors.New("timeout height higher than the latest known")
}

Expand Down
6 changes: 3 additions & 3 deletions x/ibc/23-commitment/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ func (m Mapping) Prefix(prefix []byte) Mapping {

type Indexer struct {
Mapping
enc mapping.IntEncoding
enc state.IntEncoding
}

func NewIndexer(m Mapping, enc mapping.IntEncoding) Indexer {
func NewIndexer(m Mapping, enc state.IntEncoding) Indexer {
return Indexer{
Mapping: m,
enc: enc,
}
}

func (ix Indexer) Value(index uint64) Value {
return ix.Mapping.Value(mapping.EncodeInt(index, ix.enc))
return ix.Mapping.Value(state.EncodeInt(index, ix.enc))
}

type Value struct {
Expand Down

0 comments on commit d7d32e5

Please sign in to comment.