Skip to content

Commit 422a21c

Browse files
committed
add current prices
1 parent 443d110 commit 422a21c

File tree

7 files changed

+566
-94
lines changed

7 files changed

+566
-94
lines changed

proto/feeds/v1beta1/query.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ service Query {
1717
option (google.api.http).get = "/feeds/v1beta1/current-feeds";
1818
}
1919

20+
// CurrentPrices is an RPC method that returns a list of current prices.
21+
rpc CurrentPrices(QueryCurrentPricesRequest) returns (QueryCurrentPricesResponse) {
22+
option (google.api.http).get = "/feeds/v1beta1/current-prices";
23+
}
24+
2025
// DelegatorSignals is an RPC method that returns signals of a delegator.
2126
rpc DelegatorSignals(QueryDelegatorSignalsRequest) returns (QueryDelegatorSignalsResponse) {
2227
option (google.api.http).get = "/feeds/v1beta1/delegators/{delegator_address}/signals";
@@ -73,6 +78,15 @@ message QueryCurrentFeedsResponse {
7378
CurrentFeedWithDeviations current_feeds = 1 [(gogoproto.nullable) = false];
7479
}
7580

81+
// QueryCurrentPricesRequest is the request type for the Query/CurrentPrices RPC method.
82+
message QueryCurrentPricesRequest {}
83+
84+
// QueryCurrentPricesResponse is the response type for the Query/CurrentPrices RPC method.
85+
message QueryCurrentPricesResponse {
86+
// prices is a list of current prices.
87+
repeated Price prices = 1 [(gogoproto.nullable) = false];
88+
}
89+
7690
// QueryDelegatorSignalsRequest is the request type for the Query/DelegatorSignals RPC method.
7791
message QueryDelegatorSignalsRequest {
7892
// delegator_address is the delegator address to query signal for.

scripts/feeds/submit_signals.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ bandd tx staking delegate bandvaloper1p40yh3zkmhcv0ecqp3mcazy83sa57rgjde6wec 100
44
sleep 3
55

66
# signal
7-
bandd tx feeds signal crypto_price.ethusd:30000000000 crypto_price.usdtusd:30000000000 --from validator --keyring-backend test --gas-prices 0.0025uband -y --chain-id bandchain
8-
bandd tx feeds signal crypto_price.ethusd:30000000000 crypto_price.usdtusd:29000000000 --from requester --keyring-backend test --gas-prices 0.0025uband -y --chain-id bandchain
7+
bandd tx feeds signal crypto_price.btcusd,30000000000 crypto_price.usdtusd,30000000000 --from validator --keyring-backend test --gas-prices 0.0025uband -y --chain-id bandchain
8+
bandd tx feeds signal crypto_price.btcusd,30000000000 crypto_price.usdtusd,29000000000 --from requester --keyring-backend test --gas-prices 0.0025uband -y --chain-id bandchain

x/feeds/client/cli/query.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func GetQueryCmd() *cobra.Command {
3131
GetQueryCmdReferenceSourceConfig(),
3232
GetQueryCmdDelegatorSignals(),
3333
GetQueryCmdCurrentFeeds(),
34+
GetQueryCmdCurrentPrices(),
3435
GetQueryCmdIsFeeder(),
3536
)
3637

@@ -144,6 +145,30 @@ func GetQueryCmdCurrentFeeds() *cobra.Command {
144145
return cmd
145146
}
146147

148+
// GetQueryCmdCurrentPrices implements the query current prices command.
149+
func GetQueryCmdCurrentPrices() *cobra.Command {
150+
cmd := &cobra.Command{
151+
Use: "current-prices",
152+
Short: "Shows all current prices of all supported feeds",
153+
Args: cobra.NoArgs,
154+
RunE: func(cmd *cobra.Command, args []string) error {
155+
clientCtx := client.GetClientContextFromCmd(cmd)
156+
queryClient := types.NewQueryClient(clientCtx)
157+
158+
res, err := queryClient.CurrentPrices(context.Background(), &types.QueryCurrentPricesRequest{})
159+
if err != nil {
160+
return err
161+
}
162+
163+
return clientCtx.PrintProto(res)
164+
},
165+
}
166+
167+
flags.AddQueryFlagsToCmd(cmd)
168+
169+
return cmd
170+
}
171+
147172
// GetQueryCmdValidatorPrices implements the query validator prices command.
148173
func GetQueryCmdValidatorPrices() *cobra.Command {
149174
cmd := &cobra.Command{

x/feeds/keeper/grpc_query.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ func (q queryServer) CurrentFeeds(
253253
}, nil
254254
}
255255

256+
// CurrentPrices queries all current prices.
257+
func (q queryServer) CurrentPrices(
258+
goCtx context.Context, _ *types.QueryCurrentPricesRequest,
259+
) (*types.QueryCurrentPricesResponse, error) {
260+
ctx := sdk.UnwrapSDKContext(goCtx)
261+
262+
currentPrices := q.keeper.GetCurrentPrices(ctx)
263+
return &types.QueryCurrentPricesResponse{Prices: currentPrices}, nil
264+
}
265+
256266
// ReferenceSourceConfig queries current reference source config.
257267
func (q queryServer) ReferenceSourceConfig(
258268
goCtx context.Context, _ *types.QueryReferenceSourceConfigRequest,

x/feeds/keeper/keeper_price.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,22 @@ func (k Keeper) GetPrices(ctx sdk.Context) (prices []types.Price) {
2626
prices = append(prices, price)
2727
}
2828

29-
return prices
29+
return
30+
}
31+
32+
// GetCurrentPrices returns a list of all current prices.
33+
func (k Keeper) GetCurrentPrices(ctx sdk.Context) (prices []types.Price) {
34+
currentFeeds := k.GetCurrentFeeds(ctx)
35+
for _, feed := range currentFeeds.Feeds {
36+
price, err := k.GetPrice(ctx, feed.SignalID)
37+
if err != nil {
38+
continue
39+
}
40+
41+
prices = append(prices, price)
42+
}
43+
44+
return
3045
}
3146

3247
// GetPrice returns a price by signal id.

0 commit comments

Comments
 (0)