-
Notifications
You must be signed in to change notification settings - Fork 368
/
msg_server.go
50 lines (38 loc) · 1.09 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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/pricefeed/types"
)
type msgServer struct {
keeper Keeper
}
// NewMsgServerImpl returns an implementation of the pricefeed MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{keeper: keeper}
}
var _ types.MsgServer = msgServer{}
func (k msgServer) PostPrice(goCtx context.Context, msg *types.MsgPostPrice) (*types.MsgPostPriceResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
from, err := sdk.AccAddressFromBech32(msg.From)
if err != nil {
return nil, err
}
_, err = k.keeper.GetOracle(ctx, msg.MarketID, from)
if err != nil {
return nil, err
}
_, err = k.keeper.SetPrice(ctx, from, msg.MarketID, msg.Price, msg.Expiry)
if err != nil {
return nil, err
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.From),
),
)
return &types.MsgPostPriceResponse{}, nil
}