mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-27 00:35:18 +00:00
a573625df8
* bump SDK version to v0.38.3 Co-authored-by: Denali Marsh <denali@kava.io> Co-authored-by: Kevin Davis <kjydavis3@gmail.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> Co-authored-by: denalimarsh <denalimarsh@gmail.com> Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package pricefeed
|
|
|
|
import (
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
)
|
|
|
|
// NewHandler handles all pricefeed type messages
|
|
func NewHandler(k Keeper) sdk.Handler {
|
|
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
|
switch msg := msg.(type) {
|
|
case MsgPostPrice:
|
|
return HandleMsgPostPrice(ctx, k, msg)
|
|
default:
|
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg)
|
|
}
|
|
}
|
|
}
|
|
|
|
// price feed questions:
|
|
// do proposers need to post the round in the message? If not, how do we determine the round?
|
|
|
|
// HandleMsgPostPrice handles prices posted by oracles
|
|
func HandleMsgPostPrice(
|
|
ctx sdk.Context,
|
|
k Keeper,
|
|
msg MsgPostPrice) (*sdk.Result, error) {
|
|
|
|
_, err := k.GetOracle(ctx, msg.MarketID, msg.From)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
_, err = k.SetPrice(ctx, msg.From, msg.MarketID, msg.Price, msg.Expiry)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory),
|
|
sdk.NewAttribute(sdk.AttributeKeySender, msg.From.String()),
|
|
),
|
|
)
|
|
|
|
return &sdk.Result{Events: ctx.EventManager().Events()}, nil
|
|
}
|