Skip to content

Commit

Permalink
fix(oracle): fix proto-lint, fix cli-tx
Browse files Browse the repository at this point in the history
  • Loading branch information
leonz789 committed Apr 14, 2024
1 parent ede2652 commit 5e69226
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions proto/exocore/oracle/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ message QueryParamsResponse {
}

message QueryGetPricesRequest {
int32 tokenId = 1;
int32 token_id = 1;
}

message QueryGetPricesResponse {
Expand All @@ -106,35 +106,35 @@ 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 {
uint64 block = 1;
}

message QueryGetRecentMsgResponse {
RecentMsg recentMsg = 1 [(gogoproto.nullable) = false];
RecentMsg recent_msg = 1 [(gogoproto.nullable) = false];
}

message QueryAllRecentMsgRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllRecentMsgResponse {
repeated RecentMsg recentMsg = 1 [(gogoproto.nullable) = false];
repeated RecentMsg recent_msg = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

Expand All @@ -143,15 +143,15 @@ message QueryGetRecentParamsRequest {
}

message QueryGetRecentParamsResponse {
RecentParams recentParams = 1 [(gogoproto.nullable) = false];
RecentParams recent_params = 1 [(gogoproto.nullable) = false];
}

message QueryAllRecentParamsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllRecentParamsResponse {
repeated RecentParams recentParams = 1 [(gogoproto.nullable) = false];
repeated RecentParams recent_params = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

3 changes: 0 additions & 3 deletions proto/exocore/oracle/token_feeder.proto
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions proto/exocore/oracle/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
59 changes: 56 additions & 3 deletions x/oracle/client/cli/tx_create_price.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"errors"
"strconv"

"github.com/ExocoreNetwork/exocore/x/oracle/types"
Expand All @@ -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),

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
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),

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
Timestamp: timestamp,
DetId: detID,
})
}
if argLength == 1 {
prices[0].Desc = args[i+1]
}

msg := types.NewMsgCreatePrice(
clientCtx.GetFromAddress().String(),
int32(feederID),

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
prices,
uint64(basedBlock),

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
int32(basedBlock),

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
to a lower bit size type int32 without an upper bound check.
)
if err := msg.ValidateBasic(); err != nil {
return err
Expand Down

0 comments on commit 5e69226

Please sign in to comment.