-
Notifications
You must be signed in to change notification settings - Fork 45
/
msg_server_commit_claimed_rewards.go
54 lines (42 loc) · 1.63 KB
/
msg_server_commit_claimed_rewards.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package keeper
import (
"context"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
aptypes "github.com/elys-network/elys/x/assetprofile/types"
"github.com/elys-network/elys/x/commitment/types"
)
// CommitClaimedRewards commit the tokens on unclaimed store to committed
func (k msgServer) CommitClaimedRewards(goCtx context.Context, msg *types.MsgCommitClaimedRewards) (*types.MsgCommitClaimedRewardsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
assetProfile, found := k.assetProfileKeeper.GetEntry(ctx, msg.Denom)
if !found {
return nil, errorsmod.Wrapf(aptypes.ErrAssetProfileNotFound, "denom: %s", msg.Denom)
}
if !assetProfile.CommitEnabled {
return nil, errorsmod.Wrapf(types.ErrCommitDisabled, "denom: %s", msg.Denom)
}
// Get the Commitments for the creator
commitments := k.GetCommitments(ctx, msg.Creator)
// Decrease unclaimed tokens amount
err := commitments.SubClaimed(sdk.NewCoin(msg.Denom, msg.Amount))
if err != nil {
return nil, err
}
// Increase committed tokens
commitments.AddCommittedTokens(msg.Denom, msg.Amount, uint64(ctx.BlockTime().Unix()))
// Update the commitments
k.SetCommitments(ctx, commitments)
// Emit Hook commitment changed
k.AfterCommitmentChange(ctx, msg.Creator, sdk.Coins{sdk.NewCoin(msg.Denom, msg.Amount)})
// Emit blockchain event
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeCommitmentChanged,
sdk.NewAttribute(types.AttributeCreator, msg.Creator),
sdk.NewAttribute(types.AttributeAmount, msg.Amount.String()),
sdk.NewAttribute(types.AttributeDenom, msg.Denom),
),
)
return &types.MsgCommitClaimedRewardsResponse{}, nil
}