/
msg_server_claim_for.go
49 lines (46 loc) · 1.25 KB
/
msg_server_claim_for.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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/public-awesome/stargaze/v5/x/claim/types"
)
func (k msgServer) ClaimFor(goCtx context.Context, msg *types.MsgClaimFor) (*types.MsgClaimForResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return nil, err
}
address, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
return nil, err
}
params := k.GetParams(ctx)
if !params.IsAirdropEnabled(ctx.BlockTime()) {
return nil, types.ErrAirdropNotEnabled
}
allowed := false
for _, authorization := range params.AllowedClaimers {
if authorization.ContractAddress == msg.Sender && authorization.Action == msg.Action {
allowed = true
break
}
}
if !allowed {
return nil, types.ErrUnauthorizedClaimer
}
coins, err := k.Keeper.ClaimCoinsForAction(ctx, address, msg.GetAction())
if err != nil {
return nil, err
}
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
),
})
return &types.MsgClaimForResponse{
Address: msg.Address,
ClaimedAmount: coins,
}, nil
}