Skip to content

Commit e2f736c

Browse files
authored
[Feeds] add isFeeder query (#167)
* add isFeeder query * fix comment * fix from comments
1 parent 19cbea3 commit e2f736c

File tree

10 files changed

+730
-119
lines changed

10 files changed

+730
-119
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
cosmossdk.io/api v0.3.1
77
cosmossdk.io/errors v1.0.1
88
cosmossdk.io/math v1.3.0
9-
github.com/bandprotocol/bothan/bothan-api/client/go-client v0.0.1
9+
github.com/bandprotocol/bothan/bothan-api/client/go-client v0.0.1-alpha.1
1010
github.com/bandprotocol/go-owasm v0.3.1
1111
github.com/bytecodealliance/wasmtime-go/v20 v20.0.0
1212
github.com/cometbft/cometbft v0.37.5
@@ -23,7 +23,7 @@ require (
2323
github.com/gorilla/mux v1.8.1
2424
github.com/grpc-ecosystem/grpc-gateway v1.16.0
2525
github.com/kyokomi/emoji v2.2.4+incompatible
26-
github.com/levigross/grequests v0.0.0-20190908174114-253788527a1a
26+
github.com/levigross/grequests v0.0.0-20231203190023-9c307ef1f48d
2727
github.com/oasisprotocol/oasis-core/go v0.2202.7
2828
github.com/peterbourgon/diskv v2.0.1+incompatible
2929
github.com/prometheus/client_golang v1.14.0
@@ -105,7 +105,7 @@ require (
105105
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
106106
github.com/google/btree v1.1.2 // indirect
107107
github.com/google/go-cmp v0.6.0 // indirect
108-
github.com/google/go-querystring v1.0.0 // indirect
108+
github.com/google/go-querystring v1.1.0 // indirect
109109
github.com/google/orderedcode v0.0.1 // indirect
110110
github.com/google/s2a-go v0.1.7 // indirect
111111
github.com/google/uuid v1.6.0 // indirect

go.sum

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX
245245
github.com/aws/aws-sdk-go v1.44.203 h1:pcsP805b9acL3wUqa4JR2vg1k2wnItkDYNvfmcy6F+U=
246246
github.com/aws/aws-sdk-go v1.44.203/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
247247
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
248-
github.com/bandprotocol/bothan/bothan-api/client/go-client v0.0.1 h1:HN9170voxmCgJFiQ+H55IWRvMAU00J4Ru1MUw6WnmVQ=
249-
github.com/bandprotocol/bothan/bothan-api/client/go-client v0.0.1/go.mod h1:F2bQczJ5iqEJ8IEG8u/TbVz4PXgHGc3oWjNQv5S9z0A=
248+
github.com/bandprotocol/bothan/bothan-api/client/go-client v0.0.1-alpha.1 h1:fuKTvR9U63xeC/Ra4ziPMC0/K8KlNsygO5obHT4Pkhk=
249+
github.com/bandprotocol/bothan/bothan-api/client/go-client v0.0.1-alpha.1/go.mod h1:1rmnpKHjLxJ26zzcG8+v/L8AGXWR/bQm3s0qiB3t4L0=
250250
github.com/bandprotocol/go-owasm v0.3.1 h1:L38qAEmb0KyTICHBHJaBoo6yy5+BlbOzQeQ+ioUV5Uw=
251251
github.com/bandprotocol/go-owasm v0.3.1/go.mod h1:SAzGihlBl8eZDXA1dO2aeAZLm8J2QkNd+KvnA2Dw9Kg=
252252
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
@@ -560,8 +560,8 @@ github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
560560
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
561561
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
562562
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
563-
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
564-
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
563+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
564+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
565565
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
566566
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
567567
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
@@ -752,8 +752,8 @@ github.com/kyokomi/emoji v2.2.4+incompatible h1:np0woGKwx9LiHAQmwZx79Oc0rHpNw3o+
752752
github.com/kyokomi/emoji v2.2.4+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA=
753753
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
754754
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
755-
github.com/levigross/grequests v0.0.0-20190908174114-253788527a1a h1:DGFy/362j92vQRE3ThU1yqg9TuJS8YJOSbQuB7BP9cA=
756-
github.com/levigross/grequests v0.0.0-20190908174114-253788527a1a/go.mod h1:jVntzcUU+2BtVohZBQmSHWUmh8B55LCNfPhcNCIvvIg=
755+
github.com/levigross/grequests v0.0.0-20231203190023-9c307ef1f48d h1:8fVmm2qScPn4JAF/YdTtqrPP3n58FgZ4GbKTNfaPuRs=
756+
github.com/levigross/grequests v0.0.0-20231203190023-9c307ef1f48d/go.mod h1:dFu6nuJHC3u9kCDcyGrEL7LwhK2m6Mt+alyiiIjDrRY=
757757
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
758758
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
759759
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
@@ -1125,7 +1125,6 @@ golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
11251125
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
11261126
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
11271127
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
1128-
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
11291128
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
11301129
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
11311130
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

proto/feeds/v1beta1/query.proto

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,55 +12,60 @@ import "feeds/v1beta1/params.proto";
1212

1313
// Query defines the gRPC querier service.
1414
service Query {
15-
// Prices is a RPC method that returns all prices.
15+
// Prices is an RPC method that returns all prices.
1616
rpc Prices(QueryPricesRequest) returns (QueryPricesResponse) {
1717
option (google.api.http).get = "/feeds/v1beta1/prices";
1818
}
1919

20-
// Price is a RPC method that returns price by signal id.
20+
// Price is an RPC method that returns price by signal id.
2121
rpc Price(QueryPriceRequest) returns (QueryPriceResponse) {
2222
option (google.api.http).get = "/feeds/v1beta1/prices/{signal_id}";
2323
}
2424

25-
// ValidatorPrices is a RPC method that returns prices of a validator.
25+
// ValidatorPrices is an RPC method that returns prices of a validator.
2626
rpc ValidatorPrices(QueryValidatorPricesRequest) returns (QueryValidatorPricesResponse) {
2727
option (google.api.http).get = "/feeds/v1beta1/validators/{validator}/prices";
2828
}
2929

30-
// ValidatorPrice is a RPC method that returns price of validator by signal id.
30+
// ValidatorPrice is an RPC method that returns price of validator by signal id.
3131
rpc ValidatorPrice(QueryValidatorPriceRequest) returns (QueryValidatorPriceResponse) {
3232
option (google.api.http).get = "/feeds/v1beta1/prices/{signal_id}/validators/{validator}";
3333
}
3434

35-
// ValidValidator is a RPC method that returns flag to show if the validator is required to send prices.
35+
// ValidValidator is an RPC method that returns flag to show if the validator is required to send prices.
3636
rpc ValidValidator(QueryValidValidatorRequest) returns (QueryValidValidatorResponse) {
3737
option (google.api.http).get = "/feeds/v1beta1/validators/{validator}";
3838
}
3939

40-
// Signals is a RPC method that returns all signal-total-powers or specified signal-total-power by signal id.
40+
// Signals is an RPC method that returns all signal-total-powers or specified signal-total-power by signal id.
4141
rpc SignalTotalPowers(QuerySignalTotalPowersRequest) returns (QuerySignalTotalPowersResponse) {
4242
option (google.api.http).get = "/feeds/v1beta1/signal-total-powers";
4343
}
4444

45-
// Params is a RPC method that returns all parameters of the module.
45+
// Params is an RPC method that returns all parameters of the module.
4646
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
4747
option (google.api.http).get = "/feeds/v1beta1/params";
4848
}
4949

50-
// PriceService is a RPC method that returns information of price service.
50+
// PriceService is an RPC method that returns information of price service.
5151
rpc PriceService(QueryPriceServiceRequest) returns (QueryPriceServiceResponse) {
5252
option (google.api.http).get = "/feeds/v1beta1/price-service";
5353
}
5454

55-
// DelegatorSignals is a RPC method that returns signals of a delegator
55+
// DelegatorSignals is an RPC method that returns signals of a delegator
5656
rpc DelegatorSignals(QueryDelegatorSignalsRequest) returns (QueryDelegatorSignalsResponse) {
5757
option (google.api.http).get = "/feeds/v1beta1/delegators/{delegator}/signals";
5858
}
5959

60-
// SupportedFeeds is a RPC method that return list of currect supported feeds
60+
// SupportedFeeds is an RPC method that returns a list of current supported feeds
6161
rpc SupportedFeeds(QuerySupportedFeedsRequest) returns (QuerySupportedFeedsResponse) {
6262
option (google.api.http).get = "/feeds/v1beta1/supported-feeds";
6363
}
64+
65+
// IsFeeder is an RPC method that returns whether an account is a feeder for specified validator.
66+
rpc IsFeeder(QueryIsFeederRequest) returns (QueryIsFeederResponse) {
67+
option (google.api.http).get = "/feeds/v1beta1/feeder/{validator_address}/{feeder_address}";
68+
}
6469
}
6570

6671
// QueryPricesRequest is the request type for the Query/Prices RPC method.
@@ -187,3 +192,17 @@ message QuerySupportedFeedsResponse {
187192
// SupportedFeeds is a list of currently supported feeds, and its last update time and block.
188193
SupportedFeeds supported_feeds = 1 [(gogoproto.nullable) = false];
189194
}
195+
196+
// QueryIsFeederRequest is request type for the Query/IsFeeder RPC method.
197+
message QueryIsFeederRequest {
198+
// ValidatorAddress is a validator address
199+
string validator_address = 1;
200+
// FeederAddress is a candidate account
201+
string feeder_address = 2;
202+
}
203+
204+
// QueryIsFeederResponse is response type for the Query/IsFeeder RPC method.
205+
message QueryIsFeederResponse {
206+
// IsFeeder is true if this account has been granted by validator
207+
bool is_feeder = 1;
208+
}

proto/feeds/v1beta1/tx.proto

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import "amino/amino.proto";
1212

1313
// Msg defines the feeds Msg service.
1414
service Msg {
15-
// SubmitPrices is a RPC method to submit prices
15+
// SubmitPrices is an RPC method to submit prices
1616
rpc SubmitPrices(MsgSubmitPrices) returns (MsgSubmitPricesResponse);
1717

18-
// UpdatePriceService is a RPC method to update price service information
18+
// UpdatePriceService is an RPC method to update price service information
1919
rpc UpdatePriceService(MsgUpdatePriceService) returns (MsgUpdatePriceServiceResponse);
2020

21-
// UpdateParams is a RPC method to update parameters
21+
// UpdateParams is an RPC method to update parameters
2222
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
2323

24-
// SubmitSignals is a RPC method to signal ids and their powers
24+
// SubmitSignals is an RPC method to signal ids and their powers
2525
rpc SubmitSignals(MsgSubmitSignals) returns (MsgSubmitSignalsResponse);
2626
}
2727

x/feeds/keeper/grpc_query.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,20 @@ func (q queryServer) Params(c context.Context, _ *types.QueryParamsRequest) (*ty
254254
Params: q.keeper.GetParams(ctx),
255255
}, nil
256256
}
257+
258+
// IsFeeder queries if the given address is a feeder grantee of the validator
259+
func (q queryServer) IsFeeder(
260+
c context.Context,
261+
req *types.QueryIsFeederRequest,
262+
) (*types.QueryIsFeederResponse, error) {
263+
ctx := sdk.UnwrapSDKContext(c)
264+
val, err := sdk.ValAddressFromBech32(req.ValidatorAddress)
265+
if err != nil {
266+
return nil, err
267+
}
268+
resp, err := sdk.AccAddressFromBech32(req.FeederAddress)
269+
if err != nil {
270+
return nil, err
271+
}
272+
return &types.QueryIsFeederResponse{IsFeeder: q.keeper.IsFeeder(ctx, val, resp)}, nil
273+
}

x/feeds/keeper/keeper.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Keeper struct {
1616
cdc codec.BinaryCodec
1717
oracleKeeper types.OracleKeeper
1818
stakingKeeper types.StakingKeeper
19+
authzKeeper types.AuthzKeeper
1920

2021
authority string
2122
}
@@ -56,3 +57,14 @@ func (k Keeper) IsBondedValidator(ctx sdk.Context, addr sdk.ValAddress) bool {
5657

5758
return val.IsBonded()
5859
}
60+
61+
// IsFeeder checks if the given address has been granted as a feeder by the given validator
62+
func (k Keeper) IsFeeder(ctx sdk.Context, validator sdk.ValAddress, feeder sdk.AccAddress) bool {
63+
cap, _ := k.authzKeeper.GetAuthorization(
64+
ctx,
65+
feeder,
66+
sdk.AccAddress(validator),
67+
sdk.MsgTypeURL(&types.MsgSubmitPrices{}),
68+
)
69+
return cap != nil
70+
}

x/feeds/types/expected_keepers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"cosmossdk.io/math"
77
sdk "github.com/cosmos/cosmos-sdk/types"
8+
"github.com/cosmos/cosmos-sdk/x/authz"
89
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
910

1011
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
@@ -30,3 +31,13 @@ type StakingKeeper interface {
3031
valAddr sdk.ValAddress,
3132
) (delegation stakingtypes.Delegation, found bool)
3233
}
34+
35+
// AuthzKeeper defines the expected authz keeper. for query and testing only don't use to create/remove grant on deliver tx
36+
type AuthzKeeper interface {
37+
GetAuthorization(
38+
ctx sdk.Context,
39+
grantee sdk.AccAddress,
40+
granter sdk.AccAddress,
41+
msgType string,
42+
) (authz.Authorization, *time.Time)
43+
}

0 commit comments

Comments
 (0)