Skip to content

Commit 550dfbc

Browse files
committed
add isFeeder query
1 parent 19cbea3 commit 550dfbc

File tree

6 files changed

+682
-70
lines changed

6 files changed

+682
-70
lines changed

proto/feeds/v1beta1/query.proto

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ service Query {
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 a RPC method that returns list of currect supported feeds
6161
rpc SupportedFeeds(QuerySupportedFeedsRequest) returns (QuerySupportedFeedsResponse) {
6262
option (google.api.http).get = "/feeds/v1beta1/supported-feeds";
6363
}
64+
65+
// IsFeeder is a 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+
}

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 grant of account on this 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+
rep, err := sdk.AccAddressFromBech32(req.FeederAddress)
269+
if err != nil {
270+
return nil, err
271+
}
272+
return &types.QueryIsFeederResponse{IsFeeder: q.keeper.IsFeeder(ctx, val, rep)}, 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 validator granted to the feeder
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)