Skip to content

Commit

Permalink
Updated swap module
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Mar 12, 2022
1 parent f3ad22d commit bca16bf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion x/swap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
res, err := server.MsgSwap(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
default:
return nil, errors.Wrapf(types.ErrorUnknownMsgType, "%s", msg.Type())
return nil, errors.Wrapf(types.ErrorUnknownMsgType, "%T", msg)
}
}
}
4 changes: 2 additions & 2 deletions x/swap/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
)

type Keeper struct {
cdc codec.BinaryMarshaler
cdc codec.BinaryCodec
key sdk.StoreKey
params paramstypes.Subspace
account expected.AccountKeeper
bank expected.BankKeeper
}

func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, params paramstypes.Subspace, account expected.AccountKeeper, bank expected.BankKeeper) Keeper {
func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, params paramstypes.Subspace, account expected.AccountKeeper, bank expected.BankKeeper) Keeper {
return Keeper{
cdc: cdc,
key: key,
Expand Down
2 changes: 1 addition & 1 deletion x/swap/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (q *queryServer) QuerySwaps(c context.Context, req *types.QuerySwapsRequest

pagination, err := query.FilteredPaginate(store, req.Pagination, func(_, value []byte, accumulate bool) (bool, error) {
var item types.Swap
if err := q.cdc.UnmarshalBinaryBare(value, &item); err != nil {
if err := q.cdc.Unmarshal(value, &item); err != nil {
return false, err
}

Expand Down
6 changes: 3 additions & 3 deletions x/swap/keeper/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func (k *Keeper) SetSwap(ctx sdk.Context, swap types.Swap) {
key := types.SwapKey(swap.GetTxHash())
value := k.cdc.MustMarshalBinaryBare(&swap)
value := k.cdc.MustMarshal(&swap)

store := k.Store(ctx)
store.Set(key, value)
Expand All @@ -24,7 +24,7 @@ func (k *Keeper) GetSwap(ctx sdk.Context, txHash types.EthereumHash) (swap types
return swap, false
}

k.cdc.MustUnmarshalBinaryBare(value, &swap)
k.cdc.MustUnmarshal(value, &swap)
return swap, true
}

Expand All @@ -48,7 +48,7 @@ func (k *Keeper) GetSwaps(ctx sdk.Context, skip, limit int64) (items types.Swaps
iter.Skip(skip)
iter.Limit(limit, func(iter sdk.Iterator) {
var item types.Swap
k.cdc.MustUnmarshalBinaryBare(iter.Value(), &item)
k.cdc.MustUnmarshal(iter.Value(), &item)
items = append(items, item)
})

Expand Down
14 changes: 8 additions & 6 deletions x/swap/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func (a AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry
types.RegisterInterfaces(registry)
}

func (a AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
func (a AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}

func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, _ client.TxEncodingConfig, message json.RawMessage) error {
func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, message json.RawMessage) error {
var state types.GenesisState
if err := cdc.UnmarshalJSON(message, &state); err != nil {
return err
Expand All @@ -74,26 +74,26 @@ func (a AppModuleBasic) GetQueryCmd() *cobra.Command {

type AppModule struct {
AppModuleBasic
cdc codec.Marshaler
cdc codec.Codec
k keeper.Keeper
}

func NewAppModule(cdc codec.Marshaler, k keeper.Keeper) AppModule {
func NewAppModule(cdc codec.Codec, k keeper.Keeper) AppModule {
return AppModule{
cdc: cdc,
k: k,
}
}

func (a AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, message json.RawMessage) []abcitypes.ValidatorUpdate {
func (a AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, message json.RawMessage) []abcitypes.ValidatorUpdate {
var state types.GenesisState
cdc.MustUnmarshalJSON(message, &state)
InitGenesis(ctx, a.k, &state)

return nil
}

func (a AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage {
func (a AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(ExportGenesis(ctx, a.k))
}

Expand All @@ -115,6 +115,8 @@ func (a AppModule) RegisterServices(configurator module.Configurator) {
types.RegisterQueryServiceServer(configurator.QueryServer(), keeper.NewQueryServiceServer(a.k))
}

func (a AppModule) ConsensusVersion() uint64 { return 1 }

func (a AppModule) BeginBlock(_ sdk.Context, _ abcitypes.RequestBeginBlock) {}

func (a AppModule) EndBlock(_ sdk.Context, _ abcitypes.RequestEndBlock) []abcitypes.ValidatorUpdate {
Expand Down
6 changes: 3 additions & 3 deletions x/swap/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/sentinel-official/hub/x/swap/types"
)

func NewStoreDecoder(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string {
func NewStoreDecoder(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
if bytes.Equal(kvA.Key[:1], types.SwapKeyPrefix) {
var swapA, swapB types.MsgSwapRequest
cdc.MustUnmarshalBinaryBare(kvA.Value, &swapA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &swapB)
cdc.MustUnmarshal(kvA.Value, &swapA)
cdc.MustUnmarshal(kvB.Value, &swapB)

return fmt.Sprintf("%v\n%v", swapA, swapB)
}
Expand Down

0 comments on commit bca16bf

Please sign in to comment.