2020-06-10 01:09:51 -07:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-07-30 07:53:02 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/kv"
|
2020-10-02 02:03:02 -07:00
|
|
|
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"
|
2020-06-10 01:09:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
|
|
|
|
// Value to the corresponding ibc type.
|
2020-08-07 01:33:47 -07:00
|
|
|
func NewDecodeStore(k keeper.Keeper) func(kvA, kvB kv.Pair) string {
|
2020-07-30 07:53:02 -07:00
|
|
|
return func(kvA, kvB kv.Pair) string {
|
2020-08-07 01:33:47 -07:00
|
|
|
if res, found := clientsim.NewDecodeStore(k.ClientKeeper, kvA, kvB); found {
|
2020-06-10 01:09:51 -07:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2020-08-07 01:33:47 -07:00
|
|
|
if res, found := connectionsim.NewDecodeStore(k.Codec(), kvA, kvB); found {
|
2020-06-10 01:09:51 -07:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2020-08-07 01:33:47 -07:00
|
|
|
if res, found := channelsim.NewDecodeStore(k.Codec(), kvA, kvB); found {
|
2020-06-10 01:09:51 -07:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
panic(fmt.Sprintf("invalid %s key prefix: %s", host.ModuleName, string(kvA.Key)))
|
|
|
|
}
|
|
|
|
}
|