Skip to content

Commit

Permalink
batch claim wasmbinding addition
Browse files Browse the repository at this point in the history
  • Loading branch information
antstalepresh committed Nov 6, 2023
1 parent cf1a77c commit 90fd329
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 2 additions & 0 deletions wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package bindings

import (
batch "github.com/Team-Kujira/core/x/batch/wasm"
denom "github.com/Team-Kujira/core/x/denom/wasm"
)

type CosmosMsg struct {
Denom *denom.DenomMsg
Batch *batch.BatchMsg
}
10 changes: 8 additions & 2 deletions wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (

"github.com/Team-Kujira/core/wasmbinding/bindings"

denom "github.com/Team-Kujira/core/x/denom/wasm"

batchkeeper "github.com/Team-Kujira/core/x/batch/keeper"
batch "github.com/Team-Kujira/core/x/batch/wasm"
denomkeeper "github.com/Team-Kujira/core/x/denom/keeper"
denom "github.com/Team-Kujira/core/x/denom/wasm"
)

// CustomMessageDecorator returns decorator for custom CosmWasm bindings messages
Expand All @@ -34,6 +35,7 @@ type CustomMessenger struct {
wrapped wasmkeeper.Messenger
bank bankkeeper.Keeper
denom denomkeeper.Keeper
batch batchkeeper.Keeper
}

var _ wasmkeeper.Messenger = (*CustomMessenger)(nil)
Expand All @@ -57,6 +59,10 @@ func (m *CustomMessenger) DispatchMsg(
return denom.HandleMsg(m.denom, m.bank, contractAddr, ctx, contractMsg.Denom)
}

if contractMsg.Batch != nil {
return batch.HandleMsg(m.batch, contractAddr, ctx, contractMsg.Batch)
}

return nil, nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown Custom variant"}
}
return m.wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg)
Expand Down
57 changes: 57 additions & 0 deletions x/batch/wasm/interface_msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package wasm

import (
"cosmossdk.io/errors"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
batchkeeper "github.com/Team-Kujira/core/x/batch/keeper"
batchtypes "github.com/Team-Kujira/core/x/batch/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

type BatchMsg struct {
// Contracts can withdraw all rewards for the delegations from the contract.
WithdrawAllDelegatorRewards *WithdrawAllDelegatorRewards `json:"withdrawAllDelegatorRewards,omitempty"`
}

type WithdrawAllDelegatorRewards struct{}

// withdrawAllDelegatorRewards withdraw all delegation rewards for the delegations from the contract address
func withdrawAllDelegatorRewards(ctx sdk.Context, contractAddr sdk.AccAddress, withdrawAllDelegatorRewards *WithdrawAllDelegatorRewards, bk batchkeeper.Keeper) ([]sdk.Event, [][]byte, error) {
err := PerformWithdrawAllDelegatorRewards(bk, ctx, contractAddr, withdrawAllDelegatorRewards)
if err != nil {
return nil, nil, errors.Wrap(err, "perform withdrawAllDelegatorRewards denom")
}
return nil, nil, nil
}

// PerformWithdrawAllDelegatorRewards is used to perform delegation rewards from the contract delegations
func PerformWithdrawAllDelegatorRewards(bk batchkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, withdrawAllDelegatorRewards *WithdrawAllDelegatorRewards) error {
if withdrawAllDelegatorRewards == nil {
return wasmvmtypes.InvalidRequest{Err: "withdrawAllDelegatorRewards denom null withdrawAllDelegatorRewards denom"}
}

msgServer := batchkeeper.NewMsgServerImpl(bk)
msgWithdrawAllDelegatorRewards := batchtypes.NewMsgWithdrawAllDelegatorRewards(contractAddr)

if err := msgWithdrawAllDelegatorRewards.ValidateBasic(); err != nil {
return errors.Wrap(err, "failed validating MsgWithdrawAllDelegatorRewards")
}

_, err := msgServer.WithdrawAllDelegatorRewards(
sdk.WrapSDKContext(ctx),
msgWithdrawAllDelegatorRewards,
)
if err != nil {
return errors.Wrap(err, "creating denom")
}
return nil
}

// QueryCustom implements custom msg interface
func HandleMsg(dk batchkeeper.Keeper, contractAddr sdk.AccAddress, ctx sdk.Context, q *BatchMsg) ([]sdk.Event, [][]byte, error) {
if q.WithdrawAllDelegatorRewards != nil {
return withdrawAllDelegatorRewards(ctx, contractAddr, q.WithdrawAllDelegatorRewards, dk)
}

return nil, nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown Custom variant"}
}

0 comments on commit 90fd329

Please sign in to comment.