Skip to content

Commit

Permalink
Add mint rewards custom message place-holder
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Oct 31, 2024
1 parent 9b24046 commit 8dfeaea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
23 changes: 15 additions & 8 deletions x/babylon/contract/in_message.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package contract

// CustomMsg is a message sent from a smart contract to the Babylon module
// TODO: implement
type CustomMsg struct {
Test *TestMsg `json:"test,omitempty"`
}
import (
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
)

type TestMsg struct {
Placeholder string `json:"placeholder,omitempty"`
}
// CustomMsg is a message sent from a smart contract to the Babylon module
type (
CustomMsg struct {
MintRewards *MintRewardsMsg `json:"mint_rewards,omitempty"`
}
// MintRewardsMsg mints the specified number of block rewards,
// and sends them to the specified recipient (typically, the staking contract)
MintRewardsMsg struct {
Amount wasmvmtypes.Coin `json:"amount"`
Recipient string `json:"recipient"`
}
)
6 changes: 3 additions & 3 deletions x/babylon/keeper/handler_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (h CustomMsgHandler) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre
if err := json.Unmarshal(msg.Custom, &customMsg); err != nil {
return nil, nil, nil, sdkerrors.ErrJSONUnmarshal.Wrap("custom message")
}
if customMsg.Test == nil {
if customMsg.MintRewards == nil {
// not our message type
return nil, nil, nil, wasmtypes.ErrUnknownMsg
}
Expand All @@ -64,10 +64,10 @@ func (h CustomMsgHandler) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre
return nil, nil, nil, sdkerrors.ErrUnauthorized.Wrapf("contract has no permission for Babylon operations")
}

return h.handleTestMsg(ctx, contractAddr, customMsg.Test)
return h.handleMintRewardsMsg(ctx, contractAddr, customMsg.MintRewards)
}

func (h CustomMsgHandler) handleTestMsg(ctx sdk.Context, actor sdk.AccAddress, testMsg *contract.TestMsg) ([]sdk.Event, [][]byte, [][]*codectypes.Any, error) {
func (h CustomMsgHandler) handleMintRewardsMsg(ctx sdk.Context, actor sdk.AccAddress, mintRewardsMsg *contract.MintRewardsMsg) ([]sdk.Event, [][]byte, [][]*codectypes.Any, error) {
return []sdk.Event{}, nil, nil, nil
}

Expand Down

0 comments on commit 8dfeaea

Please sign in to comment.