-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf1a77c
commit 90fd329
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} | ||
} |