diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index 25fdf7b79a..434fb64f1f 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -131,15 +131,10 @@ func TestAppAnteHandler(t *testing.T) { // TODO Test pricefeed oracles and bep3 deputy txs can always get into the mempool. func newPricefeedGenStateMulti(cdc codec.JSONCodec, oracles []sdk.AccAddress) app.GenesisState { - var oracleStrs []string - for _, o := range oracles { - oracleStrs = append(oracleStrs, o.String()) - } - pfGenesis := pricefeedtypes.GenesisState{ Params: pricefeedtypes.Params{ Markets: []pricefeedtypes.Market{ - {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: oracleStrs, Active: true}, + {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: oracles, Active: true}, }, }, } diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index c07de52b6b..ea0920f78e 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -51,16 +51,19 @@ - [Query](#kava.kavadist.v1beta1.Query) -- [kava/pricefeed/v1beta1/pricefeed.proto](#kava/pricefeed/v1beta1/pricefeed.proto) +- [kava/pricefeed/v1beta1/store.proto](#kava/pricefeed/v1beta1/store.proto) - [CurrentPrice](#kava.pricefeed.v1beta1.CurrentPrice) - [Market](#kava.pricefeed.v1beta1.Market) + - [Params](#kava.pricefeed.v1beta1.Params) - [PostedPrice](#kava.pricefeed.v1beta1.PostedPrice) - [kava/pricefeed/v1beta1/genesis.proto](#kava/pricefeed/v1beta1/genesis.proto) - [GenesisState](#kava.pricefeed.v1beta1.GenesisState) - - [Params](#kava.pricefeed.v1beta1.Params) - [kava/pricefeed/v1beta1/query.proto](#kava/pricefeed/v1beta1/query.proto) + - [CurrentPriceResponse](#kava.pricefeed.v1beta1.CurrentPriceResponse) + - [MarketResponse](#kava.pricefeed.v1beta1.MarketResponse) + - [PostedPriceResponse](#kava.pricefeed.v1beta1.PostedPriceResponse) - [QueryMarketsRequest](#kava.pricefeed.v1beta1.QueryMarketsRequest) - [QueryMarketsResponse](#kava.pricefeed.v1beta1.QueryMarketsResponse) - [QueryOraclesRequest](#kava.pricefeed.v1beta1.QueryOraclesRequest) @@ -662,10 +665,10 @@ Query defines the gRPC querier service. - +

Top

-## kava/pricefeed/v1beta1/pricefeed.proto +## kava/pricefeed/v1beta1/store.proto @@ -697,7 +700,7 @@ Market defines an asset in the pricefeed. | `market_id` | [string](#string) | | | | `base_asset` | [string](#string) | | | | `quote_asset` | [string](#string) | | | -| `oracles` | [string](#string) | repeated | | +| `oracles` | [bytes](#bytes) | repeated | | | `active` | [bool](#bool) | | | @@ -705,6 +708,21 @@ Market defines an asset in the pricefeed. + + +### Params +Params defines the parameters for the pricefeed module. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `markets` | [Market](#kava.pricefeed.v1beta1.Market) | repeated | | + + + + + + ### PostedPrice @@ -714,7 +732,7 @@ PostedPrice defines a price for market posted by a specific oracle. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `market_id` | [string](#string) | | | -| `oracle_address` | [string](#string) | | | +| `oracle_address` | [bytes](#bytes) | | | | `price` | [string](#string) | | | | `expiry` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | @@ -754,35 +772,74 @@ GenesisState defines the pricefeed module's genesis state. + + + + + + + + + + + +

Top

+ +## kava/pricefeed/v1beta1/query.proto - -### Params -Params defines the parameters for the pricefeed module. + + + +### CurrentPriceResponse +CurrentPriceResponse defines a current price for a particular market in the pricefeed +module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `markets` | [Market](#kava.pricefeed.v1beta1.Market) | repeated | | +| `market_id` | [string](#string) | | | +| `price` | [string](#string) | | | - - + - +### MarketResponse +MarketResponse defines an asset in the pricefeed. - +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `market_id` | [string](#string) | | | +| `base_asset` | [string](#string) | | | +| `quote_asset` | [string](#string) | | | +| `oracles` | [string](#string) | repeated | | +| `active` | [bool](#bool) | | | + + + + + + + + +### PostedPriceResponse +PostedPriceResponse defines a price for market posted by a specific oracle. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `market_id` | [string](#string) | | | +| `oracle_address` | [string](#string) | | | +| `price` | [string](#string) | | | +| `expiry` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | - -

Top

-## kava/pricefeed/v1beta1/query.proto @@ -804,7 +861,7 @@ QueryMarketsResponse is the response type for the Query/Markets RPC method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `markets` | [Market](#kava.pricefeed.v1beta1.Market) | repeated | List of markets | +| `markets` | [MarketResponse](#kava.pricefeed.v1beta1.MarketResponse) | repeated | List of markets | @@ -891,7 +948,7 @@ QueryPriceResponse is the response type for the Query/Prices RPC method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `price` | [CurrentPrice](#kava.pricefeed.v1beta1.CurrentPrice) | | | +| `price` | [CurrentPriceResponse](#kava.pricefeed.v1beta1.CurrentPriceResponse) | | | @@ -916,7 +973,7 @@ QueryPricesResponse is the response type for the Query/Prices RPC method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `prices` | [CurrentPrice](#kava.pricefeed.v1beta1.CurrentPrice) | repeated | | +| `prices` | [CurrentPriceResponse](#kava.pricefeed.v1beta1.CurrentPriceResponse) | repeated | | @@ -947,7 +1004,7 @@ method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `raw_prices` | [PostedPrice](#kava.pricefeed.v1beta1.PostedPrice) | repeated | | +| `raw_prices` | [PostedPriceResponse](#kava.pricefeed.v1beta1.PostedPriceResponse) | repeated | | diff --git a/proto/kava/pricefeed/v1beta1/genesis.proto b/proto/kava/pricefeed/v1beta1/genesis.proto index 0d14a544df..3789f0086d 100644 --- a/proto/kava/pricefeed/v1beta1/genesis.proto +++ b/proto/kava/pricefeed/v1beta1/genesis.proto @@ -1,11 +1,11 @@ syntax = "proto3"; package kava.pricefeed.v1beta1; -import "kava/pricefeed/v1beta1/pricefeed.proto"; +import "kava/pricefeed/v1beta1/store.proto"; import "gogoproto/gogo.proto"; -option go_package = "github.com/kava-labs/kava/x/pricefeed/types"; -option (gogoproto.equal_all) = true; +option go_package = "github.com/kava-labs/kava/x/pricefeed/types"; +option (gogoproto.equal_all) = true; option (gogoproto.verbose_equal_all) = true; // GenesisState defines the pricefeed module's genesis state. @@ -13,11 +13,5 @@ message GenesisState { // params defines all the paramaters of the module. Params params = 1 [(gogoproto.nullable) = false]; - repeated PostedPrice posted_prices = 2 [(gogoproto.nullable) = false]; -} - -// Params defines the parameters for the pricefeed module. -message Params { - option (gogoproto.goproto_stringer) = false; // false here because we define Stringer method in params.go - repeated Market markets = 1 [(gogoproto.nullable) = false]; + repeated PostedPrice posted_prices = 2 [(gogoproto.castrepeated) = "PostedPrices", (gogoproto.nullable) = false]; } diff --git a/proto/kava/pricefeed/v1beta1/query.proto b/proto/kava/pricefeed/v1beta1/query.proto index 5542840852..a398f6a944 100644 --- a/proto/kava/pricefeed/v1beta1/query.proto +++ b/proto/kava/pricefeed/v1beta1/query.proto @@ -1,13 +1,13 @@ syntax = "proto3"; package kava.pricefeed.v1beta1; -import "kava/pricefeed/v1beta1/genesis.proto"; -import "kava/pricefeed/v1beta1/pricefeed.proto"; +import "kava/pricefeed/v1beta1/store.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; +import "google/protobuf/timestamp.proto"; -option go_package = "github.com/kava-labs/kava/x/pricefeed/types"; -option (gogoproto.equal_all) = true; +option go_package = "github.com/kava-labs/kava/x/pricefeed/types"; +option (gogoproto.equal_all) = true; option (gogoproto.verbose_equal_all) = true; // Query defines the gRPC querier service for pricefeed module @@ -66,7 +66,7 @@ message QueryPriceRequest { message QueryPriceResponse { option (gogoproto.goproto_getters) = false; - CurrentPrice price = 1 [(gogoproto.nullable) = false]; + CurrentPriceResponse price = 1 [(gogoproto.nullable) = false]; } // QueryPricesRequest is the request type for the Query/Prices RPC method. @@ -76,7 +76,8 @@ message QueryPricesRequest {} message QueryPricesResponse { option (gogoproto.goproto_getters) = false; - repeated CurrentPrice prices = 1 [(gogoproto.nullable) = false]; + repeated CurrentPriceResponse prices = 1 + [(gogoproto.castrepeated) = "CurrentPriceResponses", (gogoproto.nullable) = false]; } // QueryRawPricesRequest is the request type for the Query/RawPrices RPC method. @@ -91,7 +92,8 @@ message QueryRawPricesRequest { message QueryRawPricesResponse { option (gogoproto.goproto_getters) = false; - repeated PostedPrice raw_prices = 1 [(gogoproto.nullable) = false]; + repeated PostedPriceResponse raw_prices = 1 + [(gogoproto.castrepeated) = "PostedPriceResponses", (gogoproto.nullable) = false]; } // QueryOraclesRequest is the request type for the Query/Oracles RPC method. @@ -117,5 +119,29 @@ message QueryMarketsResponse { option (gogoproto.goproto_getters) = false; // List of markets - repeated Market markets = 1 [(gogoproto.nullable) = false]; + repeated MarketResponse markets = 1 [(gogoproto.castrepeated) = "MarketResponses", (gogoproto.nullable) = false]; +} + +// PostedPriceResponse defines a price for market posted by a specific oracle. +message PostedPriceResponse { + string market_id = 1 [(gogoproto.customname) = "MarketID"]; + string oracle_address = 2; + string price = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + google.protobuf.Timestamp expiry = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; +} + +// CurrentPriceResponse defines a current price for a particular market in the pricefeed +// module. +message CurrentPriceResponse { + string market_id = 1 [(gogoproto.customname) = "MarketID"]; + string price = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; +} + +// MarketResponse defines an asset in the pricefeed. +message MarketResponse { + string market_id = 1 [(gogoproto.customname) = "MarketID"]; + string base_asset = 2; + string quote_asset = 3; + repeated string oracles = 4; + bool active = 5; } diff --git a/proto/kava/pricefeed/v1beta1/pricefeed.proto b/proto/kava/pricefeed/v1beta1/store.proto similarity index 52% rename from proto/kava/pricefeed/v1beta1/pricefeed.proto rename to proto/kava/pricefeed/v1beta1/store.proto index f9605ae3a8..3f71782b6b 100644 --- a/proto/kava/pricefeed/v1beta1/pricefeed.proto +++ b/proto/kava/pricefeed/v1beta1/store.proto @@ -1,30 +1,38 @@ syntax = "proto3"; package kava.pricefeed.v1beta1; +import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; -option go_package = "github.com/kava-labs/kava/x/pricefeed/types"; -option (gogoproto.equal_all) = true; +option go_package = "github.com/kava-labs/kava/x/pricefeed/types"; +option (gogoproto.equal_all) = true; option (gogoproto.verbose_equal_all) = true; +// Params defines the parameters for the pricefeed module. +message Params { + repeated Market markets = 1 [(gogoproto.castrepeated) = "Markets", (gogoproto.nullable) = false]; +} + // Market defines an asset in the pricefeed. message Market { - option (gogoproto.goproto_stringer) = false; - - string market_id = 1 [(gogoproto.customname) = "MarketID"]; - string base_asset = 2; - string quote_asset = 3; - repeated string oracles = 4; - bool active = 5; + string market_id = 1 [(gogoproto.customname) = "MarketID"]; + string base_asset = 2; + string quote_asset = 3; + repeated bytes oracles = 4 [ + (cosmos_proto.scalar) = "cosmos.AddressBytes", + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress" + ]; + bool active = 5; } // PostedPrice defines a price for market posted by a specific oracle. message PostedPrice { - option (gogoproto.goproto_stringer) = false; - string market_id = 1 [(gogoproto.customname) = "MarketID"]; - string oracle_address = 2; + bytes oracle_address = 2 [ + (cosmos_proto.scalar) = "cosmos.AddressBytes", + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress" + ]; string price = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; google.protobuf.Timestamp expiry = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; } @@ -32,8 +40,6 @@ message PostedPrice { // CurrentPrice defines a current price for a particular market in the pricefeed // module. message CurrentPrice { - option (gogoproto.goproto_stringer) = false; - string market_id = 1 [(gogoproto.customname) = "MarketID"]; string price = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; } diff --git a/proto/kava/pricefeed/v1beta1/tx.proto b/proto/kava/pricefeed/v1beta1/tx.proto index 69900c6e87..b0d95b5ebb 100644 --- a/proto/kava/pricefeed/v1beta1/tx.proto +++ b/proto/kava/pricefeed/v1beta1/tx.proto @@ -4,8 +4,8 @@ package kava.pricefeed.v1beta1; import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; -option go_package = "github.com/kava-labs/kava/x/pricefeed/types"; -option (gogoproto.equal_all) = true; +option go_package = "github.com/kava-labs/kava/x/pricefeed/types"; +option (gogoproto.equal_all) = true; option (gogoproto.verbose_equal_all) = true; // Msg defines the pricefeed Msg service. diff --git a/x/pricefeed/genesis.go b/x/pricefeed/genesis.go index f2cde37242..ebafb5ca14 100644 --- a/x/pricefeed/genesis.go +++ b/x/pricefeed/genesis.go @@ -2,6 +2,7 @@ package pricefeed import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/pricefeed/keeper" "github.com/kava-labs/kava/x/pricefeed/types" ) diff --git a/x/pricefeed/genesis_test.go b/x/pricefeed/genesis_test.go index ee6d01748f..865142590b 100644 --- a/x/pricefeed/genesis_test.go +++ b/x/pricefeed/genesis_test.go @@ -37,17 +37,11 @@ func (suite *GenesisTestSuite) TestValidGenState() { }) _, addrs := app.GeneratePrivKeyAddressPairs(10) - var strAddrs []string - - for _, addr := range addrs { - strAddrs = append(strAddrs, addr.String()) - } - // Must create a new TestApp or InitChain will panic with index already set suite.tApp = app.NewTestApp() suite.NotPanics(func() { suite.tApp.InitializeFromGenesisStates( - NewPricefeedGenStateWithOracles(strAddrs), + NewPricefeedGenStateWithOracles(addrs), ) }) } diff --git a/x/pricefeed/grpc_query.go b/x/pricefeed/grpc_query.go index b438c0a623..d9df828781 100644 --- a/x/pricefeed/grpc_query.go +++ b/x/pricefeed/grpc_query.go @@ -36,6 +36,7 @@ func (k QueryServer) Params(c context.Context, req *types.QueryParamsRequest) (* return &types.QueryParamsResponse{Params: params}, nil } +// Price implements the gRPC service handler for querying x/pricefeed price. func (k QueryServer) Price(c context.Context, req *types.QueryPriceRequest) (*types.QueryPriceResponse, error) { ctx := sdk.UnwrapSDKContext(c) @@ -49,16 +50,16 @@ func (k QueryServer) Price(c context.Context, req *types.QueryPriceRequest) (*ty } return &types.QueryPriceResponse{ - Price: types.CurrentPrice{ - MarketID: currentPrice.MarketID, - Price: currentPrice.Price, - }}, nil - + Price: types.CurrentPriceResponse(currentPrice)}, nil } + func (k QueryServer) Prices(c context.Context, req *types.QueryPricesRequest) (*types.QueryPricesResponse, error) { ctx := sdk.UnwrapSDKContext(c) - currentPrices := k.keeper.GetCurrentPrices(ctx) + var currentPrices types.CurrentPriceResponses + for _, cp := range k.keeper.GetCurrentPrices(ctx) { + currentPrices = append(currentPrices, types.CurrentPriceResponse(cp)) + } return &types.QueryPricesResponse{ Prices: currentPrices, @@ -72,10 +73,19 @@ func (k QueryServer) RawPrices(c context.Context, req *types.QueryRawPricesReque if !found { return nil, status.Error(codes.NotFound, "invalid market ID") } - rawPrices := k.keeper.GetRawPrices(ctx, req.MarketId) + + var prices types.PostedPriceResponses + for _, rp := range k.keeper.GetRawPrices(ctx, req.MarketId) { + prices = append(prices, types.PostedPriceResponse{ + MarketID: rp.MarketID, + OracleAddress: rp.OracleAddress.String(), + Price: rp.Price, + Expiry: rp.Expiry, + }) + } return &types.QueryRawPricesResponse{ - RawPrices: rawPrices, + RawPrices: prices, }, nil } @@ -87,15 +97,23 @@ func (k QueryServer) Oracles(c context.Context, req *types.QueryOraclesRequest) return nil, status.Error(codes.NotFound, "invalid market ID") } + var strOracles []string + for _, oracle := range oracles { + strOracles = append(strOracles, oracle.String()) + } + return &types.QueryOraclesResponse{ - Oracles: oracles, + Oracles: strOracles, }, nil } func (k QueryServer) Markets(c context.Context, req *types.QueryMarketsRequest) (*types.QueryMarketsResponse, error) { ctx := sdk.UnwrapSDKContext(c) - markets := k.keeper.GetMarkets(ctx) + var markets types.MarketResponses + for _, market := range k.keeper.GetMarkets(ctx) { + markets = append(markets, market.ToMarketResponse()) + } return &types.QueryMarketsResponse{ Markets: markets, diff --git a/x/pricefeed/grpc_query_test.go b/x/pricefeed/grpc_query_test.go index 215c7e87c2..f21451bba2 100644 --- a/x/pricefeed/grpc_query_test.go +++ b/x/pricefeed/grpc_query_test.go @@ -21,6 +21,7 @@ type grpcQueryTestSuite struct { keeper keeper.Keeper queryServer types.QueryServer addrs []sdk.AccAddress + strAddrs []string now time.Time } @@ -34,12 +35,18 @@ func (suite *grpcQueryTestSuite) SetupTest() { _, addrs := app.GeneratePrivKeyAddressPairs(5) suite.addrs = addrs + var strAddrs []string + for _, a := range addrs { + strAddrs = append(strAddrs, a.String()) + } + suite.strAddrs = strAddrs + suite.now = time.Now().UTC() } func (suite *grpcQueryTestSuite) setTestParams() { params := types.NewParams([]types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }) suite.keeper.SetParams(suite.ctx, params) } @@ -52,7 +59,7 @@ func (suite *grpcQueryTestSuite) TestGrpcParams() { }{ {"default params", types.DefaultParams(), true}, {"test params", types.NewParams([]types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }), true}, } @@ -76,7 +83,7 @@ func (suite *grpcQueryTestSuite) TestGrpcPrice() { suite.setTestParams() suite.setTstPrice() - expectedPrice := types.NewCurrentPrice("tstusd", sdk.MustNewDecFromStr("0.34")) + expectedPrice := types.NewCurrentPriceResponse("tstusd", sdk.MustNewDecFromStr("0.34")) res, err := suite.queryServer.Price(sdk.WrapSDKContext(suite.ctx), &types.QueryPriceRequest{MarketId: "tstusd"}) suite.NoError(err) @@ -103,7 +110,7 @@ func (suite *grpcQueryTestSuite) TestGrpcPrices() { suite.setTestParams() suite.setTstPrice() - expectedPrice := types.NewCurrentPrice("tstusd", sdk.MustNewDecFromStr("0.34")) + expectedPrice := types.NewCurrentPriceResponse("tstusd", sdk.MustNewDecFromStr("0.34")) prices, err := suite.queryServer.Prices(sdk.WrapSDKContext(suite.ctx), &types.QueryPricesRequest{}) suite.NoError(err) @@ -122,22 +129,22 @@ func (suite *grpcQueryTestSuite) TestGrpcRawPrices() { suite.ElementsMatch( res.RawPrices, - []types.PostedPrice{ - types.NewPostedPrice( + []types.PostedPriceResponse{ + types.NewPostedPriceResponse( "tstusd", - suite.addrs[0].String(), + suite.addrs[0], sdk.MustNewDecFromStr("0.33"), suite.now.Add(time.Hour*1), ), - types.NewPostedPrice( + types.NewPostedPriceResponse( "tstusd", - suite.addrs[1].String(), + suite.addrs[1], sdk.MustNewDecFromStr("0.35"), suite.now.Add(time.Hour*1), ), - types.NewPostedPrice( + types.NewPostedPriceResponse( "tstusd", - suite.addrs[2].String(), + suite.addrs[2], sdk.MustNewDecFromStr("0.34"), suite.now.Add(time.Hour*1), ), @@ -155,7 +162,7 @@ func (suite *grpcQueryTestSuite) TestGrpcRawPrices_InvalidMarket() { func (suite *grpcQueryTestSuite) TestGrpcOracles_Empty() { params := types.NewParams([]types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }) suite.keeper.SetParams(suite.ctx, params) @@ -163,38 +170,28 @@ func (suite *grpcQueryTestSuite) TestGrpcOracles_Empty() { suite.NoError(err) suite.Empty(res.Oracles) - var oracles []string - for _, a := range suite.addrs { - oracles = append(oracles, a.String()) - } - params = types.NewParams([]types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: oracles, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: suite.addrs, Active: true}, }) suite.keeper.SetParams(suite.ctx, params) res, err = suite.queryServer.Oracles(sdk.WrapSDKContext(suite.ctx), &types.QueryOraclesRequest{MarketId: "tstusd"}) suite.NoError(err) - suite.ElementsMatch(res.Oracles, oracles) + suite.ElementsMatch(suite.strAddrs, res.Oracles) _, err = suite.queryServer.Oracles(sdk.WrapSDKContext(suite.ctx), &types.QueryOraclesRequest{MarketId: "invalid"}) suite.Equal("rpc error: code = NotFound desc = invalid market ID", err.Error()) } func (suite *grpcQueryTestSuite) TestGrpcOracles() { - var oracles []string - for _, a := range suite.addrs { - oracles = append(oracles, a.String()) - } - params := types.NewParams([]types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: oracles, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: suite.addrs, Active: true}, }) suite.keeper.SetParams(suite.ctx, params) res, err := suite.queryServer.Oracles(sdk.WrapSDKContext(suite.ctx), &types.QueryOraclesRequest{MarketId: "tstusd"}) suite.NoError(err) - suite.ElementsMatch(res.Oracles, oracles) + suite.ElementsMatch(suite.strAddrs, res.Oracles) } func (suite *grpcQueryTestSuite) TestGrpcOracles_InvalidMarket() { @@ -206,32 +203,34 @@ func (suite *grpcQueryTestSuite) TestGrpcOracles_InvalidMarket() { func (suite *grpcQueryTestSuite) TestGrpcMarkets() { params := types.NewParams([]types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "btcusd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }) suite.keeper.SetParams(suite.ctx, params) res, err := suite.queryServer.Markets(sdk.WrapSDKContext(suite.ctx), &types.QueryMarketsRequest{}) suite.NoError(err) - suite.Len(res.Markets, 1) + suite.Len(res.Markets, 2) suite.Equal(len(res.Markets), len(params.Markets)) - suite.NoError(res.Markets[0].VerboseEqual(params.Markets[0])) + suite.NoError(res.Markets[0].VerboseEqual(params.Markets[0].ToMarketResponse())) + suite.NoError(res.Markets[1].VerboseEqual(params.Markets[1].ToMarketResponse())) } func (suite *grpcQueryTestSuite) setTstPrice() { _, err := suite.keeper.SetPrice( - suite.ctx, suite.addrs[0].String(), "tstusd", + suite.ctx, suite.addrs[0], "tstusd", sdk.MustNewDecFromStr("0.33"), suite.now.Add(time.Hour*1)) suite.NoError(err) _, err = suite.keeper.SetPrice( - suite.ctx, suite.addrs[1].String(), "tstusd", + suite.ctx, suite.addrs[1], "tstusd", sdk.MustNewDecFromStr("0.35"), suite.now.Add(time.Hour*1)) suite.NoError(err) _, err = suite.keeper.SetPrice( - suite.ctx, suite.addrs[2].String(), "tstusd", + suite.ctx, suite.addrs[2], "tstusd", sdk.MustNewDecFromStr("0.34"), suite.now.Add(time.Hour*1)) suite.NoError(err) diff --git a/x/pricefeed/integration_test.go b/x/pricefeed/integration_test.go index 81ca92b00b..b8d230f7e5 100644 --- a/x/pricefeed/integration_test.go +++ b/x/pricefeed/integration_test.go @@ -13,20 +13,20 @@ func NewPricefeedGen() types.GenesisState { return types.GenesisState{ Params: types.Params{ Markets: []types.Market{ - {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []string{}, Active: true}, - {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, }, PostedPrices: []types.PostedPrice{ { MarketID: "btc:usd", - OracleAddress: "", + OracleAddress: sdk.AccAddress("oracle1"), Price: sdk.MustNewDecFromStr("8000.00"), Expiry: time.Now().Add(1 * time.Hour), }, { MarketID: "xrp:usd", - OracleAddress: "", + OracleAddress: sdk.AccAddress("oracle2"), Price: sdk.MustNewDecFromStr("0.25"), Expiry: time.Now().Add(1 * time.Hour), }, @@ -39,7 +39,7 @@ func NewPricefeedGenStateMulti() app.GenesisState { return app.GenesisState{types.ModuleName: types.ModuleCdc.LegacyAmino.MustMarshalJSON(pfGenesis)} } -func NewPricefeedGenStateWithOracles(addrs []string) app.GenesisState { +func NewPricefeedGenStateWithOracles(addrs []sdk.AccAddress) app.GenesisState { pfGenesis := types.GenesisState{ Params: types.Params{ Markets: []types.Market{ diff --git a/x/pricefeed/keeper/integration_test.go b/x/pricefeed/keeper/integration_test.go index a3611c26c5..e2c1cff64b 100644 --- a/x/pricefeed/keeper/integration_test.go +++ b/x/pricefeed/keeper/integration_test.go @@ -13,20 +13,20 @@ func NewPricefeedGenStateMulti() app.GenesisState { pfGenesis := types.GenesisState{ Params: types.Params{ Markets: []types.Market{ - {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []string{}, Active: true}, - {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, }, PostedPrices: []types.PostedPrice{ { MarketID: "btc:usd", - OracleAddress: "", + OracleAddress: sdk.AccAddress{}, Price: sdk.MustNewDecFromStr("8000.00"), Expiry: time.Now().Add(1 * time.Hour), }, { MarketID: "xrp:usd", - OracleAddress: "", + OracleAddress: sdk.AccAddress{}, Price: sdk.MustNewDecFromStr("0.25"), Expiry: time.Now().Add(1 * time.Hour), }, diff --git a/x/pricefeed/keeper/keeper.go b/x/pricefeed/keeper/keeper.go index f44c9d78da..c7e35aea2c 100644 --- a/x/pricefeed/keeper/keeper.go +++ b/x/pricefeed/keeper/keeper.go @@ -48,7 +48,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // SetPrice updates the posted price for a specific oracle func (k Keeper) SetPrice( ctx sdk.Context, - oracle string, + oracle sdk.AccAddress, marketID string, price sdk.Dec, expiry time.Time) (types.PostedPrice, error) { @@ -66,7 +66,7 @@ func (k Keeper) SetPrice( sdk.NewEvent( types.EventTypeOracleUpdatedPrice, sdk.NewAttribute(types.AttributeMarketID, marketID), - sdk.NewAttribute(types.AttributeOracle, oracle), + sdk.NewAttribute(types.AttributeOracle, oracle.String()), sdk.NewAttribute(types.AttributeMarketPrice, price.String()), sdk.NewAttribute(types.AttributeExpiry, expiry.UTC().String()), ), @@ -109,7 +109,7 @@ func (k Keeper) SetCurrentPrices(ctx sdk.Context, marketID string) error { return types.ErrNoValidPrice } - medianPrice := k.CalculateMedianPrice(ctx, notExpiredPrices) + medianPrice := k.CalculateMedianPrice(notExpiredPrices) // check case that market price was not set in genesis if validPrevPrice && !medianPrice.Equal(prevPrice.Price) { @@ -135,7 +135,7 @@ func (k Keeper) setCurrentPrice(ctx sdk.Context, marketID string, currentPrice t } // CalculateMedianPrice calculates the median prices for the input prices. -func (k Keeper) CalculateMedianPrice(ctx sdk.Context, prices []types.CurrentPrice) sdk.Dec { +func (k Keeper) CalculateMedianPrice(prices []types.CurrentPrice) sdk.Dec { l := len(prices) if l == 1 { @@ -148,16 +148,15 @@ func (k Keeper) CalculateMedianPrice(ctx sdk.Context, prices []types.CurrentPric }) // for even numbers of prices, the median is calculated as the mean of the two middle prices if l%2 == 0 { - median := k.calculateMeanPrice(ctx, prices[l/2-1:l/2+1]) + median := k.calculateMeanPrice(prices[l/2-1], prices[l/2]) return median } // for odd numbers of prices, return the middle element return prices[l/2].Price - } -func (k Keeper) calculateMeanPrice(ctx sdk.Context, prices []types.CurrentPrice) sdk.Dec { - sum := prices[0].Price.Add(prices[1].Price) +func (k Keeper) calculateMeanPrice(priceA, priceB types.CurrentPrice) sdk.Dec { + sum := priceA.Price.Add(priceB.Price) mean := sum.Quo(sdk.NewDec(2)) return mean } @@ -195,8 +194,8 @@ func (k Keeper) IterateCurrentPrices(ctx sdk.Context, cb func(cp types.CurrentPr } // GetCurrentPrices returns all current price objects from the store -func (k Keeper) GetCurrentPrices(ctx sdk.Context) []types.CurrentPrice { - var cps []types.CurrentPrice +func (k Keeper) GetCurrentPrices(ctx sdk.Context) types.CurrentPrices { + var cps types.CurrentPrices k.IterateCurrentPrices(ctx, func(cp types.CurrentPrice) (stop bool) { cps = append(cps, cp) return false @@ -205,8 +204,8 @@ func (k Keeper) GetCurrentPrices(ctx sdk.Context) []types.CurrentPrice { } // GetRawPrices fetches the set of all prices posted by oracles for an asset -func (k Keeper) GetRawPrices(ctx sdk.Context, marketId string) []types.PostedPrice { - var pps []types.PostedPrice +func (k Keeper) GetRawPrices(ctx sdk.Context, marketId string) types.PostedPrices { + var pps types.PostedPrices k.IterateRawPricesByMarket(ctx, marketId, func(pp types.PostedPrice) (stop bool) { pps = append(pps, pp) return false diff --git a/x/pricefeed/keeper/keeper_test.go b/x/pricefeed/keeper/keeper_test.go index fb37cea074..220a2f613b 100644 --- a/x/pricefeed/keeper/keeper_test.go +++ b/x/pricefeed/keeper/keeper_test.go @@ -22,7 +22,7 @@ func TestKeeper_SetGetMarket(t *testing.T) { mp := types.Params{ Markets: []types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, } keeper.SetParams(ctx, mp) @@ -38,8 +38,8 @@ func TestKeeper_SetGetMarket(t *testing.T) { mp = types.Params{ Markets: []types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []string{}, Active: true}, - {MarketID: "tst2usd", BaseAsset: "tst2", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "tst2usd", BaseAsset: "tst2", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, } keeper.SetParams(ctx, mp) @@ -61,20 +61,20 @@ func TestKeeper_GetSetPrice(t *testing.T) { mp := types.Params{ Markets: []types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, } keeper.SetParams(ctx, mp) prices := []struct { - oracle string + oracle sdk.AccAddress marketID string price sdk.Dec total int }{ - {addrs[0].String(), "tstusd", sdk.MustNewDecFromStr("0.33"), 1}, - {addrs[1].String(), "tstusd", sdk.MustNewDecFromStr("0.35"), 2}, - {addrs[0].String(), "tstusd", sdk.MustNewDecFromStr("0.37"), 2}, + {addrs[0], "tstusd", sdk.MustNewDecFromStr("0.33"), 1}, + {addrs[1], "tstusd", sdk.MustNewDecFromStr("0.35"), 2}, + {addrs[0], "tstusd", sdk.MustNewDecFromStr("0.37"), 2}, } for _, p := range prices { @@ -97,7 +97,7 @@ func TestKeeper_GetSetPrice(t *testing.T) { // Find the oracle and require price to be same for _, rp := range rawPrices { - if p.oracle == rp.OracleAddress { + if p.oracle.Equals(rp.OracleAddress) { require.Equal(t, p.price, rp.Price) } } @@ -114,39 +114,39 @@ func TestKeeper_GetSetCurrentPrice(t *testing.T) { mp := types.Params{ Markets: []types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, } keeper.SetParams(ctx, mp) _, err := keeper.SetPrice( - ctx, addrs[0].String(), "tstusd", + ctx, addrs[0], "tstusd", sdk.MustNewDecFromStr("0.33"), time.Now().Add(time.Hour*1)) require.NoError(t, err) _, err = keeper.SetPrice( - ctx, addrs[1].String(), "tstusd", + ctx, addrs[1], "tstusd", sdk.MustNewDecFromStr("0.35"), time.Now().Add(time.Hour*1)) require.NoError(t, err) _, err = keeper.SetPrice( - ctx, addrs[2].String(), "tstusd", + ctx, addrs[2], "tstusd", sdk.MustNewDecFromStr("0.34"), time.Now().Add(time.Hour*1)) require.NoError(t, err) // Add an expired one which should fail _, err = keeper.SetPrice( - ctx, addrs[3].String(), "tstusd", + ctx, addrs[3], "tstusd", sdk.MustNewDecFromStr("0.9"), ctx.BlockTime().Add(-time.Hour*1)) require.Error(t, err) // Add a non-expired price, but will not be counted when BlockTime is changed _, err = keeper.SetPrice( - ctx, addrs[3].String(), "tstusd", + ctx, addrs[3], "tstusd", sdk.MustNewDecFromStr("0.9"), time.Now().Add(time.Minute*30)) require.NoError(t, err) @@ -172,7 +172,7 @@ func TestKeeper_GetSetCurrentPrice(t *testing.T) { // Even number of oracles _, err = keeper.SetPrice( - ctx, addrs[4].String(), "tstusd", + ctx, addrs[4], "tstusd", sdk.MustNewDecFromStr("0.36"), time.Now().Add(time.Hour*1)) require.NoError(t, err) @@ -204,25 +204,25 @@ func TestKeeper_ExpiredSetCurrentPrices(t *testing.T) { mp := types.Params{ Markets: []types.Market{ - {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, } keeper.SetParams(ctx, mp) _, err := keeper.SetPrice( - ctx, addrs[0].String(), "tstusd", + ctx, addrs[0], "tstusd", sdk.MustNewDecFromStr("0.33"), time.Now().Add(time.Hour*1)) require.NoError(t, err) _, err = keeper.SetPrice( - ctx, addrs[1].String(), "tstusd", + ctx, addrs[1], "tstusd", sdk.MustNewDecFromStr("0.35"), time.Now().Add(time.Hour*1)) require.NoError(t, err) _, err = keeper.SetPrice( - ctx, addrs[2].String(), "tstusd", + ctx, addrs[2], "tstusd", sdk.MustNewDecFromStr("0.34"), time.Now().Add(time.Hour*1)) require.NoError(t, err) diff --git a/x/pricefeed/keeper/params.go b/x/pricefeed/keeper/params.go index 43c86de5c0..61b30c4a3f 100644 --- a/x/pricefeed/keeper/params.go +++ b/x/pricefeed/keeper/params.go @@ -20,12 +20,12 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { } // GetMarkets returns the markets from params -func (k Keeper) GetMarkets(ctx sdk.Context) []types.Market { +func (k Keeper) GetMarkets(ctx sdk.Context) types.Markets { return k.GetParams(ctx).Markets } // GetOracles returns the oracles in the pricefeed store -func (k Keeper) GetOracles(ctx sdk.Context, marketID string) ([]string, error) { +func (k Keeper) GetOracles(ctx sdk.Context, marketID string) ([]sdk.AccAddress, error) { for _, m := range k.GetMarkets(ctx) { if marketID == m.MarketID { return m.Oracles, nil @@ -35,18 +35,18 @@ func (k Keeper) GetOracles(ctx sdk.Context, marketID string) ([]string, error) { } // GetOracle returns the oracle from the store or an error if not found -func (k Keeper) GetOracle(ctx sdk.Context, marketID string, address string) (string, error) { +func (k Keeper) GetOracle(ctx sdk.Context, marketID string, address sdk.AccAddress) (sdk.AccAddress, error) { oracles, err := k.GetOracles(ctx, marketID) if err != nil { // Error already wrapped - return "", err + return nil, err } for _, addr := range oracles { - if addr == address { + if addr.Equals(address) { return addr, nil } } - return "", sdkerrors.Wrap(types.ErrInvalidOracle, address) + return nil, sdkerrors.Wrap(types.ErrInvalidOracle, address.String()) } // GetMarket returns the market if it is in the pricefeed system @@ -69,14 +69,10 @@ func (k Keeper) GetAuthorizedAddresses(ctx sdk.Context) []sdk.AccAddress { for _, m := range k.GetMarkets(ctx) { for _, o := range m.Oracles { // de-dup list of oracles - if _, found := uniqueOracles[o]; !found { - addr, err := sdk.AccAddressFromBech32(o) - if err != nil { - panic(err) - } - oracles = append(oracles, addr) + if _, found := uniqueOracles[o.String()]; !found { + oracles = append(oracles, o) } - uniqueOracles[o] = true + uniqueOracles[o.String()] = true } } return oracles diff --git a/x/pricefeed/keeper/params_test.go b/x/pricefeed/keeper/params_test.go index 93a1c5236a..5edec22831 100644 --- a/x/pricefeed/keeper/params_test.go +++ b/x/pricefeed/keeper/params_test.go @@ -19,8 +19,7 @@ type KeeperTestSuite struct { suite.Suite keeper keeper.Keeper - addrs []string - app app.TestApp + addrs []sdk.AccAddress ctx sdk.Context } @@ -34,17 +33,12 @@ func (suite *KeeperTestSuite) SetupTest() { suite.ctx = ctx _, addrs := app.GeneratePrivKeyAddressPairs(10) - var strAddrs []string - for _, addr := range addrs { - strAddrs = append(strAddrs, addr.String()) - } - - suite.addrs = strAddrs + suite.addrs = addrs } func (suite *KeeperTestSuite) TestGetSetOracles() { params := suite.keeper.GetParams(suite.ctx) - suite.Equal([]string(nil), params.Markets[0].Oracles) + suite.Equal([]sdk.AccAddress(nil), params.Markets[0].Oracles) params.Markets[0].Oracles = suite.addrs suite.NotPanics(func() { suite.keeper.SetParams(suite.ctx, params) }) @@ -58,15 +52,11 @@ func (suite *KeeperTestSuite) TestGetSetOracles() { func (suite *KeeperTestSuite) TestGetAuthorizedAddresses() { _, oracles := app.GeneratePrivKeyAddressPairs(5) - var strOracles []string - for _, addr := range oracles { - strOracles = append(strOracles, addr.String()) - } params := types.Params{ Markets: []types.Market{ - {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: strOracles[:3], Active: true}, - {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: strOracles[2:], Active: true}, + {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: oracles[:3], Active: true}, + {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: oracles[2:], Active: true}, {MarketID: "xrp:usd:30", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: nil, Active: true}, }, } diff --git a/x/pricefeed/keeper/querier_test.go b/x/pricefeed/keeper/querier_test.go index a2976a91e5..8584e31dfa 100644 --- a/x/pricefeed/keeper/querier_test.go +++ b/x/pricefeed/keeper/querier_test.go @@ -16,8 +16,8 @@ func (suite *KeeperTestSuite) TestQuerierGetParams() { expParams := types.Params{ Markets: []types.Market{ - {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []string{}, Active: true}, - {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []string{}, Active: true}, + {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, } var p types.Params @@ -128,8 +128,8 @@ func (suite *KeeperTestSuite) TestQuerierGetMarkets() { suite.NotNil(bz) expMarkets := []types.Market{ - types.NewMarket("btc:usd", "btc", "usd", []string(nil), true), - types.NewMarket("xrp:usd", "xrp", "usd", []string(nil), true), + types.NewMarket("btc:usd", "btc", "usd", []sdk.AccAddress(nil), true), + types.NewMarket("xrp:usd", "xrp", "usd", []sdk.AccAddress(nil), true), } var p []types.Market diff --git a/x/pricefeed/module.go b/x/pricefeed/module.go index d7ef6362ed..ab9e805266 100644 --- a/x/pricefeed/module.go +++ b/x/pricefeed/module.go @@ -110,10 +110,7 @@ func (am AppModule) Name() string { } // RegisterInvariants register module invariants -func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { - // keeper.RegisterInvariants(ir, am.keeper) - // TODO -} +func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} // Route module message route name func (am AppModule) Route() sdk.Route { diff --git a/x/pricefeed/msg_server.go b/x/pricefeed/msg_server.go index b0663edad2..a65a81d370 100644 --- a/x/pricefeed/msg_server.go +++ b/x/pricefeed/msg_server.go @@ -24,18 +24,17 @@ var _ types.MsgServer = msgServer{} func (k msgServer) PostPrice(goCtx context.Context, msg *types.MsgPostPrice) (*types.MsgPostPriceResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // Just to validate, we still use string version later - _, err := sdk.AccAddressFromBech32(msg.From) + from, err := sdk.AccAddressFromBech32(msg.From) if err != nil { return nil, err } - _, err = k.keeper.GetOracle(ctx, msg.MarketID, msg.From) + _, err = k.keeper.GetOracle(ctx, msg.MarketID, from) if err != nil { return nil, err } - _, err = k.keeper.SetPrice(ctx, msg.From, msg.MarketID, msg.Price, msg.Expiry) + _, err = k.keeper.SetPrice(ctx, from, msg.MarketID, msg.Price, msg.Expiry) if err != nil { return nil, err } diff --git a/x/pricefeed/msg_server_test.go b/x/pricefeed/msg_server_test.go index 960f0b991a..111f6f689e 100644 --- a/x/pricefeed/msg_server_test.go +++ b/x/pricefeed/msg_server_test.go @@ -20,12 +20,8 @@ func TestKeeper_PostPrice(t *testing.T) { k := tApp.GetPriceFeedKeeper() msgSrv := pricefeed.NewMsgServerImpl(k) - var strAddrs []string - for _, a := range addrs { - strAddrs = append(strAddrs, a.String()) - } - authorizedOracles := strAddrs[:2] - unauthorizedAddrs := strAddrs[2:] + authorizedOracles := addrs[:2] + unauthorizedAddrs := addrs[2:] mp := types.Params{ Markets: []types.Market{ @@ -38,7 +34,7 @@ func TestKeeper_PostPrice(t *testing.T) { tests := []struct { giveMsg string - giveOracle string + giveOracle sdk.AccAddress giveMarketId string giveExpiry time.Time wantAccepted bool @@ -53,7 +49,7 @@ func TestKeeper_PostPrice(t *testing.T) { for _, tt := range tests { t.Run(tt.giveMsg, func(t *testing.T) { // Use MsgServer over keeper methods directly to tests against valid oracles - msg := types.NewMsgPostPrice(tt.giveOracle, tt.giveMarketId, sdk.MustNewDecFromStr("0.5"), tt.giveExpiry) + msg := types.NewMsgPostPrice(tt.giveOracle.String(), tt.giveMarketId, sdk.MustNewDecFromStr("0.5"), tt.giveExpiry) _, err := msgSrv.PostPrice(sdk.WrapSDKContext(ctx), msg) if tt.wantAccepted { diff --git a/x/pricefeed/types/genesis.go b/x/pricefeed/types/genesis.go index a43c64e0ed..c9eba7bee8 100644 --- a/x/pricefeed/types/genesis.go +++ b/x/pricefeed/types/genesis.go @@ -23,5 +23,5 @@ func (gs GenesisState) Validate() error { return err } - return ValidatePostedPrices(gs.PostedPrices) + return gs.PostedPrices.Validate() } diff --git a/x/pricefeed/types/genesis.pb.go b/x/pricefeed/types/genesis.pb.go index eb2e949a4b..ba10107adb 100644 --- a/x/pricefeed/types/genesis.pb.go +++ b/x/pricefeed/types/genesis.pb.go @@ -26,8 +26,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the pricefeed module's genesis state. type GenesisState struct { // params defines all the paramaters of the module. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - PostedPrices []PostedPrice `protobuf:"bytes,2,rep,name=posted_prices,json=postedPrices,proto3" json:"posted_prices"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + PostedPrices PostedPrices `protobuf:"bytes,2,rep,name=posted_prices,json=postedPrices,proto3,castrepeated=PostedPrices" json:"posted_prices"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -70,60 +70,15 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetPostedPrices() []PostedPrice { +func (m *GenesisState) GetPostedPrices() PostedPrices { if m != nil { return m.PostedPrices } return nil } -// Params defines the parameters for the pricefeed module. -type Params struct { - Markets []Market `protobuf:"bytes,1,rep,name=markets,proto3" json:"markets"` -} - -func (m *Params) Reset() { *m = Params{} } -func (*Params) ProtoMessage() {} -func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_fffec798191784d2, []int{1} -} -func (m *Params) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Params.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Params) XXX_Merge(src proto.Message) { - xxx_messageInfo_Params.Merge(m, src) -} -func (m *Params) XXX_Size() int { - return m.Size() -} -func (m *Params) XXX_DiscardUnknown() { - xxx_messageInfo_Params.DiscardUnknown(m) -} - -var xxx_messageInfo_Params proto.InternalMessageInfo - -func (m *Params) GetMarkets() []Market { - if m != nil { - return m.Markets - } - return nil -} - func init() { proto.RegisterType((*GenesisState)(nil), "kava.pricefeed.v1beta1.GenesisState") - proto.RegisterType((*Params)(nil), "kava.pricefeed.v1beta1.Params") } func init() { @@ -131,25 +86,24 @@ func init() { } var fileDescriptor_fffec798191784d2 = []byte{ - // 285 bytes of a gzipped FileDescriptorProto + // 262 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc9, 0x4e, 0x2c, 0x4b, 0xd4, 0x2f, 0x28, 0xca, 0x4c, 0x4e, 0x4d, 0x4b, 0x4d, 0x4d, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, - 0x17, 0x12, 0x03, 0xa9, 0xd2, 0x83, 0xab, 0xd2, 0x83, 0xaa, 0x92, 0x52, 0xc3, 0xa1, 0x1b, 0xa1, - 0x12, 0xac, 0x5f, 0x4a, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, 0xd4, 0x07, 0xb1, 0x20, 0xa2, 0x4a, - 0x73, 0x18, 0xb9, 0x78, 0xdc, 0x21, 0xf6, 0x04, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0xd9, 0x70, 0xb1, - 0x15, 0x24, 0x16, 0x25, 0xe6, 0x16, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0xc9, 0xe9, 0x61, - 0xb7, 0x57, 0x2f, 0x00, 0xac, 0xca, 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, 0xa8, 0x1e, 0x21, - 0x3f, 0x2e, 0xde, 0x82, 0xfc, 0xe2, 0x92, 0xd4, 0x94, 0x78, 0xb0, 0x86, 0x62, 0x09, 0x26, 0x05, - 0x66, 0x0d, 0x6e, 0x23, 0x65, 0x9c, 0x86, 0x80, 0x15, 0x07, 0x80, 0xc4, 0xa1, 0x26, 0xf1, 0x14, - 0x20, 0x84, 0x8a, 0x95, 0xfc, 0xb8, 0xd8, 0x20, 0xf6, 0x08, 0xd9, 0x71, 0xb1, 0xe7, 0x26, 0x16, - 0x65, 0xa7, 0x96, 0x80, 0x1c, 0xc6, 0x8c, 0xcf, 0x61, 0xbe, 0x60, 0x65, 0x50, 0xe3, 0x60, 0x9a, - 0xac, 0x58, 0x66, 0x2c, 0x90, 0x67, 0x70, 0xf2, 0x7d, 0xf0, 0x50, 0x8e, 0x71, 0xc5, 0x23, 0x39, - 0xc6, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, - 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xd2, 0x4e, 0xcf, 0x2c, 0xc9, - 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x07, 0x59, 0xa0, 0x9b, 0x93, 0x98, 0x54, 0x0c, 0x66, - 0xe9, 0x57, 0x20, 0x85, 0x72, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x38, 0x10, 0x8d, 0x01, - 0x01, 0x00, 0x00, 0xff, 0xff, 0xf6, 0x87, 0x5e, 0xda, 0xc2, 0x01, 0x00, 0x00, + 0x17, 0x12, 0x03, 0xa9, 0xd2, 0x83, 0xab, 0xd2, 0x83, 0xaa, 0x92, 0x52, 0xc2, 0xa1, 0xbb, 0xb8, + 0x24, 0xbf, 0x28, 0x15, 0xa2, 0x57, 0x4a, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, 0xd4, 0x07, 0xb1, + 0x20, 0xa2, 0x4a, 0x6b, 0x18, 0xb9, 0x78, 0xdc, 0x21, 0x76, 0x04, 0x97, 0x24, 0x96, 0xa4, 0x0a, + 0xd9, 0x70, 0xb1, 0x15, 0x24, 0x16, 0x25, 0xe6, 0x16, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, + 0xc9, 0xe9, 0x61, 0xb7, 0x53, 0x2f, 0x00, 0xac, 0xca, 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, + 0xa8, 0x1e, 0xa1, 0x38, 0x2e, 0xde, 0x82, 0xfc, 0xe2, 0x92, 0xd4, 0x94, 0x78, 0xb0, 0x86, 0x62, + 0x09, 0x26, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x65, 0x9c, 0x86, 0x80, 0x15, 0x07, 0x80, 0xc4, 0x9d, + 0x44, 0x40, 0x26, 0xad, 0xba, 0x2f, 0xcf, 0x83, 0x24, 0x58, 0x1c, 0xc4, 0x53, 0x80, 0xc4, 0x73, + 0xf2, 0x7d, 0xf0, 0x50, 0x8e, 0x71, 0xc5, 0x23, 0x39, 0xc6, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, + 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, + 0x3c, 0x96, 0x63, 0x88, 0xd2, 0x4e, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, + 0x07, 0x59, 0xaa, 0x9b, 0x93, 0x98, 0x54, 0x0c, 0x66, 0xe9, 0x57, 0x20, 0x85, 0x50, 0x49, 0x65, + 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x38, 0x10, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x4e, 0x23, + 0x61, 0x2f, 0x7e, 0x01, 0x00, 0x00, } func (this *GenesisState) VerboseEqual(that interface{}) error { @@ -222,70 +176,6 @@ func (this *GenesisState) Equal(that interface{}) bool { } return true } -func (this *Params) VerboseEqual(that interface{}) error { - if that == nil { - if this == nil { - return nil - } - return fmt.Errorf("that == nil && this != nil") - } - - that1, ok := that.(*Params) - if !ok { - that2, ok := that.(Params) - if ok { - that1 = &that2 - } else { - return fmt.Errorf("that is not of type *Params") - } - } - if that1 == nil { - if this == nil { - return nil - } - return fmt.Errorf("that is type *Params but is nil && this != nil") - } else if this == nil { - return fmt.Errorf("that is type *Params but is not nil && this == nil") - } - if len(this.Markets) != len(that1.Markets) { - return fmt.Errorf("Markets this(%v) Not Equal that(%v)", len(this.Markets), len(that1.Markets)) - } - for i := range this.Markets { - if !this.Markets[i].Equal(&that1.Markets[i]) { - return fmt.Errorf("Markets this[%v](%v) Not Equal that[%v](%v)", i, this.Markets[i], i, that1.Markets[i]) - } - } - return nil -} -func (this *Params) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Params) - if !ok { - that2, ok := that.(Params) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Markets) != len(that1.Markets) { - return false - } - for i := range this.Markets { - if !this.Markets[i].Equal(&that1.Markets[i]) { - return false - } - } - return true -} func (m *GenesisState) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -333,43 +223,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *Params) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Params) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Markets) > 0 { - for iNdEx := len(m.Markets) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Markets[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -398,21 +251,6 @@ func (m *GenesisState) Size() (n int) { return n } -func (m *Params) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Markets) > 0 { - for _, e := range m.Markets { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - return n -} - func sovGenesis(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -536,90 +374,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } return nil } -func (m *Params) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Params: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Markets", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Markets = append(m.Markets, Market{}) - if err := m.Markets[len(m.Markets)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGenesis(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipGenesis(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/pricefeed/types/genesis_test.go b/x/pricefeed/types/genesis_test.go index 251aea626b..e9c9e632ad 100644 --- a/x/pricefeed/types/genesis_test.go +++ b/x/pricefeed/types/genesis_test.go @@ -32,9 +32,9 @@ func TestGenesisStateValidate(t *testing.T) { msg: "valid genesis", genesisState: NewGenesisState( NewParams([]Market{ - {"market", "xrp", "bnb", []string{addr.String()}, true}, + {"market", "xrp", "bnb", []sdk.AccAddress{addr}, true}, }), - []PostedPrice{NewPostedPrice("xrp", addr.String(), sdk.OneDec(), now)}, + []PostedPrice{NewPostedPrice("xrp", addr, sdk.OneDec(), now)}, ), expPass: true, }, @@ -42,9 +42,9 @@ func TestGenesisStateValidate(t *testing.T) { msg: "invalid param", genesisState: NewGenesisState( NewParams([]Market{ - {"", "xrp", "bnb", []string{addr.String()}, true}, + {"", "xrp", "bnb", []sdk.AccAddress{addr}, true}, }), - []PostedPrice{NewPostedPrice("xrp", addr.String(), sdk.OneDec(), now)}, + []PostedPrice{NewPostedPrice("xrp", addr, sdk.OneDec(), now)}, ), expPass: false, }, @@ -52,10 +52,10 @@ func TestGenesisStateValidate(t *testing.T) { msg: "dup market param", genesisState: NewGenesisState( NewParams([]Market{ - {"market", "xrp", "bnb", []string{addr.String()}, true}, - {"market", "xrp", "bnb", []string{addr.String()}, true}, + {"market", "xrp", "bnb", []sdk.AccAddress{addr}, true}, + {"market", "xrp", "bnb", []sdk.AccAddress{addr}, true}, }), - []PostedPrice{NewPostedPrice("xrp", addr.String(), sdk.OneDec(), now)}, + []PostedPrice{NewPostedPrice("xrp", addr, sdk.OneDec(), now)}, ), expPass: false, }, @@ -63,7 +63,7 @@ func TestGenesisStateValidate(t *testing.T) { msg: "invalid posted price", genesisState: NewGenesisState( NewParams([]Market{}), - []PostedPrice{NewPostedPrice("xrp", "", sdk.OneDec(), now)}, + []PostedPrice{NewPostedPrice("xrp", nil, sdk.OneDec(), now)}, ), expPass: false, }, @@ -72,8 +72,8 @@ func TestGenesisStateValidate(t *testing.T) { genesisState: NewGenesisState( NewParams([]Market{}), []PostedPrice{ - NewPostedPrice("xrp", addr.String(), sdk.OneDec(), now), - NewPostedPrice("xrp", addr.String(), sdk.OneDec(), now), + NewPostedPrice("xrp", addr, sdk.OneDec(), now), + NewPostedPrice("xrp", addr, sdk.OneDec(), now), }, ), expPass: false, diff --git a/x/pricefeed/types/key.go b/x/pricefeed/types/key.go index 03486eb90b..c8062ed514 100644 --- a/x/pricefeed/types/key.go +++ b/x/pricefeed/types/key.go @@ -1,5 +1,7 @@ package types +import sdk "github.com/cosmos/cosmos-sdk/types" + const ( // ModuleName The name that will be used throughout the module ModuleName = "pricefeed" @@ -39,10 +41,10 @@ func RawPriceIteratorKey(marketID string) []byte { } // RawPriceKey returns the prefix for the raw price -func RawPriceKey(marketID string, oracleAddr string) []byte { +func RawPriceKey(marketID string, oracleAddr sdk.AccAddress) []byte { return append( RawPriceIteratorKey(marketID), - lengthPrefixWithByte([]byte(oracleAddr))..., + lengthPrefixWithByte(oracleAddr)..., ) } diff --git a/x/pricefeed/types/key_test.go b/x/pricefeed/types/key_test.go index d60b3d4d18..a18e17409d 100644 --- a/x/pricefeed/types/key_test.go +++ b/x/pricefeed/types/key_test.go @@ -3,14 +3,16 @@ package types import ( "testing" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" ) func TestRawPriceKey_Iteration(t *testing.T) { - // An iterator key should only match price keys with the same market iteratorKey := RawPriceIteratorKey("kava:usd") + addr := sdk.AccAddress("test addr") + testCases := []struct { name string priceKey []byte @@ -18,17 +20,12 @@ func TestRawPriceKey_Iteration(t *testing.T) { }{ { name: "equal marketID is included in iteration", - priceKey: RawPriceKey("kava:usd", "kava17e8afwcxk0k72hhr7xapugtf5xhxth0a6d5jwz"), + priceKey: RawPriceKey("kava:usd", addr), expectErr: false, }, { name: "prefix overlapping marketID excluded from iteration", - priceKey: RawPriceKey("kava:usd:30", "kava17e8afwcxk0k72hhr7xapugtf5xhxth0a6d5jwz"), - expectErr: true, - }, - { - name: "injection via oracle address excluded from iteration", - priceKey: RawPriceKey("", "kava:usdkava17e8afwcxk0k72hhr7xapugtf5xhxth0a6d5jwz"), + priceKey: RawPriceKey("kava:usd:30", addr), expectErr: true, }, } diff --git a/x/pricefeed/types/market.go b/x/pricefeed/types/market.go index 25b28cd348..923260fa39 100644 --- a/x/pricefeed/types/market.go +++ b/x/pricefeed/types/market.go @@ -10,7 +10,7 @@ import ( ) // NewMarket returns a new Market -func NewMarket(id, base, quote string, oracles []string, active bool) Market { +func NewMarket(id, base, quote string, oracles []sdk.AccAddress, active bool) Market { return Market{ MarketID: id, BaseAsset: base, @@ -20,17 +20,6 @@ func NewMarket(id, base, quote string, oracles []string, active bool) Market { } } -// String implement fmt.Stringer -func (m Market) String() string { - return fmt.Sprintf(`Asset: - Market ID: %s - Base Asset: %s - Quote Asset: %s - Oracles: %s - Active: %t`, - m.MarketID, m.BaseAsset, m.QuoteAsset, m.Oracles, m.Active) -} - // Validate performs a basic validation of the market params func (m Market) Validate() error { if strings.TrimSpace(m.MarketID) == "" { @@ -47,17 +36,25 @@ func (m Market) Validate() error { if len(oracle) == 0 { return fmt.Errorf("oracle %d is empty", i) } - if seenOracles[oracle] { + if seenOracles[oracle.String()] { return fmt.Errorf("duplicated oracle %s", oracle) } - seenOracles[oracle] = true + seenOracles[oracle.String()] = true } return nil } -// ValidateMarkets checks if all the markets are valid and there are no -// duplicated entries. -func ValidateMarkets(ms []Market) error { +// ToMarketResponse returns a new MarketResponse from a Market +func (m Market) ToMarketResponse() MarketResponse { + return NewMarketResponse(m.MarketID, m.BaseAsset, m.QuoteAsset, m.Oracles, m.Active) +} + +// Markets is a slice of Market +type Markets []Market + +// Validate checks if all the markets are valid and there are no duplicated +// entries. +func (ms Markets) Validate() error { seenMarkets := make(map[string]bool) for _, m := range ms { if seenMarkets[m.MarketID] { @@ -71,13 +68,43 @@ func ValidateMarkets(ms []Market) error { return nil } +// NewMarketResponse returns a new MarketResponse +func NewMarketResponse(id, base, quote string, oracles []sdk.AccAddress, active bool) MarketResponse { + var strOracles []string + for _, oracle := range oracles { + strOracles = append(strOracles, oracle.String()) + } + + return MarketResponse{ + MarketID: id, + BaseAsset: base, + QuoteAsset: quote, + Oracles: strOracles, + Active: active, + } +} + +// MarketResponses is a slice of MarketResponse +type MarketResponses []MarketResponse + // NewCurrentPrice returns an instance of CurrentPrice func NewCurrentPrice(marketID string, price sdk.Dec) CurrentPrice { return CurrentPrice{MarketID: marketID, Price: price} } +// CurrentPrices is a slice of CurrentPrice +type CurrentPrices []CurrentPrice + +// NewCurrentPriceResponse returns an instance of CurrentPriceResponse +func NewCurrentPriceResponse(marketID string, price sdk.Dec) CurrentPriceResponse { + return CurrentPriceResponse{MarketID: marketID, Price: price} +} + +// CurrentPriceResponses is a slice of CurrentPriceResponse +type CurrentPriceResponses []CurrentPriceResponse + // NewPostedPrice returns a new PostedPrice -func NewPostedPrice(marketID string, oracle string, price sdk.Dec, expiry time.Time) PostedPrice { +func NewPostedPrice(marketID string, oracle sdk.AccAddress, price sdk.Dec, expiry time.Time) PostedPrice { return PostedPrice{ MarketID: marketID, OracleAddress: oracle, @@ -103,37 +130,39 @@ func (pp PostedPrice) Validate() error { return nil } -// ValidatePostedPrices checks if all the posted prices are valid and there are -// no duplicated entries. -func ValidatePostedPrices(pps []PostedPrice) error { +// PostedPrices is a slice of PostedPrice +type PostedPrices []PostedPrice + +// Validate checks if all the posted prices are valid and there are no +// duplicated entries. +func (pps PostedPrices) Validate() error { seenPrices := make(map[string]bool) for _, pp := range pps { - if pp.OracleAddress != "" && seenPrices[pp.MarketID+pp.OracleAddress] { + if !pp.OracleAddress.Empty() && seenPrices[pp.MarketID+pp.OracleAddress.String()] { return fmt.Errorf("duplicated posted price for marked id %s and oracle address %s", pp.MarketID, pp.OracleAddress) } if err := pp.Validate(); err != nil { return err } - seenPrices[pp.MarketID+pp.OracleAddress] = true + seenPrices[pp.MarketID+pp.OracleAddress.String()] = true } return nil } -// String implements fmt.Stringer -func (cp CurrentPrice) String() string { - return strings.TrimSpace(fmt.Sprintf(`Market ID: %s -Price: %s`, cp.MarketID, cp.Price)) +// NewPostedPrice returns a new PostedPrice +func NewPostedPriceResponse(marketID string, oracle sdk.AccAddress, price sdk.Dec, expiry time.Time) PostedPriceResponse { + return PostedPriceResponse{ + MarketID: marketID, + OracleAddress: oracle.String(), + Price: price, + Expiry: expiry, + } } -// String implements fmt.Stringer -func (pp PostedPrice) String() string { - return strings.TrimSpace(fmt.Sprintf(`Market ID: %s -Oracle Address: %s -Price: %s -Expiry: %s`, pp.MarketID, pp.OracleAddress, pp.Price, pp.Expiry)) -} +// PostedPriceResponses is a slice of PostedPriceResponse +type PostedPriceResponses []PostedPriceResponse // SortDecs provides the interface needed to sort sdk.Dec slices type SortDecs []sdk.Dec diff --git a/x/pricefeed/types/market_test.go b/x/pricefeed/types/market_test.go index e2f6259349..54bc397395 100644 --- a/x/pricefeed/types/market_test.go +++ b/x/pricefeed/types/market_test.go @@ -28,7 +28,7 @@ func TestMarketValidate(t *testing.T) { MarketID: "market", BaseAsset: "xrp", QuoteAsset: "bnb", - Oracles: []string{addr.String()}, + Oracles: []sdk.AccAddress{addr}, Active: true, }, true, @@ -64,7 +64,7 @@ func TestMarketValidate(t *testing.T) { MarketID: "market", BaseAsset: "xrp", QuoteAsset: "bnb", - Oracles: []string{""}, + Oracles: []sdk.AccAddress{nil}, }, false, }, @@ -74,7 +74,7 @@ func TestMarketValidate(t *testing.T) { MarketID: "market", BaseAsset: "xrp", QuoteAsset: "bnb", - Oracles: []string{addr.String(), addr.String()}, + Oracles: []sdk.AccAddress{addr, addr}, }, false, }, @@ -108,7 +108,7 @@ func TestPostedPriceValidate(t *testing.T) { "valid posted price", PostedPrice{ MarketID: "market", - OracleAddress: addr.String(), + OracleAddress: addr, Price: sdk.OneDec(), Expiry: now, }, @@ -125,7 +125,7 @@ func TestPostedPriceValidate(t *testing.T) { "invalid oracle", PostedPrice{ MarketID: "market", - OracleAddress: "", + OracleAddress: sdk.AccAddress{}, }, false, }, @@ -133,7 +133,7 @@ func TestPostedPriceValidate(t *testing.T) { "invalid price", PostedPrice{ MarketID: "market", - OracleAddress: addr.String(), + OracleAddress: addr, Price: sdk.NewDec(-1), }, false, @@ -142,7 +142,7 @@ func TestPostedPriceValidate(t *testing.T) { "zero expiry time ", PostedPrice{ MarketID: "market", - OracleAddress: addr.String(), + OracleAddress: addr, Price: sdk.OneDec(), Expiry: time.Time{}, }, diff --git a/x/pricefeed/types/params.go b/x/pricefeed/types/params.go index ed718338a1..96716df248 100644 --- a/x/pricefeed/types/params.go +++ b/x/pricefeed/types/params.go @@ -2,7 +2,6 @@ package types import ( "fmt" - "strings" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -38,25 +37,16 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { } } -// String implements fmt.stringer -func (p Params) String() string { - out := "Params:\n" - for _, a := range p.Markets { - out += fmt.Sprintf("%s\n", a.String()) - } - return strings.TrimSpace(out) -} - // Validate ensure that params have valid values func (p Params) Validate() error { return validateMarketParams(p.Markets) } func validateMarketParams(i interface{}) error { - markets, ok := i.([]Market) + markets, ok := i.(Markets) if !ok { return fmt.Errorf("invalid parameter type: %T", i) } - return ValidateMarkets(markets) + return markets.Validate() } diff --git a/x/pricefeed/types/query.pb.go b/x/pricefeed/types/query.pb.go index 9e5f88b905..a59fe0df5a 100644 --- a/x/pricefeed/types/query.pb.go +++ b/x/pricefeed/types/query.pb.go @@ -6,22 +6,27 @@ package types import ( context "context" fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" + time "time" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf +var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -146,7 +151,7 @@ var xxx_messageInfo_QueryPriceRequest proto.InternalMessageInfo // QueryPriceResponse is the response type for the Query/Prices RPC method. type QueryPriceResponse struct { - Price CurrentPrice `protobuf:"bytes,1,opt,name=price,proto3" json:"price"` + Price CurrentPriceResponse `protobuf:"bytes,1,opt,name=price,proto3" json:"price"` } func (m *QueryPriceResponse) Reset() { *m = QueryPriceResponse{} } @@ -221,7 +226,7 @@ var xxx_messageInfo_QueryPricesRequest proto.InternalMessageInfo // QueryPricesResponse is the response type for the Query/Prices RPC method. type QueryPricesResponse struct { - Prices []CurrentPrice `protobuf:"bytes,1,rep,name=prices,proto3" json:"prices"` + Prices CurrentPriceResponses `protobuf:"bytes,1,rep,name=prices,proto3,castrepeated=CurrentPriceResponses" json:"prices"` } func (m *QueryPricesResponse) Reset() { *m = QueryPricesResponse{} } @@ -298,7 +303,7 @@ var xxx_messageInfo_QueryRawPricesRequest proto.InternalMessageInfo // QueryRawPricesResponse is the response type for the Query/RawPrices RPC // method. type QueryRawPricesResponse struct { - RawPrices []PostedPrice `protobuf:"bytes,1,rep,name=raw_prices,json=rawPrices,proto3" json:"raw_prices"` + RawPrices PostedPriceResponses `protobuf:"bytes,1,rep,name=raw_prices,json=rawPrices,proto3,castrepeated=PostedPriceResponses" json:"raw_prices"` } func (m *QueryRawPricesResponse) Reset() { *m = QueryRawPricesResponse{} } @@ -451,7 +456,7 @@ var xxx_messageInfo_QueryMarketsRequest proto.InternalMessageInfo // QueryMarketsResponse is the response type for the Query/Markets RPC method. type QueryMarketsResponse struct { // List of markets - Markets []Market `protobuf:"bytes,1,rep,name=markets,proto3" json:"markets"` + Markets MarketResponses `protobuf:"bytes,1,rep,name=markets,proto3,castrepeated=MarketResponses" json:"markets"` } func (m *QueryMarketsResponse) Reset() { *m = QueryMarketsResponse{} } @@ -487,6 +492,192 @@ func (m *QueryMarketsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryMarketsResponse proto.InternalMessageInfo +// PostedPriceResponse defines a price for market posted by a specific oracle. +type PostedPriceResponse struct { + MarketID string `protobuf:"bytes,1,opt,name=market_id,json=marketId,proto3" json:"market_id,omitempty"` + OracleAddress string `protobuf:"bytes,2,opt,name=oracle_address,json=oracleAddress,proto3" json:"oracle_address,omitempty"` + Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price"` + Expiry time.Time `protobuf:"bytes,4,opt,name=expiry,proto3,stdtime" json:"expiry"` +} + +func (m *PostedPriceResponse) Reset() { *m = PostedPriceResponse{} } +func (m *PostedPriceResponse) String() string { return proto.CompactTextString(m) } +func (*PostedPriceResponse) ProtoMessage() {} +func (*PostedPriceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_84567be3085e4c6c, []int{12} +} +func (m *PostedPriceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PostedPriceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PostedPriceResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PostedPriceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_PostedPriceResponse.Merge(m, src) +} +func (m *PostedPriceResponse) XXX_Size() int { + return m.Size() +} +func (m *PostedPriceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_PostedPriceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_PostedPriceResponse proto.InternalMessageInfo + +func (m *PostedPriceResponse) GetMarketID() string { + if m != nil { + return m.MarketID + } + return "" +} + +func (m *PostedPriceResponse) GetOracleAddress() string { + if m != nil { + return m.OracleAddress + } + return "" +} + +func (m *PostedPriceResponse) GetExpiry() time.Time { + if m != nil { + return m.Expiry + } + return time.Time{} +} + +// CurrentPriceResponse defines a current price for a particular market in the pricefeed +// module. +type CurrentPriceResponse struct { + MarketID string `protobuf:"bytes,1,opt,name=market_id,json=marketId,proto3" json:"market_id,omitempty"` + Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price"` +} + +func (m *CurrentPriceResponse) Reset() { *m = CurrentPriceResponse{} } +func (m *CurrentPriceResponse) String() string { return proto.CompactTextString(m) } +func (*CurrentPriceResponse) ProtoMessage() {} +func (*CurrentPriceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_84567be3085e4c6c, []int{13} +} +func (m *CurrentPriceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CurrentPriceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CurrentPriceResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CurrentPriceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CurrentPriceResponse.Merge(m, src) +} +func (m *CurrentPriceResponse) XXX_Size() int { + return m.Size() +} +func (m *CurrentPriceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CurrentPriceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CurrentPriceResponse proto.InternalMessageInfo + +func (m *CurrentPriceResponse) GetMarketID() string { + if m != nil { + return m.MarketID + } + return "" +} + +// MarketResponse defines an asset in the pricefeed. +type MarketResponse struct { + MarketID string `protobuf:"bytes,1,opt,name=market_id,json=marketId,proto3" json:"market_id,omitempty"` + BaseAsset string `protobuf:"bytes,2,opt,name=base_asset,json=baseAsset,proto3" json:"base_asset,omitempty"` + QuoteAsset string `protobuf:"bytes,3,opt,name=quote_asset,json=quoteAsset,proto3" json:"quote_asset,omitempty"` + Oracles []string `protobuf:"bytes,4,rep,name=oracles,proto3" json:"oracles,omitempty"` + Active bool `protobuf:"varint,5,opt,name=active,proto3" json:"active,omitempty"` +} + +func (m *MarketResponse) Reset() { *m = MarketResponse{} } +func (m *MarketResponse) String() string { return proto.CompactTextString(m) } +func (*MarketResponse) ProtoMessage() {} +func (*MarketResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_84567be3085e4c6c, []int{14} +} +func (m *MarketResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MarketResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MarketResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MarketResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MarketResponse.Merge(m, src) +} +func (m *MarketResponse) XXX_Size() int { + return m.Size() +} +func (m *MarketResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MarketResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MarketResponse proto.InternalMessageInfo + +func (m *MarketResponse) GetMarketID() string { + if m != nil { + return m.MarketID + } + return "" +} + +func (m *MarketResponse) GetBaseAsset() string { + if m != nil { + return m.BaseAsset + } + return "" +} + +func (m *MarketResponse) GetQuoteAsset() string { + if m != nil { + return m.QuoteAsset + } + return "" +} + +func (m *MarketResponse) GetOracles() []string { + if m != nil { + return m.Oracles + } + return nil +} + +func (m *MarketResponse) GetActive() bool { + if m != nil { + return m.Active + } + return false +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "kava.pricefeed.v1beta1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "kava.pricefeed.v1beta1.QueryParamsResponse") @@ -500,6 +691,9 @@ func init() { proto.RegisterType((*QueryOraclesResponse)(nil), "kava.pricefeed.v1beta1.QueryOraclesResponse") proto.RegisterType((*QueryMarketsRequest)(nil), "kava.pricefeed.v1beta1.QueryMarketsRequest") proto.RegisterType((*QueryMarketsResponse)(nil), "kava.pricefeed.v1beta1.QueryMarketsResponse") + proto.RegisterType((*PostedPriceResponse)(nil), "kava.pricefeed.v1beta1.PostedPriceResponse") + proto.RegisterType((*CurrentPriceResponse)(nil), "kava.pricefeed.v1beta1.CurrentPriceResponse") + proto.RegisterType((*MarketResponse)(nil), "kava.pricefeed.v1beta1.MarketResponse") } func init() { @@ -507,48 +701,63 @@ func init() { } var fileDescriptor_84567be3085e4c6c = []byte{ - // 643 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x95, 0xb1, 0x6f, 0xd3, 0x40, - 0x14, 0xc6, 0x73, 0xd0, 0x24, 0xe4, 0x98, 0x38, 0xd2, 0xaa, 0x32, 0xc8, 0x29, 0xa6, 0x2a, 0x90, - 0x34, 0xb6, 0x9a, 0x8a, 0x0a, 0x55, 0x08,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3, 0xa1, 0x8e, 0x8e, 0x87, 0x3a, 0xfa, 0x38, 0xd2, 0x33, - 0x47, 0x23, 0x3d, 0xf3, 0x73, 0xa4, 0x67, 0x9e, 0x57, 0x6c, 0x27, 0xd8, 0xe9, 0xb7, 0xcc, 0x36, - 0xef, 0x49, 0xb3, 0x6a, 0x97, 0xb6, 0x7c, 0x65, 0xfb, 0x72, 0xc2, 0x38, 0x38, 0xf0, 0x98, 0xdf, - 0xca, 0xc9, 0xdf, 0xb9, 0xf5, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xbd, 0xf8, 0x1e, 0x9d, 0xa7, - 0x07, 0x00, 0x00, + // 883 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcf, 0x6f, 0x1b, 0x45, + 0x14, 0xf6, 0xa4, 0xfe, 0x39, 0x85, 0x22, 0xa6, 0x4e, 0xb0, 0x4c, 0xbb, 0x1b, 0x56, 0x22, 0xb4, + 0x71, 0xbc, 0xab, 0xa6, 0xa2, 0x42, 0x15, 0x97, 0x9a, 0x1c, 0xe8, 0xa1, 0x02, 0x56, 0x5c, 0xca, + 0xc5, 0x1a, 0x7b, 0xa7, 0xee, 0x2a, 0xb1, 0x67, 0xb3, 0x33, 0x8e, 0x1b, 0x21, 0x24, 0x84, 0x90, + 0x28, 0x07, 0xa4, 0x08, 0x4e, 0xdc, 0xe0, 0x86, 0x90, 0xf8, 0x3f, 0x72, 0x8c, 0xc4, 0x05, 0x71, + 0x48, 0x82, 0xc3, 0x8d, 0x7f, 0x02, 0xed, 0xcc, 0xdb, 0xc5, 0x9b, 0x78, 0x93, 0xb5, 0x38, 0x79, + 0xe7, 0xcd, 0x7b, 0xdf, 0xfb, 0xde, 0x37, 0x33, 0x9f, 0xb1, 0xb5, 0x4d, 0xf7, 0xa8, 0x13, 0x84, + 0x7e, 0x9f, 0x3d, 0x63, 0xcc, 0x73,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, 0x0a, 0x9f, + 0xb5, 0x66, 0x7c, 0x28, 0x02, 0x6b, 0xef, 0xd0, 0x9e, 0xd0, 0xb0, 0x2f, 0x66, 0x80, 0x95, 0x21, + 0xf5, 0xca, 0xca, 0x35, 0xef, 0xff, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xfb, 0x14, 0x01, 0xd9, 0x2c, + 0x0a, 0x00, 0x00, } func (this *QueryParamsRequest) VerboseEqual(that interface{}) error { @@ -1221,6 +1430,226 @@ func (this *QueryMarketsResponse) Equal(that interface{}) bool { } return true } +func (this *PostedPriceResponse) VerboseEqual(that interface{}) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } + + that1, ok := that.(*PostedPriceResponse) + if !ok { + that2, ok := that.(PostedPriceResponse) + if ok { + that1 = &that2 + } else { + return fmt.Errorf("that is not of type *PostedPriceResponse") + } + } + if that1 == nil { + if this == nil { + return nil + } + return fmt.Errorf("that is type *PostedPriceResponse but is nil && this != nil") + } else if this == nil { + return fmt.Errorf("that is type *PostedPriceResponse but is not nil && this == nil") + } + if this.MarketID != that1.MarketID { + return fmt.Errorf("MarketID this(%v) Not Equal that(%v)", this.MarketID, that1.MarketID) + } + if this.OracleAddress != that1.OracleAddress { + return fmt.Errorf("OracleAddress this(%v) Not Equal that(%v)", this.OracleAddress, that1.OracleAddress) + } + if !this.Price.Equal(that1.Price) { + return fmt.Errorf("Price this(%v) Not Equal that(%v)", this.Price, that1.Price) + } + if !this.Expiry.Equal(that1.Expiry) { + return fmt.Errorf("Expiry this(%v) Not Equal that(%v)", this.Expiry, that1.Expiry) + } + return nil +} +func (this *PostedPriceResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*PostedPriceResponse) + if !ok { + that2, ok := that.(PostedPriceResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.MarketID != that1.MarketID { + return false + } + if this.OracleAddress != that1.OracleAddress { + return false + } + if !this.Price.Equal(that1.Price) { + return false + } + if !this.Expiry.Equal(that1.Expiry) { + return false + } + return true +} +func (this *CurrentPriceResponse) VerboseEqual(that interface{}) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } + + that1, ok := that.(*CurrentPriceResponse) + if !ok { + that2, ok := that.(CurrentPriceResponse) + if ok { + that1 = &that2 + } else { + return fmt.Errorf("that is not of type *CurrentPriceResponse") + } + } + if that1 == nil { + if this == nil { + return nil + } + return fmt.Errorf("that is type *CurrentPriceResponse but is nil && this != nil") + } else if this == nil { + return fmt.Errorf("that is type *CurrentPriceResponse but is not nil && this == nil") + } + if this.MarketID != that1.MarketID { + return fmt.Errorf("MarketID this(%v) Not Equal that(%v)", this.MarketID, that1.MarketID) + } + if !this.Price.Equal(that1.Price) { + return fmt.Errorf("Price this(%v) Not Equal that(%v)", this.Price, that1.Price) + } + return nil +} +func (this *CurrentPriceResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*CurrentPriceResponse) + if !ok { + that2, ok := that.(CurrentPriceResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.MarketID != that1.MarketID { + return false + } + if !this.Price.Equal(that1.Price) { + return false + } + return true +} +func (this *MarketResponse) VerboseEqual(that interface{}) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } + + that1, ok := that.(*MarketResponse) + if !ok { + that2, ok := that.(MarketResponse) + if ok { + that1 = &that2 + } else { + return fmt.Errorf("that is not of type *MarketResponse") + } + } + if that1 == nil { + if this == nil { + return nil + } + return fmt.Errorf("that is type *MarketResponse but is nil && this != nil") + } else if this == nil { + return fmt.Errorf("that is type *MarketResponse but is not nil && this == nil") + } + if this.MarketID != that1.MarketID { + return fmt.Errorf("MarketID this(%v) Not Equal that(%v)", this.MarketID, that1.MarketID) + } + if this.BaseAsset != that1.BaseAsset { + return fmt.Errorf("BaseAsset this(%v) Not Equal that(%v)", this.BaseAsset, that1.BaseAsset) + } + if this.QuoteAsset != that1.QuoteAsset { + return fmt.Errorf("QuoteAsset this(%v) Not Equal that(%v)", this.QuoteAsset, that1.QuoteAsset) + } + if len(this.Oracles) != len(that1.Oracles) { + return fmt.Errorf("Oracles this(%v) Not Equal that(%v)", len(this.Oracles), len(that1.Oracles)) + } + for i := range this.Oracles { + if this.Oracles[i] != that1.Oracles[i] { + return fmt.Errorf("Oracles this[%v](%v) Not Equal that[%v](%v)", i, this.Oracles[i], i, that1.Oracles[i]) + } + } + if this.Active != that1.Active { + return fmt.Errorf("Active this(%v) Not Equal that(%v)", this.Active, that1.Active) + } + return nil +} +func (this *MarketResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MarketResponse) + if !ok { + that2, ok := that.(MarketResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.MarketID != that1.MarketID { + return false + } + if this.BaseAsset != that1.BaseAsset { + return false + } + if this.QuoteAsset != that1.QuoteAsset { + return false + } + if len(this.Oracles) != len(that1.Oracles) { + return false + } + for i := range this.Oracles { + if this.Oracles[i] != that1.Oracles[i] { + return false + } + } + if this.Active != that1.Active { + return false + } + return true +} // Reference imports to suppress errors if they are not otherwise used. var _ context.Context @@ -1862,6 +2291,164 @@ func (m *QueryMarketsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *PostedPriceResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PostedPriceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PostedPriceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Expiry, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Expiry):]) + if err3 != nil { + return 0, err3 + } + i -= n3 + i = encodeVarintQuery(dAtA, i, uint64(n3)) + i-- + dAtA[i] = 0x22 + { + size := m.Price.Size() + i -= size + if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.OracleAddress) > 0 { + i -= len(m.OracleAddress) + copy(dAtA[i:], m.OracleAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.OracleAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.MarketID) > 0 { + i -= len(m.MarketID) + copy(dAtA[i:], m.MarketID) + i = encodeVarintQuery(dAtA, i, uint64(len(m.MarketID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *CurrentPriceResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CurrentPriceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CurrentPriceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Price.Size() + i -= size + if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.MarketID) > 0 { + i -= len(m.MarketID) + copy(dAtA[i:], m.MarketID) + i = encodeVarintQuery(dAtA, i, uint64(len(m.MarketID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MarketResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MarketResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MarketResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Active { + i-- + if m.Active { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + if len(m.Oracles) > 0 { + for iNdEx := len(m.Oracles) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Oracles[iNdEx]) + copy(dAtA[i:], m.Oracles[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Oracles[iNdEx]))) + i-- + dAtA[i] = 0x22 + } + } + if len(m.QuoteAsset) > 0 { + i -= len(m.QuoteAsset) + copy(dAtA[i:], m.QuoteAsset) + i = encodeVarintQuery(dAtA, i, uint64(len(m.QuoteAsset))) + i-- + dAtA[i] = 0x1a + } + if len(m.BaseAsset) > 0 { + i -= len(m.BaseAsset) + copy(dAtA[i:], m.BaseAsset) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BaseAsset))) + i-- + dAtA[i] = 0x12 + } + if len(m.MarketID) > 0 { + i -= len(m.MarketID) + copy(dAtA[i:], m.MarketID) + i = encodeVarintQuery(dAtA, i, uint64(len(m.MarketID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -2021,6 +2608,72 @@ func (m *QueryMarketsResponse) Size() (n int) { return n } +func (m *PostedPriceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MarketID) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.OracleAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = m.Price.Size() + n += 1 + l + sovQuery(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Expiry) + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *CurrentPriceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MarketID) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = m.Price.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *MarketResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MarketID) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.BaseAsset) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.QuoteAsset) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if len(m.Oracles) > 0 { + for _, s := range m.Oracles { + l = len(s) + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Active { + n += 2 + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2433,7 +3086,7 @@ func (m *QueryPricesResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Prices = append(m.Prices, CurrentPrice{}) + m.Prices = append(m.Prices, CurrentPriceResponse{}) if err := m.Prices[len(m.Prices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -2599,7 +3252,7 @@ func (m *QueryRawPricesResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.RawPrices = append(m.RawPrices, PostedPrice{}) + m.RawPrices = append(m.RawPrices, PostedPriceResponse{}) if err := m.RawPrices[len(m.RawPrices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -2897,7 +3550,7 @@ func (m *QueryMarketsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Markets = append(m.Markets, Market{}) + m.Markets = append(m.Markets, MarketResponse{}) if err := m.Markets[len(m.Markets)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -2923,6 +3576,501 @@ func (m *QueryMarketsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *PostedPriceResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PostedPriceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PostedPriceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MarketID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MarketID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OracleAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OracleAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Price.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Expiry", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Expiry, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CurrentPriceResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CurrentPriceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CurrentPriceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MarketID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MarketID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Price.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MarketResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MarketResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MarketResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MarketID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MarketID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseAsset", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BaseAsset = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteAsset", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QuoteAsset = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Oracles", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Oracles = append(m.Oracles, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Active", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Active = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/pricefeed/types/pricefeed.pb.go b/x/pricefeed/types/store.pb.go similarity index 61% rename from x/pricefeed/types/pricefeed.pb.go rename to x/pricefeed/types/store.pb.go index bf97fdb498..654c7e048e 100644 --- a/x/pricefeed/types/pricefeed.pb.go +++ b/x/pricefeed/types/store.pb.go @@ -1,10 +1,12 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: kava/pricefeed/v1beta1/pricefeed.proto +// source: kava/pricefeed/v1beta1/store.proto package types import ( + bytes "bytes" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" @@ -28,19 +30,65 @@ var _ = time.Kitchen // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// Params defines the parameters for the pricefeed module. +type Params struct { + Markets Markets `protobuf:"bytes,1,rep,name=markets,proto3,castrepeated=Markets" json:"markets"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_9df40639f5e16f9a, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMarkets() Markets { + if m != nil { + return m.Markets + } + return nil +} + // Market defines an asset in the pricefeed. type Market struct { - MarketID string `protobuf:"bytes,1,opt,name=market_id,json=marketId,proto3" json:"market_id,omitempty"` - BaseAsset string `protobuf:"bytes,2,opt,name=base_asset,json=baseAsset,proto3" json:"base_asset,omitempty"` - QuoteAsset string `protobuf:"bytes,3,opt,name=quote_asset,json=quoteAsset,proto3" json:"quote_asset,omitempty"` - Oracles []string `protobuf:"bytes,4,rep,name=oracles,proto3" json:"oracles,omitempty"` - Active bool `protobuf:"varint,5,opt,name=active,proto3" json:"active,omitempty"` + MarketID string `protobuf:"bytes,1,opt,name=market_id,json=marketId,proto3" json:"market_id,omitempty"` + BaseAsset string `protobuf:"bytes,2,opt,name=base_asset,json=baseAsset,proto3" json:"base_asset,omitempty"` + QuoteAsset string `protobuf:"bytes,3,opt,name=quote_asset,json=quoteAsset,proto3" json:"quote_asset,omitempty"` + Oracles []github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,4,rep,name=oracles,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"oracles,omitempty"` + Active bool `protobuf:"varint,5,opt,name=active,proto3" json:"active,omitempty"` } -func (m *Market) Reset() { *m = Market{} } -func (*Market) ProtoMessage() {} +func (m *Market) Reset() { *m = Market{} } +func (m *Market) String() string { return proto.CompactTextString(m) } +func (*Market) ProtoMessage() {} func (*Market) Descriptor() ([]byte, []int) { - return fileDescriptor_188809b7a903b86f, []int{0} + return fileDescriptor_9df40639f5e16f9a, []int{1} } func (m *Market) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -90,7 +138,7 @@ func (m *Market) GetQuoteAsset() string { return "" } -func (m *Market) GetOracles() []string { +func (m *Market) GetOracles() []github_com_cosmos_cosmos_sdk_types.AccAddress { if m != nil { return m.Oracles } @@ -106,16 +154,17 @@ func (m *Market) GetActive() bool { // PostedPrice defines a price for market posted by a specific oracle. type PostedPrice struct { - MarketID string `protobuf:"bytes,1,opt,name=market_id,json=marketId,proto3" json:"market_id,omitempty"` - OracleAddress string `protobuf:"bytes,2,opt,name=oracle_address,json=oracleAddress,proto3" json:"oracle_address,omitempty"` - Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price"` - Expiry time.Time `protobuf:"bytes,4,opt,name=expiry,proto3,stdtime" json:"expiry"` + MarketID string `protobuf:"bytes,1,opt,name=market_id,json=marketId,proto3" json:"market_id,omitempty"` + OracleAddress github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,2,opt,name=oracle_address,json=oracleAddress,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"oracle_address,omitempty"` + Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price"` + Expiry time.Time `protobuf:"bytes,4,opt,name=expiry,proto3,stdtime" json:"expiry"` } -func (m *PostedPrice) Reset() { *m = PostedPrice{} } -func (*PostedPrice) ProtoMessage() {} +func (m *PostedPrice) Reset() { *m = PostedPrice{} } +func (m *PostedPrice) String() string { return proto.CompactTextString(m) } +func (*PostedPrice) ProtoMessage() {} func (*PostedPrice) Descriptor() ([]byte, []int) { - return fileDescriptor_188809b7a903b86f, []int{1} + return fileDescriptor_9df40639f5e16f9a, []int{2} } func (m *PostedPrice) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -151,11 +200,11 @@ func (m *PostedPrice) GetMarketID() string { return "" } -func (m *PostedPrice) GetOracleAddress() string { +func (m *PostedPrice) GetOracleAddress() github_com_cosmos_cosmos_sdk_types.AccAddress { if m != nil { return m.OracleAddress } - return "" + return nil } func (m *PostedPrice) GetExpiry() time.Time { @@ -172,10 +221,11 @@ type CurrentPrice struct { Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price"` } -func (m *CurrentPrice) Reset() { *m = CurrentPrice{} } -func (*CurrentPrice) ProtoMessage() {} +func (m *CurrentPrice) Reset() { *m = CurrentPrice{} } +func (m *CurrentPrice) String() string { return proto.CompactTextString(m) } +func (*CurrentPrice) ProtoMessage() {} func (*CurrentPrice) Descriptor() ([]byte, []int) { - return fileDescriptor_188809b7a903b86f, []int{2} + return fileDescriptor_9df40639f5e16f9a, []int{3} } func (m *CurrentPrice) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -212,47 +262,116 @@ func (m *CurrentPrice) GetMarketID() string { } func init() { + proto.RegisterType((*Params)(nil), "kava.pricefeed.v1beta1.Params") proto.RegisterType((*Market)(nil), "kava.pricefeed.v1beta1.Market") proto.RegisterType((*PostedPrice)(nil), "kava.pricefeed.v1beta1.PostedPrice") proto.RegisterType((*CurrentPrice)(nil), "kava.pricefeed.v1beta1.CurrentPrice") } func init() { - proto.RegisterFile("kava/pricefeed/v1beta1/pricefeed.proto", fileDescriptor_188809b7a903b86f) + proto.RegisterFile("kava/pricefeed/v1beta1/store.proto", fileDescriptor_9df40639f5e16f9a) } -var fileDescriptor_188809b7a903b86f = []byte{ - // 440 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x52, 0x31, 0x6f, 0x13, 0x31, - 0x14, 0x3e, 0xb7, 0x69, 0x48, 0x9c, 0xc2, 0x70, 0x42, 0xd5, 0x29, 0x12, 0xbe, 0xa8, 0x12, 0x55, - 0x10, 0xaa, 0xad, 0xc2, 0x86, 0x58, 0x1a, 0xb2, 0x74, 0xa8, 0x54, 0x9d, 0x98, 0x58, 0x22, 0xdf, - 0xdd, 0xeb, 0x71, 0x4a, 0x0e, 0x1f, 0xb6, 0x2f, 0x6a, 0x7f, 0x00, 0x7b, 0x47, 0x46, 0x46, 0x24, - 0xfe, 0x48, 0xc7, 0x8e, 0x88, 0x21, 0x94, 0xcb, 0xc4, 0xbf, 0x40, 0xb6, 0xef, 0x68, 0xd7, 0xa8, - 0x93, 0xdf, 0xfb, 0xde, 0x67, 0xfb, 0xfb, 0xde, 0x7b, 0xf8, 0x60, 0xce, 0x97, 0x9c, 0x95, 0x32, - 0x4f, 0xe0, 0x1c, 0x20, 0x65, 0xcb, 0xa3, 0x18, 0x34, 0x3f, 0xba, 0x43, 0x68, 0x29, 0x85, 0x16, - 0xfe, 0x9e, 0xe1, 0xd1, 0x3b, 0xb4, 0xe1, 0x0d, 0x9f, 0x66, 0x22, 0x13, 0x96, 0xc2, 0x4c, 0xe4, - 0xd8, 0xc3, 0x30, 0x13, 0x22, 0x5b, 0x00, 0xb3, 0x59, 0x5c, 0x9d, 0x33, 0x9d, 0x17, 0xa0, 0x34, - 0x2f, 0x4a, 0x47, 0xd8, 0xff, 0x81, 0x70, 0xf7, 0x94, 0xcb, 0x39, 0x68, 0xff, 0x05, 0xee, 0x17, - 0x36, 0x9a, 0xe5, 0x69, 0x80, 0x46, 0x68, 0xdc, 0x9f, 0xec, 0xd6, 0xab, 0xb0, 0xe7, 0xca, 0x27, - 0xd3, 0xa8, 0xe7, 0xca, 0x27, 0xa9, 0xff, 0x0c, 0xe3, 0x98, 0x2b, 0x98, 0x71, 0xa5, 0x40, 0x07, - 0x5b, 0x86, 0x1b, 0xf5, 0x0d, 0x72, 0x6c, 0x00, 0x3f, 0xc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a, 0xa0, - 0xeb, 0x9a, 0xa0, 0x9b, 0x9a, 0xa0, 0xdb, 0x9a, 0xa0, 0xab, 0x35, 0xf1, 0x6e, 0xd6, 0xc4, 0xfb, - 0xb9, 0x26, 0xde, 0x87, 0x97, 0xf7, 0x9e, 0x35, 0xdb, 0x79, 0xb8, 0xe0, 0xb1, 0xb2, 0x11, 0xbb, - 0xb8, 0xb7, 0xd1, 0xf6, 0xfd, 0xb8, 0x6b, 0x5b, 0xf0, 0xfa, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x0f, 0x37, 0x52, 0xc9, 0xf0, 0x02, 0x00, 0x00, +var fileDescriptor_9df40639f5e16f9a = []byte{ + // 508 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0x3f, 0x6f, 0xd3, 0x40, + 0x14, 0xcf, 0x25, 0x6d, 0xfe, 0x5c, 0x02, 0x48, 0x06, 0x55, 0x26, 0x12, 0x76, 0x94, 0x01, 0x19, + 0xa1, 0x9c, 0xd5, 0xb2, 0xb2, 0xc4, 0x64, 0x20, 0x43, 0xa5, 0xc8, 0x30, 0xb1, 0x44, 0x67, 0xfb, + 0xd5, 0x58, 0x89, 0x39, 0x73, 0x77, 0x89, 0x9a, 0x89, 0xaf, 0xd0, 0x8f, 0x81, 0x90, 0xd8, 0xf8, + 0x10, 0x1d, 0x2b, 0x26, 0xc4, 0x90, 0x16, 0xe7, 0x03, 0xb0, 0x33, 0x21, 0xdf, 0xd9, 0x55, 0x07, + 0x06, 0x2a, 0x98, 0xee, 0xde, 0xef, 0xfd, 0xde, 0xbf, 0xdf, 0xbd, 0xc3, 0xc3, 0x05, 0x5d, 0x53, + 0x37, 0xe3, 0x49, 0x08, 0x27, 0x00, 0x91, 0xbb, 0x3e, 0x0c, 0x40, 0xd2, 0x43, 0x57, 0x48, 0xc6, + 0x81, 0x64, 0x9c, 0x49, 0x66, 0x1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x20, 0xd4, 0xcd, 0x3d, 0xbd, 0xf1, 0x7d, 0x55, 0xe6, 0xa0, 0xa9, 0xa6, 0x7e, 0xf6, 0x3b, + 0x00, 0x00, 0xff, 0xff, 0x18, 0xb5, 0x5b, 0xc1, 0xdd, 0x03, 0x00, 0x00, } +func (this *Params) VerboseEqual(that interface{}) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return fmt.Errorf("that is not of type *Params") + } + } + if that1 == nil { + if this == nil { + return nil + } + return fmt.Errorf("that is type *Params but is nil && this != nil") + } else if this == nil { + return fmt.Errorf("that is type *Params but is not nil && this == nil") + } + if len(this.Markets) != len(that1.Markets) { + return fmt.Errorf("Markets this(%v) Not Equal that(%v)", len(this.Markets), len(that1.Markets)) + } + for i := range this.Markets { + if !this.Markets[i].Equal(&that1.Markets[i]) { + return fmt.Errorf("Markets this[%v](%v) Not Equal that[%v](%v)", i, this.Markets[i], i, that1.Markets[i]) + } + } + return nil +} +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Markets) != len(that1.Markets) { + return false + } + for i := range this.Markets { + if !this.Markets[i].Equal(&that1.Markets[i]) { + return false + } + } + return true +} func (this *Market) VerboseEqual(that interface{}) error { if that == nil { if this == nil { @@ -291,7 +410,7 @@ func (this *Market) VerboseEqual(that interface{}) error { return fmt.Errorf("Oracles this(%v) Not Equal that(%v)", len(this.Oracles), len(that1.Oracles)) } for i := range this.Oracles { - if this.Oracles[i] != that1.Oracles[i] { + if !bytes.Equal(this.Oracles[i], that1.Oracles[i]) { return fmt.Errorf("Oracles this[%v](%v) Not Equal that[%v](%v)", i, this.Oracles[i], i, that1.Oracles[i]) } } @@ -332,7 +451,7 @@ func (this *Market) Equal(that interface{}) bool { return false } for i := range this.Oracles { - if this.Oracles[i] != that1.Oracles[i] { + if !bytes.Equal(this.Oracles[i], that1.Oracles[i]) { return false } } @@ -369,7 +488,7 @@ func (this *PostedPrice) VerboseEqual(that interface{}) error { if this.MarketID != that1.MarketID { return fmt.Errorf("MarketID this(%v) Not Equal that(%v)", this.MarketID, that1.MarketID) } - if this.OracleAddress != that1.OracleAddress { + if !bytes.Equal(this.OracleAddress, that1.OracleAddress) { return fmt.Errorf("OracleAddress this(%v) Not Equal that(%v)", this.OracleAddress, that1.OracleAddress) } if !this.Price.Equal(that1.Price) { @@ -402,7 +521,7 @@ func (this *PostedPrice) Equal(that interface{}) bool { if this.MarketID != that1.MarketID { return false } - if this.OracleAddress != that1.OracleAddress { + if !bytes.Equal(this.OracleAddress, that1.OracleAddress) { return false } if !this.Price.Equal(that1.Price) { @@ -473,6 +592,43 @@ func (this *CurrentPrice) Equal(that interface{}) bool { } return true } +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Markets) > 0 { + for iNdEx := len(m.Markets) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Markets[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintStore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func (m *Market) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -507,7 +663,7 @@ func (m *Market) MarshalToSizedBuffer(dAtA []byte) (int, error) { for iNdEx := len(m.Oracles) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.Oracles[iNdEx]) copy(dAtA[i:], m.Oracles[iNdEx]) - i = encodeVarintPricefeed(dAtA, i, uint64(len(m.Oracles[iNdEx]))) + i = encodeVarintStore(dAtA, i, uint64(len(m.Oracles[iNdEx]))) i-- dAtA[i] = 0x22 } @@ -515,21 +671,21 @@ func (m *Market) MarshalToSizedBuffer(dAtA []byte) (int, error) { if len(m.QuoteAsset) > 0 { i -= len(m.QuoteAsset) copy(dAtA[i:], m.QuoteAsset) - i = encodeVarintPricefeed(dAtA, i, uint64(len(m.QuoteAsset))) + i = encodeVarintStore(dAtA, i, uint64(len(m.QuoteAsset))) i-- dAtA[i] = 0x1a } if len(m.BaseAsset) > 0 { i -= len(m.BaseAsset) copy(dAtA[i:], m.BaseAsset) - i = encodeVarintPricefeed(dAtA, i, uint64(len(m.BaseAsset))) + i = encodeVarintStore(dAtA, i, uint64(len(m.BaseAsset))) i-- dAtA[i] = 0x12 } if len(m.MarketID) > 0 { i -= len(m.MarketID) copy(dAtA[i:], m.MarketID) - i = encodeVarintPricefeed(dAtA, i, uint64(len(m.MarketID))) + i = encodeVarintStore(dAtA, i, uint64(len(m.MarketID))) i-- dAtA[i] = 0xa } @@ -561,7 +717,7 @@ func (m *PostedPrice) MarshalToSizedBuffer(dAtA []byte) (int, error) { return 0, err1 } i -= n1 - i = encodeVarintPricefeed(dAtA, i, uint64(n1)) + i = encodeVarintStore(dAtA, i, uint64(n1)) i-- dAtA[i] = 0x22 { @@ -570,21 +726,21 @@ func (m *PostedPrice) MarshalToSizedBuffer(dAtA []byte) (int, error) { if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { return 0, err } - i = encodeVarintPricefeed(dAtA, i, uint64(size)) + i = encodeVarintStore(dAtA, i, uint64(size)) } i-- dAtA[i] = 0x1a if len(m.OracleAddress) > 0 { i -= len(m.OracleAddress) copy(dAtA[i:], m.OracleAddress) - i = encodeVarintPricefeed(dAtA, i, uint64(len(m.OracleAddress))) + i = encodeVarintStore(dAtA, i, uint64(len(m.OracleAddress))) i-- dAtA[i] = 0x12 } if len(m.MarketID) > 0 { i -= len(m.MarketID) copy(dAtA[i:], m.MarketID) - i = encodeVarintPricefeed(dAtA, i, uint64(len(m.MarketID))) + i = encodeVarintStore(dAtA, i, uint64(len(m.MarketID))) i-- dAtA[i] = 0xa } @@ -617,22 +773,22 @@ func (m *CurrentPrice) MarshalToSizedBuffer(dAtA []byte) (int, error) { if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { return 0, err } - i = encodeVarintPricefeed(dAtA, i, uint64(size)) + i = encodeVarintStore(dAtA, i, uint64(size)) } i-- dAtA[i] = 0x12 if len(m.MarketID) > 0 { i -= len(m.MarketID) copy(dAtA[i:], m.MarketID) - i = encodeVarintPricefeed(dAtA, i, uint64(len(m.MarketID))) + i = encodeVarintStore(dAtA, i, uint64(len(m.MarketID))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarintPricefeed(dAtA []byte, offset int, v uint64) int { - offset -= sovPricefeed(v) +func encodeVarintStore(dAtA []byte, offset int, v uint64) int { + offset -= sovStore(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -642,6 +798,21 @@ func encodeVarintPricefeed(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Markets) > 0 { + for _, e := range m.Markets { + l = e.Size() + n += 1 + l + sovStore(uint64(l)) + } + } + return n +} + func (m *Market) Size() (n int) { if m == nil { return 0 @@ -650,20 +821,20 @@ func (m *Market) Size() (n int) { _ = l l = len(m.MarketID) if l > 0 { - n += 1 + l + sovPricefeed(uint64(l)) + n += 1 + l + sovStore(uint64(l)) } l = len(m.BaseAsset) if l > 0 { - n += 1 + l + sovPricefeed(uint64(l)) + n += 1 + l + sovStore(uint64(l)) } l = len(m.QuoteAsset) if l > 0 { - n += 1 + l + sovPricefeed(uint64(l)) + n += 1 + l + sovStore(uint64(l)) } if len(m.Oracles) > 0 { - for _, s := range m.Oracles { - l = len(s) - n += 1 + l + sovPricefeed(uint64(l)) + for _, b := range m.Oracles { + l = len(b) + n += 1 + l + sovStore(uint64(l)) } } if m.Active { @@ -680,16 +851,16 @@ func (m *PostedPrice) Size() (n int) { _ = l l = len(m.MarketID) if l > 0 { - n += 1 + l + sovPricefeed(uint64(l)) + n += 1 + l + sovStore(uint64(l)) } l = len(m.OracleAddress) if l > 0 { - n += 1 + l + sovPricefeed(uint64(l)) + n += 1 + l + sovStore(uint64(l)) } l = m.Price.Size() - n += 1 + l + sovPricefeed(uint64(l)) + n += 1 + l + sovStore(uint64(l)) l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Expiry) - n += 1 + l + sovPricefeed(uint64(l)) + n += 1 + l + sovStore(uint64(l)) return n } @@ -701,18 +872,102 @@ func (m *CurrentPrice) Size() (n int) { _ = l l = len(m.MarketID) if l > 0 { - n += 1 + l + sovPricefeed(uint64(l)) + n += 1 + l + sovStore(uint64(l)) } l = m.Price.Size() - n += 1 + l + sovPricefeed(uint64(l)) + n += 1 + l + sovStore(uint64(l)) return n } -func sovPricefeed(x uint64) (n int) { +func sovStore(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozPricefeed(x uint64) (n int) { - return sovPricefeed(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozStore(x uint64) (n int) { + return sovStore(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Markets", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthStore + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthStore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Markets = append(m.Markets, Market{}) + if err := m.Markets[len(m.Markets)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipStore(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthStore + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil } func (m *Market) Unmarshal(dAtA []byte) error { l := len(dAtA) @@ -722,7 +977,7 @@ func (m *Market) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -750,7 +1005,7 @@ func (m *Market) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -764,11 +1019,11 @@ func (m *Market) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if postIndex > l { return io.ErrUnexpectedEOF @@ -782,7 +1037,7 @@ func (m *Market) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -796,11 +1051,11 @@ func (m *Market) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if postIndex > l { return io.ErrUnexpectedEOF @@ -814,7 +1069,7 @@ func (m *Market) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -828,11 +1083,11 @@ func (m *Market) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if postIndex > l { return io.ErrUnexpectedEOF @@ -843,33 +1098,33 @@ func (m *Market) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Oracles", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthPricefeed + if byteLen < 0 { + return ErrInvalidLengthStore } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if postIndex > l { return io.ErrUnexpectedEOF } - m.Oracles = append(m.Oracles, string(dAtA[iNdEx:postIndex])) + m.Oracles = append(m.Oracles, make([]byte, postIndex-iNdEx)) + copy(m.Oracles[len(m.Oracles)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex case 5: if wireType != 0 { @@ -878,7 +1133,7 @@ func (m *Market) Unmarshal(dAtA []byte) error { var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -893,12 +1148,12 @@ func (m *Market) Unmarshal(dAtA []byte) error { m.Active = bool(v != 0) default: iNdEx = preIndex - skippy, err := skipPricefeed(dAtA[iNdEx:]) + skippy, err := skipStore(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -920,7 +1175,7 @@ func (m *PostedPrice) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -948,7 +1203,7 @@ func (m *PostedPrice) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -962,11 +1217,11 @@ func (m *PostedPrice) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if postIndex > l { return io.ErrUnexpectedEOF @@ -977,33 +1232,35 @@ func (m *PostedPrice) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field OracleAddress", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthPricefeed + if byteLen < 0 { + return ErrInvalidLengthStore } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if postIndex > l { return io.ErrUnexpectedEOF } - m.OracleAddress = string(dAtA[iNdEx:postIndex]) + m.OracleAddress = append(m.OracleAddress[:0], dAtA[iNdEx:postIndex]...) + if m.OracleAddress == nil { + m.OracleAddress = []byte{} + } iNdEx = postIndex case 3: if wireType != 2 { @@ -1012,7 +1269,7 @@ func (m *PostedPrice) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1026,11 +1283,11 @@ func (m *PostedPrice) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if postIndex > l { return io.ErrUnexpectedEOF @@ -1046,7 +1303,7 @@ func (m *PostedPrice) Unmarshal(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1059,11 +1316,11 @@ func (m *PostedPrice) Unmarshal(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if postIndex > l { return io.ErrUnexpectedEOF @@ -1074,12 +1331,12 @@ func (m *PostedPrice) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipPricefeed(dAtA[iNdEx:]) + skippy, err := skipStore(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1101,7 +1358,7 @@ func (m *CurrentPrice) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1129,7 +1386,7 @@ func (m *CurrentPrice) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1143,11 +1400,11 @@ func (m *CurrentPrice) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if postIndex > l { return io.ErrUnexpectedEOF @@ -1161,7 +1418,7 @@ func (m *CurrentPrice) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPricefeed + return ErrIntOverflowStore } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1175,11 +1432,11 @@ func (m *CurrentPrice) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if postIndex > l { return io.ErrUnexpectedEOF @@ -1190,12 +1447,12 @@ func (m *CurrentPrice) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipPricefeed(dAtA[iNdEx:]) + skippy, err := skipStore(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPricefeed + return ErrInvalidLengthStore } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1209,7 +1466,7 @@ func (m *CurrentPrice) Unmarshal(dAtA []byte) error { } return nil } -func skipPricefeed(dAtA []byte) (n int, err error) { +func skipStore(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -1217,7 +1474,7 @@ func skipPricefeed(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowPricefeed + return 0, ErrIntOverflowStore } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1234,7 +1491,7 @@ func skipPricefeed(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowPricefeed + return 0, ErrIntOverflowStore } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1250,7 +1507,7 @@ func skipPricefeed(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowPricefeed + return 0, ErrIntOverflowStore } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1263,14 +1520,14 @@ func skipPricefeed(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthPricefeed + return 0, ErrInvalidLengthStore } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupPricefeed + return 0, ErrUnexpectedEndOfGroupStore } depth-- case 5: @@ -1279,7 +1536,7 @@ func skipPricefeed(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthPricefeed + return 0, ErrInvalidLengthStore } if depth == 0 { return iNdEx, nil @@ -1289,7 +1546,7 @@ func skipPricefeed(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthPricefeed = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowPricefeed = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupPricefeed = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthStore = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowStore = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupStore = fmt.Errorf("proto: unexpected end of group") )