-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_server.go
84 lines (67 loc) · 2.01 KB
/
msg_server.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/furya-official/mage/x/liquid/types"
)
type msgServer struct {
keeper Keeper
}
// NewMsgServerImpl returns an implementation of the liquid MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{keeper: keeper}
}
var _ types.MsgServer = msgServer{}
// MintDerivative handles MintDerivative msgs.
func (k msgServer) MintDerivative(goCtx context.Context, msg *types.MsgMintDerivative) (*types.MsgMintDerivativeResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
validator, err := sdk.ValAddressFromBech32(msg.Validator)
if err != nil {
return nil, err
}
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return nil, err
}
mintedDerivative, err := k.keeper.MintDerivative(ctx, sender, validator, msg.Amount)
if err != nil {
return nil, err
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
),
)
return &types.MsgMintDerivativeResponse{
Received: mintedDerivative,
}, nil
}
// BurnDerivative handles BurnDerivative msgs.
func (k msgServer) BurnDerivative(goCtx context.Context, msg *types.MsgBurnDerivative) (*types.MsgBurnDerivativeResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return nil, err
}
validator, err := sdk.ValAddressFromBech32(msg.Validator)
if err != nil {
return nil, err
}
sharesReceived, err := k.keeper.BurnDerivative(ctx, sender, validator, msg.Amount)
if err != nil {
return nil, err
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
),
)
return &types.MsgBurnDerivativeResponse{
Received: sharesReceived,
}, nil
}