Skip to content

Commit

Permalink
add wasm binding
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Jul 26, 2023
1 parent 9f200c1 commit ad4a82f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bindings

import (
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/sei-protocol/sei-chain/x/dex/types"
)

Expand All @@ -22,6 +23,10 @@ type ChangeAdmin struct {
NewAdminAddress string `json:"new_admin_address"`
}

type SetMetadata struct {
Metadata banktypes.Metadata `json:"metadata"`
}

type MintTokens struct {
Amount sdk.Coin `json:"amount"`
}
Expand Down
3 changes: 3 additions & 0 deletions wasmbinding/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type SeiWasmMessage struct {
MintTokens json.RawMessage `json:"mint_tokens,omitempty"`
BurnTokens json.RawMessage `json:"burn_tokens,omitempty"`
ChangeAdmin json.RawMessage `json:"change_admin,omitempty"`
SetMetadata json.RawMessage `json:"set_metadata,omitempty"`
}

func CustomEncoder(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error) {
Expand All @@ -37,6 +38,8 @@ func CustomEncoder(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error
return tokenfactorywasm.EncodeTokenFactoryBurn(parsedMessage.BurnTokens, sender)
case parsedMessage.ChangeAdmin != nil:
return tokenfactorywasm.EncodeTokenFactoryChangeAdmin(parsedMessage.ChangeAdmin, sender)
case parsedMessage.SetMetadata != nil:
return tokenfactorywasm.EncodeTokenFactorySetMetadata(parsedMessage.SetMetadata, sender)
default:
return []sdk.Msg{}, wasmvmtypes.UnsupportedRequest{Kind: "Unknown Sei Wasm Message"}
}
Expand Down
12 changes: 12 additions & 0 deletions x/tokenfactory/client/wasm/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,15 @@ func EncodeTokenFactoryChangeAdmin(rawMsg json.RawMessage, sender sdk.AccAddress
}
return []sdk.Msg{&changeAdminMsg}, nil
}

func EncodeTokenFactorySetMetadata(rawMsg json.RawMessage, sender sdk.AccAddress) ([]sdk.Msg, error) {
encodedSetMetadataMsg := bindings.SetMetadata{}
if err := json.Unmarshal(rawMsg, &encodedSetMetadataMsg); err != nil {
return []sdk.Msg{}, types.ErrEncodeTokenFactorySetMetadata
}
setMetadataMsg := types.MsgSetDenomMetadata{
Sender: sender.String(),
Metadata: encodedSetMetadataMsg.Metadata,
}
return []sdk.Msg{&setMetadataMsg}, nil
}
1 change: 1 addition & 0 deletions x/tokenfactory/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ var (
ErrEncodeTokenFactoryChangeAdmin = sdkerrors.Register(ModuleName, 14, "Error while encoding tokenfactory change admin msg in wasmd")
ErrParsingSeiTokenFactoryQuery = sdkerrors.Register(ModuleName, 15, "Error parsing SeiTokenFactoryQuery")
ErrAdminAlreadyExists = sdkerrors.Register(ModuleName, 16, "attempting to create a new admin that already exists for the denom")
ErrEncodeTokenFactorySetMetadata = sdkerrors.Register(ModuleName, 17, "Error while encoding tokenfactory set metadata msg in wasmd")
ErrUnknownSeiTokenFactoryQuery = sdkerrors.Register(ModuleName, 23, "Error unknown sei token factory query")
)

0 comments on commit ad4a82f

Please sign in to comment.