Skip to content

Commit

Permalink
feat(oracle):add updateparams service
Browse files Browse the repository at this point in the history
  • Loading branch information
leonz789 committed Apr 13, 2024
1 parent bd5ffc8 commit ede2652
Show file tree
Hide file tree
Showing 6 changed files with 509 additions and 26 deletions.
21 changes: 20 additions & 1 deletion proto/exocore/oracle/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ syntax = "proto3";
package exocore.oracle;

import "exocore/oracle/price.proto";
import "exocore/oracle/params.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

import "amino/amino.proto";
import "cosmos/msg/v1/msg.proto";
option go_package = "github.com/ExocoreNetwork/exocore/x/oracle/types";

// Msg defines the Msg service.
service Msg {
//create price for a new oracle round
rpc CreatePrice (MsgCreatePrice) returns (MsgCreatePriceResponse);

rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}
message MsgCreatePrice {
string creator = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
Expand All @@ -23,3 +28,17 @@ message MsgCreatePrice {
}

message MsgCreatePriceResponse {}

message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "cosmos-sdk/x/oracle/MsgUpdateParams";

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// params defines the x/staking parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
};

message MsgUpdateParamsResponse {};
1 change: 1 addition & 0 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type (
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
paramstore paramtypes.Subspace
authority string
common.KeeperStaking
}
)
Expand Down
24 changes: 24 additions & 0 deletions x/oracle/keeper/msg_server_update_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keeper

import (
"context"

"github.com/ExocoreNetwork/exocore/x/oracle/types"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

func (ms msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if ms.authority != msg.Authority {
return nil, govtypes.ErrInvalidSigner.Wrapf("invalid authority; expected %s, got %s", ms.authority, msg.Authority)
}

// store params
if err := ms.SetParams(ctx, msg.Params); err != nil {
return nil, err
}

return &types.MsgUpdateParamsResponse{}, nil
}
8 changes: 6 additions & 2 deletions x/oracle/types/message_create_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ const TypeMsgCreatePrice = "create_price"

var _ sdk.Msg = &MsgCreatePrice{}

func NewMsgCreatePrice(creator string) *MsgCreatePrice {
func NewMsgCreatePrice(creator string, feederID int32, prices []*PriceWithSource, basedBlock uint64, nonce int32) *MsgCreatePrice {
return &MsgCreatePrice{
Creator: creator,
Creator: creator,
FeederId: feederID,
Prices: prices,
BasedBlock: basedBlock,
Nonce: nonce,
}
}

Expand Down
39 changes: 39 additions & 0 deletions x/oracle/types/message_update_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const TypeMsgUpdateParams = "update_params"

var _ sdk.Msg = &MsgUpdateParams{}

func (msg *MsgUpdateParams) Route() string {
return RouterKey
}

func (msg *MsgUpdateParams) Type() string {
return TypeMsgUpdateParams
}

// GetSignBytes returns the raw bytes for a MsgUpdateParams message that
// the expected signer needs to sign.
func (msg *MsgUpdateParams) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

// ValidateBasic executes sanity validation on the provided data
func (msg *MsgUpdateParams) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
return sdkerrors.Wrap(err, "invalid authority address")
}
return msg.Params.Validate()
}

// GetSigners returns the expected signers for a MsgUpdateParams message
func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Authority)

Check warning

Code scanning / gosec

Returned error is not propagated up the stack. Warning

Returned error is not propagated up the stack.
return []sdk.AccAddress{addr}
}
Loading

0 comments on commit ede2652

Please sign in to comment.