cosmos-sdk/x/ibc/core/simulation/decoder.go
Federico Kunze 2c93ec7a0c
ibc: core restructure (#7434)
* ibc: protobuf v1

* update codec

* core client

* core connection

* core host

* core commitment

* core port

* core channel

* core ibc module files

* core exported

* core types & simulation

* core spec

* make proto-all

* ibc alias
2020-10-02 06:03:02 -03:00

33 lines
1.0 KiB
Go

package simulation
import (
"fmt"
"github.com/cosmos/cosmos-sdk/types/kv"
clientsim "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/simulation"
connectionsim "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/simulation"
channelsim "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/simulation"
host "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host"
"github.com/cosmos/cosmos-sdk/x/ibc/core/keeper"
)
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
// Value to the corresponding ibc type.
func NewDecodeStore(k keeper.Keeper) func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
if res, found := clientsim.NewDecodeStore(k.ClientKeeper, kvA, kvB); found {
return res
}
if res, found := connectionsim.NewDecodeStore(k.Codec(), kvA, kvB); found {
return res
}
if res, found := channelsim.NewDecodeStore(k.Codec(), kvA, kvB); found {
return res
}
panic(fmt.Sprintf("invalid %s key prefix: %s", host.ModuleName, string(kvA.Key)))
}
}