From 5e69226ddd6742bf913d57b2ba9bb9f26a29b2c3 Mon Sep 17 00:00:00 2001 From: leonz789 Date: Sun, 14 Apr 2024 21:02:59 +0800 Subject: [PATCH] fix(oracle): fix proto-lint, fix cli-tx --- go.mod | 2 +- proto/exocore/oracle/query.proto | 16 +++---- proto/exocore/oracle/token_feeder.proto | 3 -- proto/exocore/oracle/tx.proto | 4 +- x/oracle/client/cli/tx_create_price.go | 59 +++++++++++++++++++++++-- 5 files changed, 67 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index a21d8696d..402af94a9 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,6 @@ require ( golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e google.golang.org/grpc v1.57.1 - google.golang.org/protobuf v1.33.0 gopkg.in/yaml.v2 v2.4.0 sigs.k8s.io/yaml v1.3.0 ) @@ -222,6 +221,7 @@ require ( google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect + google.golang.org/protobuf v1.33.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/proto/exocore/oracle/query.proto b/proto/exocore/oracle/query.proto index 9482a55e3..024c0cfdc 100644 --- a/proto/exocore/oracle/query.proto +++ b/proto/exocore/oracle/query.proto @@ -87,7 +87,7 @@ message QueryParamsResponse { } message QueryGetPricesRequest { - int32 tokenId = 1; + int32 token_id = 1; } message QueryGetPricesResponse { @@ -106,19 +106,19 @@ message QueryAllPricesResponse { message QueryGetValidatorUpdateBlockRequest {} message QueryGetValidatorUpdateBlockResponse { - ValidatorUpdateBlock ValidatorUpdateBlock = 1 [(gogoproto.nullable) = false]; + ValidatorUpdateBlock validator_update_block = 1 [(gogoproto.nullable) = false]; } message QueryGetIndexRecentParamsRequest {} message QueryGetIndexRecentParamsResponse { - IndexRecentParams IndexRecentParams = 1 [(gogoproto.nullable) = false]; + IndexRecentParams index_recent_params = 1 [(gogoproto.nullable) = false]; } message QueryGetIndexRecentMsgRequest {} message QueryGetIndexRecentMsgResponse { - IndexRecentMsg IndexRecentMsg = 1 [(gogoproto.nullable) = false]; + IndexRecentMsg index_recent_msg = 1 [(gogoproto.nullable) = false]; } message QueryGetRecentMsgRequest { @@ -126,7 +126,7 @@ message QueryGetRecentMsgRequest { } message QueryGetRecentMsgResponse { - RecentMsg recentMsg = 1 [(gogoproto.nullable) = false]; + RecentMsg recent_msg = 1 [(gogoproto.nullable) = false]; } message QueryAllRecentMsgRequest { @@ -134,7 +134,7 @@ message QueryAllRecentMsgRequest { } message QueryAllRecentMsgResponse { - repeated RecentMsg recentMsg = 1 [(gogoproto.nullable) = false]; + repeated RecentMsg recent_msg = 1 [(gogoproto.nullable) = false]; cosmos.base.query.v1beta1.PageResponse pagination = 2; } @@ -143,7 +143,7 @@ message QueryGetRecentParamsRequest { } message QueryGetRecentParamsResponse { - RecentParams recentParams = 1 [(gogoproto.nullable) = false]; + RecentParams recent_params = 1 [(gogoproto.nullable) = false]; } message QueryAllRecentParamsRequest { @@ -151,7 +151,7 @@ message QueryAllRecentParamsRequest { } message QueryAllRecentParamsResponse { - repeated RecentParams recentParams = 1 [(gogoproto.nullable) = false]; + repeated RecentParams recent_params = 1 [(gogoproto.nullable) = false]; cosmos.base.query.v1beta1.PageResponse pagination = 2; } diff --git a/proto/exocore/oracle/token_feeder.proto b/proto/exocore/oracle/token_feeder.proto index 818e3867f..b9245d342 100644 --- a/proto/exocore/oracle/token_feeder.proto +++ b/proto/exocore/oracle/token_feeder.proto @@ -1,9 +1,6 @@ syntax = "proto3"; package exocore.oracle; -import "gogoproto/gogo.proto"; -import "exocore/oracle/info.proto"; - option go_package = "github.com/ExocoreNetwork/exocore/x/oracle/types"; //n out of m required source diff --git a/proto/exocore/oracle/tx.proto b/proto/exocore/oracle/tx.proto index 4e828ba1d..690722c06 100644 --- a/proto/exocore/oracle/tx.proto +++ b/proto/exocore/oracle/tx.proto @@ -12,9 +12,9 @@ option go_package = "github.com/ExocoreNetwork/exocore/x/oracle/types"; // Msg defines the Msg service. service Msg { -//create price for a new oracle round +// CreatePrice creates price for a new oracle round rpc CreatePrice (MsgCreatePrice) returns (MsgCreatePriceResponse); - +// UpdateParams update params value rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); } message MsgCreatePrice { diff --git a/x/oracle/client/cli/tx_create_price.go b/x/oracle/client/cli/tx_create_price.go index d85013787..483422b76 100644 --- a/x/oracle/client/cli/tx_create_price.go +++ b/x/oracle/client/cli/tx_create_price.go @@ -1,6 +1,7 @@ package cli import ( + "errors" "strconv" "github.com/ExocoreNetwork/exocore/x/oracle/types" @@ -14,18 +15,70 @@ var _ = strconv.Itoa(0) func CmdCreatePrice() *cobra.Command { cmd := &cobra.Command{ - Use: "create-price", + //TODO: support v1 single sourceID for temporary + Use: "create-price feederid basedblock nonce sourceid decimal price timestamp detid optinoal(price timestamp detid) optional(desc)", Short: "Broadcast message create-price", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, _ []string) (err error) { + //Args: cobra.ExactArgs(0), + Args: cobra.MinimumNArgs(8), + RunE: func(cmd *cobra.Command, args []string) (err error) { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } + feederID, err := strconv.ParseInt(args[0], 10, 32) + if err != nil || feederID < 1 { + return errors.New("feederID invalid") + } + basedBlock, err := strconv.ParseInt(args[1], 10, 64) + if err != nil || basedBlock < 1 { + return errors.New("basedBlock invalid") + } + nonce, err := strconv.ParseInt(args[2], 10, 32) + if err != nil || nonce < 1 || nonce > 3 { + return errors.New("nonce invalid") + } + sourceID, err := strconv.ParseInt(args[3], 10, 32) + if err != nil || sourceID < 1 { + return errors.New("sourceID invalid") + } + decimal, err := strconv.ParseInt(args[4], 10, 32) + if err != nil || decimal < 0 { + return errors.New("decimal invalid") + } + //prices := make([]*types.PriceWithSource, 0, 1) + prices := []*types.PriceWithSource{ + { + SourceId: int32(sourceID), + Prices: make([]*types.PriceWithTimeAndDetId, 0, 1), + Desc: "", + }, + } + argLength := len(args) - 5 + i := 5 + for argLength > 2 { + price := args[i] + timestamp := args[i+1] + detID := args[i+2] + argLength -= 3 + i += 3 + prices[0].Prices = append(prices[0].Prices, &types.PriceWithTimeAndDetId{ + Price: price, + Decimal: int32(decimal), + Timestamp: timestamp, + DetId: detID, + }) + } + if argLength == 1 { + prices[0].Desc = args[i+1] + } msg := types.NewMsgCreatePrice( clientCtx.GetFromAddress().String(), + int32(feederID), + prices, + uint64(basedBlock), + int32(basedBlock), ) if err := msg.ValidateBasic(); err != nil { return err