From f43228dee8afc4e5d24413e34249fe50233b89fe Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 1 Apr 2022 18:11:35 +0200 Subject: [PATCH] feat: add grants by grantee authz query (backport #10944) (#11523) * feat: add grants by grantee authz query (#10944) (cherry picked from commit fa8099da98ac2e58f7672b94c35799d032fdb06b) # Conflicts: # CHANGELOG.md # api/cosmos/app/module/v1alpha1/module.pulsar.go # api/cosmos/app/v1alpha1/config.pulsar.go # api/cosmos/app/v1alpha1/module.pulsar.go # api/cosmos/app/v1alpha1/query.pulsar.go # api/cosmos/authz/v1beta1/authz.pulsar.go # api/cosmos/authz/v1beta1/genesis.pulsar.go # api/cosmos/authz/v1beta1/query.pulsar.go # api/cosmos/authz/v1beta1/query_grpc.pb.go # api/cosmos/base/query/v1beta1/pagination.pulsar.go # api/cosmos/tx/signing/v1beta1/signing.pulsar.go # proto/cosmos/authz/v1beta1/genesis.proto # proto/cosmos/authz/v1beta1/query.proto # x/authz/authz.pb.go # x/authz/client/cli/query.go # x/authz/client/rest/grpc_query_test.go # x/authz/genesis.pb.go # x/authz/keeper/grpc_query.go # x/authz/keeper/grpc_query_test.go # x/authz/query.pb.go # x/authz/query.pb.gw.go * fix conflicts * remove doc * remove scalar * Apply suggestions from code review Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> * fix conflicts * remove go-eth dep Co-authored-by: Callum Waters Co-authored-by: marbar3778 Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> --- CHANGELOG.md | 1 + .../secp256k1/internal/secp256k1/dummy.go | 6 +- docs/core/proto-docs.md | 307 +++-- proto/cosmos/authz/v1beta1/authz.proto | 12 + proto/cosmos/authz/v1beta1/genesis.proto | 13 +- proto/cosmos/authz/v1beta1/query.proto | 48 +- snapshots/types/snapshot.pb.go | 10 +- x/authz/authz.pb.go | 321 ++++- x/authz/client/cli/query.go | 98 ++ x/authz/client/rest/grpc_query_test.go | 111 +- x/authz/client/testutil/cli_test.go | 1 + x/authz/genesis.pb.go | 376 +----- x/authz/keeper/grpc_query.go | 103 ++ x/authz/keeper/grpc_query_test.go | 153 +++ x/authz/keeper/keys.go | 6 + x/authz/query.pb.go | 1093 ++++++++++++++++- x/authz/query.pb.gw.go | 232 ++++ 17 files changed, 2386 insertions(+), 505 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d57ef81ae..29e4768fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/bank) [\#11417](https://github.com/cosmos/cosmos-sdk/pull/11417) Introduce a new `SpendableBalances` gRPC query that retrieves an account's total (paginated) spendable balances. * (x/bank) [\#10771](https://github.com/cosmos/cosmos-sdk/pull/10771) Add safety check on bank module perms to allow module-specific mint restrictions (e.g. only minting a certain denom). * (x/bank) [\#10771](https://github.com/cosmos/cosmos-sdk/pull/10771) Add `bank.BankKeeper.WithMintCoinsRestriction` function to restrict use of bank `MintCoins` usage. This function is not on the bank `Keeper` interface, so it's not API-breaking, but only additive on the keeper implementation. +* [\#10944](https://github.com/cosmos/cosmos-sdk/pull/10944) `x/authz` add all grants by grantee query * [\#11124](https://github.com/cosmos/cosmos-sdk/pull/11124) Add `GetAllVersions` to application store * (x/auth) [\#10880](https://github.com/cosmos/cosmos-sdk/pull/10880) Added a new query to the tx query service that returns a block with transactions fully decoded. * [#11314](https://github.com/cosmos/cosmos-sdk/pull/11314) Add state rollback command. diff --git a/crypto/keys/secp256k1/internal/secp256k1/dummy.go b/crypto/keys/secp256k1/internal/secp256k1/dummy.go index 65a75080f..4ad93ac48 100644 --- a/crypto/keys/secp256k1/internal/secp256k1/dummy.go +++ b/crypto/keys/secp256k1/internal/secp256k1/dummy.go @@ -15,7 +15,7 @@ package secp256k1 import ( - _ "github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/include" - _ "github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src" - _ "github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/recovery" + _ "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/include" + _ "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src" + _ "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/modules/recovery" ) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 0f50a88cf..05da452d7 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -29,6 +29,7 @@ - [cosmos/authz/v1beta1/authz.proto](#cosmos/authz/v1beta1/authz.proto) - [GenericAuthorization](#cosmos.authz.v1beta1.GenericAuthorization) - [Grant](#cosmos.authz.v1beta1.Grant) + - [GrantAuthorization](#cosmos.authz.v1beta1.GrantAuthorization) - [cosmos/authz/v1beta1/event.proto](#cosmos/authz/v1beta1/event.proto) - [EventGrant](#cosmos.authz.v1beta1.EventGrant) @@ -36,9 +37,12 @@ - [cosmos/authz/v1beta1/genesis.proto](#cosmos/authz/v1beta1/genesis.proto) - [GenesisState](#cosmos.authz.v1beta1.GenesisState) - - [GrantAuthorization](#cosmos.authz.v1beta1.GrantAuthorization) - [cosmos/authz/v1beta1/query.proto](#cosmos/authz/v1beta1/query.proto) + - [QueryGranteeGrantsRequest](#cosmos.authz.v1beta1.QueryGranteeGrantsRequest) + - [QueryGranteeGrantsResponse](#cosmos.authz.v1beta1.QueryGranteeGrantsResponse) + - [QueryGranterGrantsRequest](#cosmos.authz.v1beta1.QueryGranterGrantsRequest) + - [QueryGranterGrantsResponse](#cosmos.authz.v1beta1.QueryGranterGrantsResponse) - [QueryGrantsRequest](#cosmos.authz.v1beta1.QueryGrantsRequest) - [QueryGrantsResponse](#cosmos.authz.v1beta1.QueryGrantsResponse) @@ -99,6 +103,8 @@ - [QueryDenomsMetadataResponse](#cosmos.bank.v1beta1.QueryDenomsMetadataResponse) - [QueryParamsRequest](#cosmos.bank.v1beta1.QueryParamsRequest) - [QueryParamsResponse](#cosmos.bank.v1beta1.QueryParamsResponse) + - [QuerySpendableBalancesRequest](#cosmos.bank.v1beta1.QuerySpendableBalancesRequest) + - [QuerySpendableBalancesResponse](#cosmos.bank.v1beta1.QuerySpendableBalancesResponse) - [QuerySupplyOfRequest](#cosmos.bank.v1beta1.QuerySupplyOfRequest) - [QuerySupplyOfResponse](#cosmos.bank.v1beta1.QuerySupplyOfResponse) - [QueryTotalSupplyRequest](#cosmos.bank.v1beta1.QueryTotalSupplyRequest) @@ -159,6 +165,11 @@ - [cosmos/base/snapshots/v1beta1/snapshot.proto](#cosmos/base/snapshots/v1beta1/snapshot.proto) - [Metadata](#cosmos.base.snapshots.v1beta1.Metadata) - [Snapshot](#cosmos.base.snapshots.v1beta1.Snapshot) + - [SnapshotExtensionMeta](#cosmos.base.snapshots.v1beta1.SnapshotExtensionMeta) + - [SnapshotExtensionPayload](#cosmos.base.snapshots.v1beta1.SnapshotExtensionPayload) + - [SnapshotIAVLItem](#cosmos.base.snapshots.v1beta1.SnapshotIAVLItem) + - [SnapshotItem](#cosmos.base.snapshots.v1beta1.SnapshotItem) + - [SnapshotStoreItem](#cosmos.base.snapshots.v1beta1.SnapshotStoreItem) - [cosmos/base/store/v1beta1/commit_info.proto](#cosmos/base/store/v1beta1/commit_info.proto) - [CommitID](#cosmos.base.store.v1beta1.CommitID) @@ -168,11 +179,6 @@ - [cosmos/base/store/v1beta1/listening.proto](#cosmos/base/store/v1beta1/listening.proto) - [StoreKVPair](#cosmos.base.store.v1beta1.StoreKVPair) -- [cosmos/base/store/v1beta1/snapshot.proto](#cosmos/base/store/v1beta1/snapshot.proto) - - [SnapshotIAVLItem](#cosmos.base.store.v1beta1.SnapshotIAVLItem) - - [SnapshotItem](#cosmos.base.store.v1beta1.SnapshotItem) - - [SnapshotStoreItem](#cosmos.base.store.v1beta1.SnapshotStoreItem) - - [cosmos/base/tendermint/v1beta1/query.proto](#cosmos/base/tendermint/v1beta1/query.proto) - [GetBlockByHeightRequest](#cosmos.base.tendermint.v1beta1.GetBlockByHeightRequest) - [GetBlockByHeightResponse](#cosmos.base.tendermint.v1beta1.GetBlockByHeightResponse) @@ -919,6 +925,25 @@ the provide method with expiration time. + + + +### GrantAuthorization +GrantAuthorization extends a grant with both the addresses of the grantee and granter. +It is used in genesis.proto and query.proto + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `granter` | [string](#string) | | | +| `grantee` | [string](#string) | | | +| `authorization` | [google.protobuf.Any](#google.protobuf.Any) | | | +| `expiration` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | + + + + + @@ -1000,24 +1025,6 @@ GenesisState defines the authz module's genesis state. - - - -### GrantAuthorization -GrantAuthorization defines the GenesisState/GrantAuthorization type. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `granter` | [string](#string) | | | -| `grantee` | [string](#string) | | | -| `authorization` | [google.protobuf.Any](#google.protobuf.Any) | | | -| `expiration` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | - - - - - @@ -1035,6 +1042,70 @@ GrantAuthorization defines the GenesisState/GrantAuthorization type. Since: cosmos-sdk 0.43 + + +### QueryGranteeGrantsRequest +QueryGranteeGrantsRequest is the request type for the Query/IssuedGrants RPC method. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `grantee` | [string](#string) | | | +| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an pagination for the request. | + + + + + + + + +### QueryGranteeGrantsResponse +QueryGranteeGrantsResponse is the response type for the Query/GranteeGrants RPC method. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `grants` | [GrantAuthorization](#cosmos.authz.v1beta1.GrantAuthorization) | repeated | grants is a list of grants granted to the grantee. | +| `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines an pagination for the response. | + + + + + + + + +### QueryGranterGrantsRequest +QueryGranterGrantsRequest is the request type for the Query/GranterGrants RPC method. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `granter` | [string](#string) | | | +| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an pagination for the request. | + + + + + + + + +### QueryGranterGrantsResponse +QueryGranterGrantsResponse is the response type for the Query/GranterGrants RPC method. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `grants` | [GrantAuthorization](#cosmos.authz.v1beta1.GrantAuthorization) | repeated | grants is a list of grants granted by the granter. | +| `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines an pagination for the response. | + + + + + + ### QueryGrantsRequest @@ -1083,6 +1154,12 @@ Query defines the gRPC querier service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | | `Grants` | [QueryGrantsRequest](#cosmos.authz.v1beta1.QueryGrantsRequest) | [QueryGrantsResponse](#cosmos.authz.v1beta1.QueryGrantsResponse) | Returns list of `Authorization`, granted to the grantee by the granter. | GET|/cosmos/authz/v1beta1/grants| +| `GranterGrants` | [QueryGranterGrantsRequest](#cosmos.authz.v1beta1.QueryGranterGrantsRequest) | [QueryGranterGrantsResponse](#cosmos.authz.v1beta1.QueryGranterGrantsResponse) | GranterGrants returns list of `GrantAuthorization`, granted by granter. + +Since: cosmos-sdk 0.46 | GET|/cosmos/authz/v1beta1/grants/granter/{granter}| +| `GranteeGrants` | [QueryGranteeGrantsRequest](#cosmos.authz.v1beta1.QueryGranteeGrantsRequest) | [QueryGranteeGrantsResponse](#cosmos.authz.v1beta1.QueryGranteeGrantsResponse) | GranteeGrants returns a list of `GrantAuthorization` by grantee. + +Since: cosmos-sdk 0.46 | GET|/cosmos/authz/v1beta1/grants/grantee/{grantee}| @@ -1874,6 +1951,40 @@ QueryParamsResponse defines the response type for querying x/bank parameters. + + +### QuerySpendableBalancesRequest +QuerySpendableBalancesRequest defines the gRPC request structure for querying +an account's spendable balances. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `address` | [string](#string) | | address is the address to query spendable balances for. | +| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an optional pagination for the request. | + + + + + + + + +### QuerySpendableBalancesResponse +QuerySpendableBalancesResponse defines the gRPC response structure for querying +an account's spendable balances. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `balances` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | balances is the spendable balances of all the coins. | +| `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines the pagination in the response. | + + + + + + ### QuerySupplyOfRequest @@ -1956,6 +2067,7 @@ Query defines the gRPC querier service. | ----------- | ------------ | ------------- | ------------| ------- | -------- | | `Balance` | [QueryBalanceRequest](#cosmos.bank.v1beta1.QueryBalanceRequest) | [QueryBalanceResponse](#cosmos.bank.v1beta1.QueryBalanceResponse) | Balance queries the balance of a single coin for a single account. | GET|/cosmos/bank/v1beta1/balances/{address}/by_denom| | `AllBalances` | [QueryAllBalancesRequest](#cosmos.bank.v1beta1.QueryAllBalancesRequest) | [QueryAllBalancesResponse](#cosmos.bank.v1beta1.QueryAllBalancesResponse) | AllBalances queries the balance of all coins for a single account. | GET|/cosmos/bank/v1beta1/balances/{address}| +| `SpendableBalances` | [QuerySpendableBalancesRequest](#cosmos.bank.v1beta1.QuerySpendableBalancesRequest) | [QuerySpendableBalancesResponse](#cosmos.bank.v1beta1.QuerySpendableBalancesResponse) | SpendableBalances queries the spenable balance of all coins for a single account. | GET|/cosmos/bank/v1beta1/spendable_balances/{address}| | `TotalSupply` | [QueryTotalSupplyRequest](#cosmos.bank.v1beta1.QueryTotalSupplyRequest) | [QueryTotalSupplyResponse](#cosmos.bank.v1beta1.QueryTotalSupplyResponse) | TotalSupply queries the total supply of all coins. | GET|/cosmos/bank/v1beta1/supply| | `SupplyOf` | [QuerySupplyOfRequest](#cosmos.bank.v1beta1.QuerySupplyOfRequest) | [QuerySupplyOfResponse](#cosmos.bank.v1beta1.QuerySupplyOfResponse) | SupplyOf queries the supply of a single coin. | GET|/cosmos/bank/v1beta1/supply/{denom}| | `Params` | [QueryParamsRequest](#cosmos.bank.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#cosmos.bank.v1beta1.QueryParamsResponse) | Params queries the parameters of x/bank module. | GET|/cosmos/bank/v1beta1/params| @@ -2630,6 +2742,88 @@ Snapshot contains Tendermint state sync snapshot info. + + + +### SnapshotExtensionMeta +SnapshotExtensionMeta contains metadata about an external snapshotter. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `name` | [string](#string) | | | +| `format` | [uint32](#uint32) | | | + + + + + + + + +### SnapshotExtensionPayload +SnapshotExtensionPayload contains payloads of an external snapshotter. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `payload` | [bytes](#bytes) | | | + + + + + + + + +### SnapshotIAVLItem +SnapshotIAVLItem is an exported IAVL node. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `key` | [bytes](#bytes) | | | +| `value` | [bytes](#bytes) | | | +| `version` | [int64](#int64) | | version is block height | +| `height` | [int32](#int32) | | height is depth of the tree. | + + + + + + + + +### SnapshotItem +SnapshotItem is an item contained in a rootmulti.Store snapshot. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `store` | [SnapshotStoreItem](#cosmos.base.snapshots.v1beta1.SnapshotStoreItem) | | | +| `iavl` | [SnapshotIAVLItem](#cosmos.base.snapshots.v1beta1.SnapshotIAVLItem) | | | +| `extension` | [SnapshotExtensionMeta](#cosmos.base.snapshots.v1beta1.SnapshotExtensionMeta) | | | +| `extension_payload` | [SnapshotExtensionPayload](#cosmos.base.snapshots.v1beta1.SnapshotExtensionPayload) | | | + + + + + + + + +### SnapshotStoreItem +SnapshotStoreItem contains metadata about a snapshotted store. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `name` | [string](#string) | | | + + + + + @@ -2735,71 +2929,6 @@ Since: cosmos-sdk 0.43 - - - - - - - - - - - -

Top

- -## cosmos/base/store/v1beta1/snapshot.proto - - - - - -### SnapshotIAVLItem -SnapshotIAVLItem is an exported IAVL node. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `key` | [bytes](#bytes) | | | -| `value` | [bytes](#bytes) | | | -| `version` | [int64](#int64) | | | -| `height` | [int32](#int32) | | | - - - - - - - - -### SnapshotItem -SnapshotItem is an item contained in a rootmulti.Store snapshot. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `store` | [SnapshotStoreItem](#cosmos.base.store.v1beta1.SnapshotStoreItem) | | | -| `iavl` | [SnapshotIAVLItem](#cosmos.base.store.v1beta1.SnapshotIAVLItem) | | | - - - - - - - - -### SnapshotStoreItem -SnapshotStoreItem contains metadata about a snapshotted store. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `name` | [string](#string) | | | - - - - - diff --git a/proto/cosmos/authz/v1beta1/authz.proto b/proto/cosmos/authz/v1beta1/authz.proto index 2c376905e..05b1feefa 100644 --- a/proto/cosmos/authz/v1beta1/authz.proto +++ b/proto/cosmos/authz/v1beta1/authz.proto @@ -25,3 +25,15 @@ message Grant { google.protobuf.Any authorization = 1 [(cosmos_proto.accepts_interface) = "Authorization"]; google.protobuf.Timestamp expiration = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; } + +// GrantAuthorization extends a grant with both the addresses of the grantee and granter. +// It is used in genesis.proto and query.proto +// +// Since: cosmos-sdk 0.45.2 +message GrantAuthorization { + string granter = 1; + string grantee = 2; + + google.protobuf.Any authorization = 3 [(cosmos_proto.accepts_interface) = "Authorization"]; + google.protobuf.Timestamp expiration = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; +} diff --git a/proto/cosmos/authz/v1beta1/genesis.proto b/proto/cosmos/authz/v1beta1/genesis.proto index ea8986944..310f62656 100644 --- a/proto/cosmos/authz/v1beta1/genesis.proto +++ b/proto/cosmos/authz/v1beta1/genesis.proto @@ -2,10 +2,8 @@ syntax = "proto3"; package cosmos.authz.v1beta1; -import "google/protobuf/timestamp.proto"; -import "google/protobuf/any.proto"; import "gogoproto/gogo.proto"; -import "cosmos_proto/cosmos.proto"; +import "cosmos/authz/v1beta1/authz.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/authz"; @@ -13,12 +11,3 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/authz"; message GenesisState { repeated GrantAuthorization authorization = 1 [(gogoproto.nullable) = false]; } - -// GrantAuthorization defines the GenesisState/GrantAuthorization type. -message GrantAuthorization { - string granter = 1; - string grantee = 2; - - google.protobuf.Any authorization = 3 [(cosmos_proto.accepts_interface) = "Authorization"]; - google.protobuf.Timestamp expiration = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; -} diff --git a/proto/cosmos/authz/v1beta1/query.proto b/proto/cosmos/authz/v1beta1/query.proto index 428210de0..f668309be 100644 --- a/proto/cosmos/authz/v1beta1/query.proto +++ b/proto/cosmos/authz/v1beta1/query.proto @@ -14,6 +14,20 @@ service Query { rpc Grants(QueryGrantsRequest) returns (QueryGrantsResponse) { option (google.api.http).get = "/cosmos/authz/v1beta1/grants"; } + + // GranterGrants returns list of `GrantAuthorization`, granted by granter. + // + // Since: cosmos-sdk 0.45.2 + rpc GranterGrants(QueryGranterGrantsRequest) returns (QueryGranterGrantsResponse) { + option (google.api.http).get = "/cosmos/authz/v1beta1/grants/granter/{granter}"; + } + + // GranteeGrants returns a list of `GrantAuthorization` by grantee. + // + // Since: cosmos-sdk 0.45.2 + rpc GranteeGrants(QueryGranteeGrantsRequest) returns (QueryGranteeGrantsResponse) { + option (google.api.http).get = "/cosmos/authz/v1beta1/grants/grantee/{grantee}"; + } } // QueryGrantsRequest is the request type for the Query/Grants RPC method. @@ -29,7 +43,39 @@ message QueryGrantsRequest { // QueryGrantsResponse is the response type for the Query/Authorizations RPC method. message QueryGrantsResponse { // authorizations is a list of grants granted for grantee by granter. - repeated cosmos.authz.v1beta1.Grant grants = 1; + repeated Grant grants = 1; + // pagination defines an pagination for the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +// QueryGranterGrantsRequest is the request type for the Query/GranterGrants RPC method. +message QueryGranterGrantsRequest { + string granter = 1; + + // pagination defines an pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +// QueryGranterGrantsResponse is the response type for the Query/GranterGrants RPC method. +message QueryGranterGrantsResponse { + // grants is a list of grants granted by the granter. + repeated GrantAuthorization grants = 1; + // pagination defines an pagination for the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +// QueryGranteeGrantsRequest is the request type for the Query/IssuedGrants RPC method. +message QueryGranteeGrantsRequest { + string grantee = 1; + + // pagination defines an pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +// QueryGranteeGrantsResponse is the response type for the Query/GranteeGrants RPC method. +message QueryGranteeGrantsResponse { + // grants is a list of grants granted to the grantee. + repeated GrantAuthorization grants = 1; // pagination defines an pagination for the response. cosmos.base.query.v1beta1.PageResponse pagination = 2; } diff --git a/snapshots/types/snapshot.pb.go b/snapshots/types/snapshot.pb.go index 5a70e5eb8..c7e427343 100644 --- a/snapshots/types/snapshot.pb.go +++ b/snapshots/types/snapshot.pb.go @@ -306,10 +306,12 @@ func (m *SnapshotStoreItem) GetName() string { // SnapshotIAVLItem is an exported IAVL node. type SnapshotIAVLItem struct { - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - Version int64 `protobuf:"varint,3,opt,name=version,proto3" json:"version,omitempty"` - Height int32 `protobuf:"varint,4,opt,name=height,proto3" json:"height,omitempty"` + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + // version is block height + Version int64 `protobuf:"varint,3,opt,name=version,proto3" json:"version,omitempty"` + // height is depth of the tree. + Height int32 `protobuf:"varint,4,opt,name=height,proto3" json:"height,omitempty"` } func (m *SnapshotIAVLItem) Reset() { *m = SnapshotIAVLItem{} } diff --git a/x/authz/authz.pb.go b/x/authz/authz.pb.go index 34fe197e0..772152fe5 100644 --- a/x/authz/authz.pb.go +++ b/x/authz/authz.pb.go @@ -109,15 +109,58 @@ func (m *Grant) XXX_DiscardUnknown() { var xxx_messageInfo_Grant proto.InternalMessageInfo +// GrantAuthorization extends a grant with both the addresses of the grantee and granter. +// It is used in genesis.proto and query.proto +type GrantAuthorization struct { + Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` + Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` + Authorization *types.Any `protobuf:"bytes,3,opt,name=authorization,proto3" json:"authorization,omitempty"` + Expiration time.Time `protobuf:"bytes,4,opt,name=expiration,proto3,stdtime" json:"expiration"` +} + +func (m *GrantAuthorization) Reset() { *m = GrantAuthorization{} } +func (m *GrantAuthorization) String() string { return proto.CompactTextString(m) } +func (*GrantAuthorization) ProtoMessage() {} +func (*GrantAuthorization) Descriptor() ([]byte, []int) { + return fileDescriptor_544dc2e84b61c637, []int{2} +} +func (m *GrantAuthorization) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GrantAuthorization) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GrantAuthorization.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 *GrantAuthorization) XXX_Merge(src proto.Message) { + xxx_messageInfo_GrantAuthorization.Merge(m, src) +} +func (m *GrantAuthorization) XXX_Size() int { + return m.Size() +} +func (m *GrantAuthorization) XXX_DiscardUnknown() { + xxx_messageInfo_GrantAuthorization.DiscardUnknown(m) +} + +var xxx_messageInfo_GrantAuthorization proto.InternalMessageInfo + func init() { proto.RegisterType((*GenericAuthorization)(nil), "cosmos.authz.v1beta1.GenericAuthorization") proto.RegisterType((*Grant)(nil), "cosmos.authz.v1beta1.Grant") + proto.RegisterType((*GrantAuthorization)(nil), "cosmos.authz.v1beta1.GrantAuthorization") } func init() { proto.RegisterFile("cosmos/authz/v1beta1/authz.proto", fileDescriptor_544dc2e84b61c637) } var fileDescriptor_544dc2e84b61c637 = []byte{ - // 303 bytes of a gzipped FileDescriptorProto + // 343 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0x84, 0xf0, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x44, 0x20, 0x2a, 0xf4, 0x20, 0x62, 0x50, @@ -132,11 +175,14 @@ var fileDescriptor_544dc2e84b61c637 = []byte{ 0x41, 0x6c, 0xd6, 0x83, 0xd9, 0xac, 0xe7, 0x98, 0x57, 0xe9, 0x24, 0x78, 0x0a, 0xdd, 0xa4, 0x20, 0x54, 0xdd, 0x42, 0x2e, 0x5c, 0x5c, 0xa9, 0x15, 0x05, 0x99, 0x45, 0x10, 0xb3, 0x98, 0xc0, 0x66, 0x49, 0x61, 0x98, 0x15, 0x02, 0xf3, 0xbc, 0x13, 0xc7, 0x89, 0x7b, 0xf2, 0x0c, 0x13, 0xee, 0xcb, - 0x33, 0x06, 0x21, 0xe9, 0x73, 0x72, 0x3a, 0xf1, 0x50, 0x8e, 0xe1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, - 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, - 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x54, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, - 0xa1, 0x81, 0x0c, 0xa5, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0x20, 0x11, 0x95, 0xc4, 0x06, 0xb6, - 0xcd, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x6e, 0xbe, 0xf1, 0x5a, 0xcd, 0x01, 0x00, 0x00, + 0x33, 0x06, 0x21, 0xe9, 0x53, 0xba, 0xcb, 0xc8, 0x25, 0x04, 0x76, 0x1e, 0xaa, 0xd7, 0x24, 0xb8, + 0xd8, 0xd3, 0x41, 0xa2, 0xa9, 0x45, 0x50, 0xef, 0xc1, 0xb8, 0x08, 0x99, 0x54, 0xb0, 0x9d, 0x70, + 0x99, 0x54, 0x4c, 0xff, 0x31, 0x53, 0xd1, 0x7f, 0x2c, 0xe4, 0xf9, 0xcf, 0xc9, 0xe9, 0xc4, 0x43, + 0x39, 0x86, 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, 0x52, 0x49, 0xcf, 0x2c, + 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0x85, 0x26, 0x22, 0x28, 0xa5, 0x5b, 0x9c, 0x92, 0xad, + 0x5f, 0x01, 0x49, 0x88, 0x49, 0x6c, 0x60, 0xdb, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf5, + 0xd2, 0x8f, 0xb0, 0xad, 0x02, 0x00, 0x00, } func (m *GenericAuthorization) Marshal() (dAtA []byte, err error) { @@ -212,6 +258,63 @@ func (m *Grant) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *GrantAuthorization) 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 *GrantAuthorization) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GrantAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Expiration, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Expiration):]) + if err3 != nil { + return 0, err3 + } + i -= n3 + i = encodeVarintAuthz(dAtA, i, uint64(n3)) + i-- + dAtA[i] = 0x22 + if m.Authorization != nil { + { + size, err := m.Authorization.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAuthz(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.Grantee) > 0 { + i -= len(m.Grantee) + copy(dAtA[i:], m.Grantee) + i = encodeVarintAuthz(dAtA, i, uint64(len(m.Grantee))) + i-- + dAtA[i] = 0x12 + } + if len(m.Granter) > 0 { + i -= len(m.Granter) + copy(dAtA[i:], m.Granter) + i = encodeVarintAuthz(dAtA, i, uint64(len(m.Granter))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintAuthz(dAtA []byte, offset int, v uint64) int { offset -= sovAuthz(v) base := offset @@ -251,6 +354,29 @@ func (m *Grant) Size() (n int) { return n } +func (m *GrantAuthorization) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Granter) + if l > 0 { + n += 1 + l + sovAuthz(uint64(l)) + } + l = len(m.Grantee) + if l > 0 { + n += 1 + l + sovAuthz(uint64(l)) + } + if m.Authorization != nil { + l = m.Authorization.Size() + n += 1 + l + sovAuthz(uint64(l)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Expiration) + n += 1 + l + sovAuthz(uint64(l)) + return n +} + func sovAuthz(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -458,6 +584,189 @@ func (m *Grant) Unmarshal(dAtA []byte) error { } return nil } +func (m *GrantAuthorization) 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 ErrIntOverflowAuthz + } + 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: GrantAuthorization: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GrantAuthorization: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Granter", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + 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 ErrInvalidLengthAuthz + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuthz + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Granter = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Grantee", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + 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 ErrInvalidLengthAuthz + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuthz + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Grantee = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authorization", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAuthz + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAuthz + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Authorization == nil { + m.Authorization = &types.Any{} + } + if err := m.Authorization.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Expiration", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAuthz + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAuthz + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Expiration, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAuthz(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAuthz + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipAuthz(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/authz/client/cli/query.go b/x/authz/client/cli/query.go index c8772b2aa..dfc997c44 100644 --- a/x/authz/client/cli/query.go +++ b/x/authz/client/cli/query.go @@ -27,6 +27,8 @@ func GetQueryCmd() *cobra.Command { authorizationQueryCmd.AddCommand( GetCmdQueryGrants(), + GetQueryGranterGrants(), + GetQueryGranteeGrants(), ) return authorizationQueryCmd @@ -91,3 +93,99 @@ $ %s query %s grants cosmos1skjw.. cosmos1skjwj.. %s flags.AddPaginationFlagsToCmd(cmd, "grants") return cmd } + +func GetQueryGranterGrants() *cobra.Command { + cmd := &cobra.Command{ + Use: "granter-grants [granter-addr]", + Args: cobra.ExactArgs(1), + Short: "query authorization grants granted by granter", + Long: strings.TrimSpace( + fmt.Sprintf(`Query authorization grants granted by granter. +Examples: +$ %s q %s granter-grants cosmos1skj.. +`, + version.AppName, authz.ModuleName), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + granter, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := authz.NewQueryClient(clientCtx) + res, err := queryClient.GranterGrants( + cmd.Context(), + &authz.QueryGranterGrantsRequest{ + Granter: granter.String(), + Pagination: pageReq, + }, + ) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "granter-grants") + return cmd +} + +func GetQueryGranteeGrants() *cobra.Command { + cmd := &cobra.Command{ + Use: "grantee-grants [grantee-addr]", + Args: cobra.ExactArgs(1), + Short: "query authorization grants granted to a grantee", + Long: strings.TrimSpace( + fmt.Sprintf(`Query authorization grants granted to a grantee. +Examples: +$ %s q %s grantee-grants cosmos1skj.. +`, + version.AppName, authz.ModuleName), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + grantee, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := authz.NewQueryClient(clientCtx) + res, err := queryClient.GranteeGrants( + cmd.Context(), + &authz.QueryGranteeGrantsRequest{ + Grantee: grantee.String(), + Pagination: pageReq, + }, + ) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "grantee-grants") + return cmd +} diff --git a/x/authz/client/rest/grpc_query_test.go b/x/authz/client/rest/grpc_query_test.go index 614e283a1..af6e940d7 100644 --- a/x/authz/client/rest/grpc_query_test.go +++ b/x/authz/client/rest/grpc_query_test.go @@ -1,3 +1,4 @@ +//go:build norace // +build norace package rest_test @@ -218,7 +219,9 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { tc := tc s.Run(tc.name, func() { tc.preRun() - resp, _ := rest.GetRequest(tc.url) + resp, err := rest.GetRequest(tc.url) + s.Require().NoError(err) + if tc.expectErr { s.Require().Contains(string(resp), tc.errMsg) } else { @@ -232,6 +235,108 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { } } -func TestIntegrationTestSuite(t *testing.T) { - suite.Run(t, new(IntegrationTestSuite)) +func (s *IntegrationTestSuite) TestQueryGranterGrantsGRPC() { + val := s.network.Validators[0] + grantee := s.grantee[1] + require := s.Require() + + testCases := []struct { + name string + url string + expectErr bool + errMsg string + numItems int + }{ + { + "invalid account address", + fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.APIAddress, "invalid address"), + true, + "decoding bech32 failed", + 0, + }, + { + "no authorizations found", + fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.APIAddress, grantee.String()), + false, + "", + 0, + }, + { + "valid query", + fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.APIAddress, val.Address.String()), + false, + "", + 7, + }, + } + for _, tc := range testCases { + s.Run(tc.name, func() { + resp, err := rest.GetRequest(tc.url) + require.NoError(err) + + if tc.expectErr { + require.Contains(string(resp), tc.errMsg) + } else { + var authorizations authz.QueryGranterGrantsResponse + err := val.ClientCtx.Codec.UnmarshalJSON(resp, &authorizations) + require.NoError(err) + // FIXME: https://github.com/cosmos/cosmos-sdk/issues/10965 + require.Len(authorizations.Grants, tc.numItems) + } + + }) + } +} + +func (s *IntegrationTestSuite) TestQueryGranteeGrantsGRPC() { + val := s.network.Validators[0] + grantee := s.grantee[1] + require := s.Require() + + testCases := []struct { + name string + url string + expectErr bool + errMsg string + numItems int + }{ + { + "invalid account address", + fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/grantee/%s", val.APIAddress, "invalid address"), + true, + "decoding bech32 failed", + 0, + }, + { + "no authorizations found", + fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/grantee/%s", val.APIAddress, val.Address.String()), + false, + "", + 0, + }, + { + "valid query", + fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/grantee/%s", val.APIAddress, grantee.String()), + false, + "", + 1, + }, + } + for _, tc := range testCases { + s.Run(tc.name, func() { + resp, err := rest.GetRequest(tc.url) + require.NoError(err) + + if tc.expectErr { + require.Contains(string(resp), tc.errMsg) + } else { + var authorizations authz.QueryGranteeGrantsResponse + err := val.ClientCtx.Codec.UnmarshalJSON(resp, &authorizations) + require.NoError(err) + // FIXME: https://github.com/cosmos/cosmos-sdk/issues/10965 + require.Len(authorizations.Grants, tc.numItems) + } + + }) + } } diff --git a/x/authz/client/testutil/cli_test.go b/x/authz/client/testutil/cli_test.go index 3c083e694..5b3ef61c5 100644 --- a/x/authz/client/testutil/cli_test.go +++ b/x/authz/client/testutil/cli_test.go @@ -1,3 +1,4 @@ +//go:build norace // +build norace package testutil diff --git a/x/authz/genesis.pb.go b/x/authz/genesis.pb.go index eb6b63d4c..56f2157a9 100644 --- a/x/authz/genesis.pb.go +++ b/x/authz/genesis.pb.go @@ -5,23 +5,17 @@ package authz import ( fmt "fmt" - types "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "github.com/regen-network/cosmos-proto" - _ "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. @@ -74,78 +68,8 @@ func (m *GenesisState) GetAuthorization() []GrantAuthorization { return nil } -// GrantAuthorization defines the GenesisState/GrantAuthorization type. -type GrantAuthorization struct { - Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` - Grantee string `protobuf:"bytes,2,opt,name=grantee,proto3" json:"grantee,omitempty"` - Authorization *types.Any `protobuf:"bytes,3,opt,name=authorization,proto3" json:"authorization,omitempty"` - Expiration time.Time `protobuf:"bytes,4,opt,name=expiration,proto3,stdtime" json:"expiration"` -} - -func (m *GrantAuthorization) Reset() { *m = GrantAuthorization{} } -func (m *GrantAuthorization) String() string { return proto.CompactTextString(m) } -func (*GrantAuthorization) ProtoMessage() {} -func (*GrantAuthorization) Descriptor() ([]byte, []int) { - return fileDescriptor_4c2fbb971da7c892, []int{1} -} -func (m *GrantAuthorization) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *GrantAuthorization) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_GrantAuthorization.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 *GrantAuthorization) XXX_Merge(src proto.Message) { - xxx_messageInfo_GrantAuthorization.Merge(m, src) -} -func (m *GrantAuthorization) XXX_Size() int { - return m.Size() -} -func (m *GrantAuthorization) XXX_DiscardUnknown() { - xxx_messageInfo_GrantAuthorization.DiscardUnknown(m) -} - -var xxx_messageInfo_GrantAuthorization proto.InternalMessageInfo - -func (m *GrantAuthorization) GetGranter() string { - if m != nil { - return m.Granter - } - return "" -} - -func (m *GrantAuthorization) GetGrantee() string { - if m != nil { - return m.Grantee - } - return "" -} - -func (m *GrantAuthorization) GetAuthorization() *types.Any { - if m != nil { - return m.Authorization - } - return nil -} - -func (m *GrantAuthorization) GetExpiration() time.Time { - if m != nil { - return m.Expiration - } - return time.Time{} -} - func init() { proto.RegisterType((*GenesisState)(nil), "cosmos.authz.v1beta1.GenesisState") - proto.RegisterType((*GrantAuthorization)(nil), "cosmos.authz.v1beta1.GrantAuthorization") } func init() { @@ -153,29 +77,20 @@ func init() { } var fileDescriptor_4c2fbb971da7c892 = []byte{ - // 337 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x52, 0xbb, 0x6e, 0xc2, 0x30, - 0x14, 0x8d, 0x0b, 0xea, 0xc3, 0x94, 0xa1, 0x11, 0x43, 0xca, 0x60, 0x10, 0xea, 0x90, 0x05, 0x5b, - 0xd0, 0xbd, 0x12, 0x51, 0x25, 0xa6, 0x2e, 0x94, 0xa9, 0x4b, 0xe5, 0x80, 0x6b, 0xac, 0x36, 0x31, - 0x8a, 0x4d, 0x05, 0x7c, 0x05, 0x1f, 0xd3, 0x8f, 0x40, 0x9d, 0x18, 0xbb, 0xf4, 0x21, 0xf8, 0x91, - 0x2a, 0x76, 0xa2, 0xf2, 0xe8, 0x94, 0x7b, 0x73, 0xce, 0x3d, 0xe7, 0xf8, 0xda, 0xb0, 0x31, 0x90, - 0x2a, 0x92, 0x8a, 0xd0, 0x89, 0x1e, 0xcd, 0xc9, 0x6b, 0x2b, 0x64, 0x9a, 0xb6, 0x08, 0x67, 0x31, - 0x53, 0x42, 0xe1, 0x71, 0x22, 0xb5, 0x74, 0x2b, 0x96, 0x83, 0x0d, 0x07, 0x67, 0x9c, 0x6a, 0x8d, - 0x4b, 0xc9, 0x5f, 0x18, 0x31, 0x9c, 0x70, 0xf2, 0x44, 0xb4, 0x88, 0x98, 0xd2, 0x34, 0x1a, 0xdb, - 0xb1, 0xea, 0xe5, 0x3e, 0x81, 0xc6, 0xb3, 0x0c, 0xaa, 0x70, 0xc9, 0xa5, 0x29, 0x49, 0x5a, 0xe5, - 0x03, 0xd6, 0xe7, 0xd1, 0x02, 0x99, 0xa9, 0x69, 0x1a, 0x43, 0x78, 0xde, 0xb5, 0x99, 0xee, 0x35, - 0xd5, 0xcc, 0xed, 0xc3, 0x72, 0x9a, 0x46, 0x26, 0x62, 0x4e, 0xb5, 0x90, 0xb1, 0x07, 0xea, 0x05, - 0xbf, 0xd4, 0xf6, 0xf1, 0x7f, 0x51, 0x71, 0x37, 0xa1, 0xb1, 0xee, 0x6c, 0xf3, 0x83, 0xe2, 0xf2, - 0xab, 0xe6, 0xf4, 0x76, 0x45, 0x1a, 0x9f, 0x00, 0xba, 0x87, 0x5c, 0xd7, 0x83, 0x27, 0x3c, 0xfd, - 0xcb, 0x12, 0x0f, 0xd4, 0x81, 0x7f, 0xd6, 0xcb, 0xdb, 0x3f, 0x84, 0x79, 0x47, 0xdb, 0x08, 0x73, - 0xef, 0xf6, 0x03, 0x16, 0xea, 0xc0, 0x2f, 0xb5, 0x2b, 0xd8, 0x2e, 0x05, 0xe7, 0x4b, 0xc1, 0x9d, - 0x78, 0x16, 0x5c, 0xbc, 0xbf, 0x35, 0xcb, 0x3b, 0x9e, 0x7b, 0xc9, 0xdc, 0x5b, 0x08, 0xd9, 0x74, - 0x2c, 0x12, 0xab, 0x55, 0x34, 0x5a, 0xd5, 0x03, 0xad, 0x7e, 0x7e, 0x03, 0xc1, 0x69, 0x7a, 0xbc, - 0xc5, 0x77, 0x0d, 0xf4, 0xb6, 0xe6, 0x82, 0x9b, 0xe5, 0x1a, 0x81, 0xd5, 0x1a, 0x81, 0x9f, 0x35, - 0x02, 0x8b, 0x0d, 0x72, 0x56, 0x1b, 0xe4, 0x7c, 0x6c, 0x90, 0xf3, 0x70, 0xc5, 0x85, 0x1e, 0x4d, - 0x42, 0x3c, 0x90, 0x51, 0xb6, 0xf8, 0xec, 0xd3, 0x54, 0xc3, 0x67, 0x32, 0xb5, 0xcf, 0x23, 0x3c, - 0x36, 0x4e, 0xd7, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7c, 0xdb, 0x6c, 0xcb, 0x35, 0x02, 0x00, - 0x00, + // 206 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4a, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, + 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, + 0x81, 0xa8, 0xd1, 0x03, 0xab, 0xd1, 0x83, 0xaa, 0x91, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, + 0xd0, 0x07, 0xb1, 0x20, 0x6a, 0xa5, 0x14, 0xb0, 0x9a, 0x07, 0xd1, 0x09, 0x56, 0xa1, 0x94, 0xc2, + 0xc5, 0xe3, 0x0e, 0x31, 0x3e, 0xb8, 0x24, 0xb1, 0x24, 0x55, 0x28, 0x84, 0x8b, 0x17, 0x24, 0x9d, + 0x5f, 0x94, 0x59, 0x95, 0x58, 0x92, 0x99, 0x9f, 0x27, 0xc1, 0xa8, 0xc0, 0xac, 0xc1, 0x6d, 0xa4, + 0xa1, 0x87, 0xcd, 0x56, 0x3d, 0xf7, 0xa2, 0xc4, 0xbc, 0x12, 0x47, 0x64, 0xf5, 0x4e, 0x2c, 0x27, + 0xee, 0xc9, 0x33, 0x04, 0xa1, 0x1a, 0xe2, 0x64, 0x77, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, + 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, + 0x72, 0x0c, 0x51, 0x2a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x50, + 0xc7, 0x42, 0x28, 0xdd, 0xe2, 0x94, 0x6c, 0xfd, 0x0a, 0x88, 0x5b, 0x93, 0xd8, 0xc0, 0x8e, 0x35, + 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xb9, 0xd2, 0x41, 0x42, 0x20, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -215,63 +130,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *GrantAuthorization) 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 *GrantAuthorization) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *GrantAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Expiration, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Expiration):]) - if err1 != nil { - return 0, err1 - } - i -= n1 - i = encodeVarintGenesis(dAtA, i, uint64(n1)) - i-- - dAtA[i] = 0x22 - if m.Authorization != nil { - { - size, err := m.Authorization.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - if len(m.Grantee) > 0 { - i -= len(m.Grantee) - copy(dAtA[i:], m.Grantee) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.Grantee))) - i-- - dAtA[i] = 0x12 - } - if len(m.Granter) > 0 { - i -= len(m.Granter) - copy(dAtA[i:], m.Granter) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.Granter))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -298,29 +156,6 @@ func (m *GenesisState) Size() (n int) { return n } -func (m *GrantAuthorization) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Granter) - if l > 0 { - n += 1 + l + sovGenesis(uint64(l)) - } - l = len(m.Grantee) - if l > 0 { - n += 1 + l + sovGenesis(uint64(l)) - } - if m.Authorization != nil { - l = m.Authorization.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Expiration) - n += 1 + l + sovGenesis(uint64(l)) - return n -} - func sovGenesis(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -411,189 +246,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } return nil } -func (m *GrantAuthorization) 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: GrantAuthorization: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: GrantAuthorization: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Granter", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - 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 ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Granter = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Grantee", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - 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 ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Grantee = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Authorization", 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 - } - if m.Authorization == nil { - m.Authorization = &types.Any{} - } - if err := m.Authorization.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Expiration", 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 - } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Expiration, 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/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index 76091daaf..6b114c19b 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -90,6 +90,109 @@ func (k Keeper) Grants(c context.Context, req *authz.QueryGrantsRequest) (*authz }, nil } +// GranterGrants implements the Query/GranterGrants gRPC method. +func (k Keeper) GranterGrants(c context.Context, req *authz.QueryGranterGrantsRequest) (*authz.QueryGranterGrantsResponse, error) { + if req == nil { + return nil, status.Errorf(codes.InvalidArgument, "empty request") + } + + granter, err := sdk.AccAddressFromBech32(req.Granter) + if err != nil { + return nil, err + } + + ctx := sdk.UnwrapSDKContext(c) + store := ctx.KVStore(k.storeKey) + authzStore := prefix.NewStore(store, grantStoreKey(nil, granter, "")) + + var grants []*authz.GrantAuthorization + pageRes, err := query.FilteredPaginate(authzStore, req.Pagination, func(key []byte, value []byte, + accumulate bool) (bool, error) { + auth, err := unmarshalAuthorization(k.cdc, value) + if err != nil { + return false, err + } + + auth1 := auth.GetAuthorization() + if accumulate { + any, err := codectypes.NewAnyWithValue(auth1) + if err != nil { + return false, status.Errorf(codes.Internal, err.Error()) + } + + grantee := firstAddressFromGrantStoreKey(key) + grants = append(grants, &authz.GrantAuthorization{ + Granter: granter.String(), + Grantee: grantee.String(), + Authorization: any, + Expiration: auth.Expiration, + }) + } + return true, nil + }) + if err != nil { + return nil, err + } + + return &authz.QueryGranterGrantsResponse{ + Grants: grants, + Pagination: pageRes, + }, nil +} + +// GranteeGrants implements the Query/GranteeGrants gRPC method. +func (k Keeper) GranteeGrants(c context.Context, req *authz.QueryGranteeGrantsRequest) (*authz.QueryGranteeGrantsResponse, error) { + if req == nil { + return nil, status.Errorf(codes.InvalidArgument, "empty request") + } + + grantee, err := sdk.AccAddressFromBech32(req.Grantee) + if err != nil { + return nil, err + } + + ctx := sdk.UnwrapSDKContext(c) + store := prefix.NewStore(ctx.KVStore(k.storeKey), GrantKey) + + var authorizations []*authz.GrantAuthorization + pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key []byte, value []byte, + accumulate bool) (bool, error) { + auth, err := unmarshalAuthorization(k.cdc, value) + if err != nil { + return false, err + } + + granter, g := addressesFromGrantStoreKey(append(GrantKey, key...)) + if !g.Equals(grantee) { + return false, nil + } + + auth1 := auth.GetAuthorization() + if accumulate { + any, err := codectypes.NewAnyWithValue(auth1) + if err != nil { + return false, status.Errorf(codes.Internal, err.Error()) + } + + authorizations = append(authorizations, &authz.GrantAuthorization{ + Authorization: any, + Expiration: auth.Expiration, + Granter: granter.String(), + Grantee: grantee.String(), + }) + } + return true, nil + }) + if err != nil { + return nil, err + } + + return &authz.QueryGranteeGrantsResponse{ + Grants: authorizations, + Pagination: pageRes, + }, nil +} + // unmarshal an authorization from a store value func unmarshalAuthorization(cdc codec.BinaryCodec, value []byte) (v authz.Grant, err error) { err = cdc.Unmarshal(value, &v) diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index 37ddb7cf8..f10163b27 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -162,3 +163,155 @@ func (suite *TestSuite) TestGRPCQueryAuthorizations() { }) } } + +func (suite *TestSuite) TestGRPCQueryGranterGrants() { + require := suite.Require() + app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs + + testCases := []struct { + msg string + preRun func() + expError bool + request authz.QueryGranterGrantsRequest + numItems int + }{ + { + "fail invalid granter addr", + func() {}, + true, + authz.QueryGranterGrantsRequest{}, + 0, + }, + { + "valid case, single authorization", + func() { + now := ctx.BlockHeader().Time + newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) + authorization := &banktypes.SendAuthorization{SpendLimit: newCoins} + err := app.AuthzKeeper.SaveGrant(ctx, addrs[1], addrs[0], authorization, now.Add(time.Hour)) + require.NoError(err) + }, + false, + authz.QueryGranterGrantsRequest{ + Granter: addrs[0].String(), + }, + 1, + }, + { + "valid case, multiple authorization", + func() { + now := ctx.BlockHeader().Time + newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) + authorization := &banktypes.SendAuthorization{SpendLimit: newCoins} + err := app.AuthzKeeper.SaveGrant(ctx, addrs[2], addrs[0], authorization, now.Add(time.Hour)) + require.NoError(err) + }, + false, + authz.QueryGranterGrantsRequest{ + Granter: addrs[0].String(), + }, + 2, + }, + { + "valid case, pagination", + func() {}, + false, + authz.QueryGranterGrantsRequest{ + Granter: addrs[0].String(), + Pagination: &query.PageRequest{ + Limit: 1, + }, + }, + 1, + }, + } + + for _, tc := range testCases { + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + tc.preRun() + result, err := queryClient.GranterGrants(gocontext.Background(), &tc.request) + if tc.expError { + require.Error(err) + } else { + require.NoError(err) + require.Len(result.Grants, tc.numItems) + } + }) + } +} + +func (suite *TestSuite) TestGRPCQueryGranteeGrants() { + require := suite.Require() + app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs + + testCases := []struct { + msg string + preRun func() + expError bool + request authz.QueryGranteeGrantsRequest + numItems int + }{ + { + "fail invalid granter addr", + func() {}, + true, + authz.QueryGranteeGrantsRequest{}, + 0, + }, + { + "valid case, single authorization", + func() { + now := ctx.BlockHeader().Time + newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) + authorization := &banktypes.SendAuthorization{SpendLimit: newCoins} + err := app.AuthzKeeper.SaveGrant(ctx, addrs[0], addrs[1], authorization, now.Add(time.Hour)) + require.NoError(err) + }, + false, + authz.QueryGranteeGrantsRequest{ + Grantee: addrs[0].String(), + }, + 1, + }, + { + "valid case, multiple authorization", + func() { + now := ctx.BlockHeader().Time + newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) + authorization := &banktypes.SendAuthorization{SpendLimit: newCoins} + err := app.AuthzKeeper.SaveGrant(ctx, addrs[0], addrs[2], authorization, now.Add(time.Hour)) + require.NoError(err) + }, + false, + authz.QueryGranteeGrantsRequest{ + Grantee: addrs[0].String(), + }, + 2, + }, + { + "valid case, pagination", + func() {}, + false, + authz.QueryGranteeGrantsRequest{ + Grantee: addrs[0].String(), + Pagination: &query.PageRequest{ + Limit: 1, + }, + }, + 1, + }, + } + + for _, tc := range testCases { + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + tc.preRun() + result, err := queryClient.GranteeGrants(gocontext.Background(), &tc.request) + if tc.expError { + require.Error(err) + } else { + require.NoError(err) + require.Len(result.Grants, tc.numItems) + } + }) + } +} diff --git a/x/authz/keeper/keys.go b/x/authz/keeper/keys.go index 3bdd02138..0ffd7ba32 100644 --- a/x/authz/keeper/keys.go +++ b/x/authz/keeper/keys.go @@ -45,3 +45,9 @@ func addressesFromGrantStoreKey(key []byte) (granterAddr, granteeAddr sdk.AccAdd return granterAddr, granteeAddr } + +// firstAddressFromGrantStoreKey parses the first address only +func firstAddressFromGrantStoreKey(key []byte) sdk.AccAddress { + addrLen := key[0] + return sdk.AccAddress(key[1 : 1+addrLen]) +} diff --git a/x/authz/query.pb.go b/x/authz/query.pb.go index 3e332ef64..e7b570453 100644 --- a/x/authz/query.pb.go +++ b/x/authz/query.pb.go @@ -155,39 +155,268 @@ func (m *QueryGrantsResponse) GetPagination() *query.PageResponse { return nil } +// QueryGranterGrantsRequest is the request type for the Query/GranterGrants RPC method. +type QueryGranterGrantsRequest struct { + Granter string `protobuf:"bytes,1,opt,name=granter,proto3" json:"granter,omitempty"` + // pagination defines an pagination for the request. + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryGranterGrantsRequest) Reset() { *m = QueryGranterGrantsRequest{} } +func (m *QueryGranterGrantsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGranterGrantsRequest) ProtoMessage() {} +func (*QueryGranterGrantsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_376d714ffdeb1545, []int{2} +} +func (m *QueryGranterGrantsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGranterGrantsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGranterGrantsRequest.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 *QueryGranterGrantsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGranterGrantsRequest.Merge(m, src) +} +func (m *QueryGranterGrantsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGranterGrantsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGranterGrantsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGranterGrantsRequest proto.InternalMessageInfo + +func (m *QueryGranterGrantsRequest) GetGranter() string { + if m != nil { + return m.Granter + } + return "" +} + +func (m *QueryGranterGrantsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryGranterGrantsResponse is the response type for the Query/GranterGrants RPC method. +type QueryGranterGrantsResponse struct { + // grants is a list of grants granted by the granter. + Grants []*GrantAuthorization `protobuf:"bytes,1,rep,name=grants,proto3" json:"grants,omitempty"` + // pagination defines an pagination for the response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryGranterGrantsResponse) Reset() { *m = QueryGranterGrantsResponse{} } +func (m *QueryGranterGrantsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGranterGrantsResponse) ProtoMessage() {} +func (*QueryGranterGrantsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_376d714ffdeb1545, []int{3} +} +func (m *QueryGranterGrantsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGranterGrantsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGranterGrantsResponse.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 *QueryGranterGrantsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGranterGrantsResponse.Merge(m, src) +} +func (m *QueryGranterGrantsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGranterGrantsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGranterGrantsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGranterGrantsResponse proto.InternalMessageInfo + +func (m *QueryGranterGrantsResponse) GetGrants() []*GrantAuthorization { + if m != nil { + return m.Grants + } + return nil +} + +func (m *QueryGranterGrantsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryGranteeGrantsRequest is the request type for the Query/IssuedGrants RPC method. +type QueryGranteeGrantsRequest struct { + Grantee string `protobuf:"bytes,1,opt,name=grantee,proto3" json:"grantee,omitempty"` + // pagination defines an pagination for the request. + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryGranteeGrantsRequest) Reset() { *m = QueryGranteeGrantsRequest{} } +func (m *QueryGranteeGrantsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGranteeGrantsRequest) ProtoMessage() {} +func (*QueryGranteeGrantsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_376d714ffdeb1545, []int{4} +} +func (m *QueryGranteeGrantsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGranteeGrantsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGranteeGrantsRequest.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 *QueryGranteeGrantsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGranteeGrantsRequest.Merge(m, src) +} +func (m *QueryGranteeGrantsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGranteeGrantsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGranteeGrantsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGranteeGrantsRequest proto.InternalMessageInfo + +func (m *QueryGranteeGrantsRequest) GetGrantee() string { + if m != nil { + return m.Grantee + } + return "" +} + +func (m *QueryGranteeGrantsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryGranteeGrantsResponse is the response type for the Query/GranteeGrants RPC method. +type QueryGranteeGrantsResponse struct { + // grants is a list of grants granted to the grantee. + Grants []*GrantAuthorization `protobuf:"bytes,1,rep,name=grants,proto3" json:"grants,omitempty"` + // pagination defines an pagination for the response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryGranteeGrantsResponse) Reset() { *m = QueryGranteeGrantsResponse{} } +func (m *QueryGranteeGrantsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGranteeGrantsResponse) ProtoMessage() {} +func (*QueryGranteeGrantsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_376d714ffdeb1545, []int{5} +} +func (m *QueryGranteeGrantsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGranteeGrantsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGranteeGrantsResponse.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 *QueryGranteeGrantsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGranteeGrantsResponse.Merge(m, src) +} +func (m *QueryGranteeGrantsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGranteeGrantsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGranteeGrantsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGranteeGrantsResponse proto.InternalMessageInfo + +func (m *QueryGranteeGrantsResponse) GetGrants() []*GrantAuthorization { + if m != nil { + return m.Grants + } + return nil +} + +func (m *QueryGranteeGrantsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + func init() { proto.RegisterType((*QueryGrantsRequest)(nil), "cosmos.authz.v1beta1.QueryGrantsRequest") proto.RegisterType((*QueryGrantsResponse)(nil), "cosmos.authz.v1beta1.QueryGrantsResponse") + proto.RegisterType((*QueryGranterGrantsRequest)(nil), "cosmos.authz.v1beta1.QueryGranterGrantsRequest") + proto.RegisterType((*QueryGranterGrantsResponse)(nil), "cosmos.authz.v1beta1.QueryGranterGrantsResponse") + proto.RegisterType((*QueryGranteeGrantsRequest)(nil), "cosmos.authz.v1beta1.QueryGranteeGrantsRequest") + proto.RegisterType((*QueryGranteeGrantsResponse)(nil), "cosmos.authz.v1beta1.QueryGranteeGrantsResponse") } func init() { proto.RegisterFile("cosmos/authz/v1beta1/query.proto", fileDescriptor_376d714ffdeb1545) } var fileDescriptor_376d714ffdeb1545 = []byte{ - // 381 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x4f, 0xf2, 0x30, - 0x18, 0xc7, 0x29, 0xbc, 0x2f, 0xc6, 0xe2, 0xa9, 0x7a, 0x58, 0x90, 0x2c, 0x0b, 0x21, 0x3a, 0x4d, - 0xec, 0x02, 0xdc, 0x3d, 0x78, 0x90, 0xab, 0x2e, 0x7a, 0xf1, 0x42, 0x3a, 0x6c, 0xca, 0x22, 0x5b, - 0xc7, 0xda, 0x19, 0xf1, 0xa8, 0x67, 0x13, 0x13, 0xbe, 0x89, 0x9f, 0xc2, 0x23, 0x89, 0x17, 0x8f, - 0x06, 0xfc, 0x20, 0x86, 0xb6, 0x08, 0xc4, 0x25, 0x7a, 0x5a, 0xb6, 0xe7, 0xf7, 0xfc, 0x9f, 0x5f, - 0x9f, 0x15, 0x3a, 0x3d, 0x2e, 0x22, 0x2e, 0x3c, 0x92, 0xc9, 0xfe, 0xbd, 0x77, 0xdb, 0x0c, 0xa8, - 0x24, 0x4d, 0x6f, 0x98, 0xd1, 0x74, 0x84, 0x93, 0x94, 0x4b, 0x8e, 0x76, 0x34, 0x81, 0x15, 0x81, - 0x0d, 0x51, 0xad, 0x31, 0xce, 0xd9, 0x80, 0x7a, 0x24, 0x09, 0x3d, 0x12, 0xc7, 0x5c, 0x12, 0x19, - 0xf2, 0x58, 0xe8, 0x9e, 0xea, 0xa1, 0x49, 0x0d, 0x88, 0xa0, 0x3a, 0xec, 0x3b, 0x3a, 0x21, 0x2c, - 0x8c, 0x15, 0x6c, 0xd8, 0x7c, 0x03, 0x3d, 0x4d, 0x11, 0xf5, 0x17, 0x00, 0xd1, 0xf9, 0x3c, 0xa4, - 0x93, 0x92, 0x58, 0x0a, 0x9f, 0x0e, 0x33, 0x2a, 0x24, 0xb2, 0xe0, 0x06, 0x9b, 0x7f, 0xa0, 0xa9, - 0x05, 0x1c, 0xe0, 0x6e, 0xfa, 0x8b, 0xd7, 0x65, 0x85, 0x5a, 0xc5, 0xd5, 0x0a, 0x45, 0x0e, 0xdc, - 0x8a, 0x04, 0xeb, 0xca, 0x51, 0x42, 0xbb, 0x59, 0x3a, 0xb0, 0x4a, 0xaa, 0x0c, 0x23, 0xc1, 0x2e, - 0x46, 0x09, 0xbd, 0x4c, 0x07, 0xe8, 0x14, 0xc2, 0xa5, 0xa2, 0xf5, 0xcf, 0x01, 0x6e, 0xa5, 0xb5, - 0x87, 0xcd, 0x0e, 0xe6, 0xe7, 0xc1, 0x7a, 0x39, 0x46, 0x14, 0x9f, 0x11, 0x46, 0x8d, 0x91, 0xbf, - 0xd2, 0x59, 0x1f, 0x03, 0xb8, 0xbd, 0x26, 0x2d, 0x12, 0x1e, 0x0b, 0x8a, 0xda, 0xb0, 0xac, 0x64, - 0x84, 0x05, 0x9c, 0x92, 0x5b, 0x69, 0xed, 0xe2, 0xbc, 0xfd, 0x62, 0xd5, 0xe5, 0x1b, 0x14, 0x75, - 0xd6, 0xa4, 0x8a, 0x4a, 0x6a, 0xff, 0x57, 0x29, 0x3d, 0x71, 0xd5, 0xaa, 0xf5, 0x04, 0xe0, 0x7f, - 0x65, 0x85, 0x1e, 0x01, 0x2c, 0x6b, 0x35, 0xe4, 0xe6, 0x2b, 0xfc, 0x5c, 0x79, 0xf5, 0xe0, 0x0f, - 0xa4, 0x9e, 0x5a, 0x6f, 0x3c, 0xbc, 0x7d, 0x8e, 0x8b, 0x36, 0xaa, 0x79, 0xb9, 0xff, 0x57, 0x1f, - 0xec, 0xe4, 0xf8, 0x75, 0x6a, 0x83, 0xc9, 0xd4, 0x06, 0x1f, 0x53, 0x1b, 0x3c, 0xcf, 0xec, 0xc2, - 0x64, 0x66, 0x17, 0xde, 0x67, 0x76, 0xe1, 0xaa, 0xc1, 0x42, 0xd9, 0xcf, 0x02, 0xdc, 0xe3, 0xd1, - 0x22, 0x41, 0x3f, 0x8e, 0xc4, 0xf5, 0x8d, 0x77, 0xa7, 0xe3, 0x82, 0xb2, 0xba, 0x21, 0xed, 0xaf, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xf2, 0x52, 0x9e, 0x65, 0xc7, 0x02, 0x00, 0x00, + // 495 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x94, 0xc1, 0x6e, 0xd3, 0x30, + 0x18, 0xc7, 0xeb, 0x16, 0x8a, 0xf0, 0xe0, 0x62, 0x38, 0x84, 0x30, 0x45, 0x51, 0x35, 0x41, 0x41, + 0xc2, 0xde, 0x3a, 0x89, 0x23, 0x02, 0x0e, 0xdb, 0x15, 0x2a, 0xb8, 0x70, 0x99, 0xdc, 0xf1, 0xc9, + 0x8d, 0x68, 0xe3, 0xcc, 0x76, 0x10, 0x1d, 0xea, 0x05, 0x5e, 0x00, 0x69, 0x0f, 0x81, 0xc4, 0x91, + 0xa7, 0xe0, 0x38, 0x89, 0x0b, 0x47, 0xd4, 0x22, 0xf1, 0x1a, 0xa8, 0xb6, 0x4b, 0x9b, 0x91, 0x6d, + 0x01, 0x34, 0x69, 0xa7, 0x36, 0xf1, 0xff, 0xfb, 0xbe, 0x9f, 0x7f, 0x8a, 0x8d, 0xe3, 0x5d, 0xa9, + 0x87, 0x52, 0x33, 0x9e, 0x9b, 0xfe, 0x3e, 0x7b, 0xbd, 0xd1, 0x03, 0xc3, 0x37, 0xd8, 0x5e, 0x0e, + 0x6a, 0x44, 0x33, 0x25, 0x8d, 0x24, 0xd7, 0x5d, 0x82, 0xda, 0x04, 0xf5, 0x89, 0x70, 0x55, 0x48, + 0x29, 0x06, 0xc0, 0x78, 0x96, 0x30, 0x9e, 0xa6, 0xd2, 0x70, 0x93, 0xc8, 0x54, 0xbb, 0x9a, 0xf0, + 0xae, 0xef, 0xda, 0xe3, 0x1a, 0x5c, 0xb3, 0xdf, 0xad, 0x33, 0x2e, 0x92, 0xd4, 0x86, 0x7d, 0xb6, + 0x9c, 0xc0, 0x4d, 0xb3, 0x89, 0xd6, 0x67, 0x84, 0xc9, 0xd3, 0x59, 0x93, 0x6d, 0xc5, 0x53, 0xa3, + 0xbb, 0xb0, 0x97, 0x83, 0x36, 0x24, 0xc0, 0x97, 0xc4, 0xec, 0x05, 0xa8, 0x00, 0xc5, 0xa8, 0x7d, + 0xb9, 0x3b, 0x7f, 0x5c, 0xac, 0x40, 0x50, 0x5f, 0x5e, 0x01, 0x12, 0xe3, 0x2b, 0x43, 0x2d, 0x76, + 0xcc, 0x28, 0x83, 0x9d, 0x5c, 0x0d, 0x82, 0x86, 0x5d, 0xc6, 0x43, 0x2d, 0x9e, 0x8d, 0x32, 0x78, + 0xae, 0x06, 0x64, 0x0b, 0xe3, 0x05, 0x62, 0x70, 0x21, 0x46, 0xed, 0x95, 0xce, 0x2d, 0xea, 0x1d, + 0xcc, 0xf6, 0x43, 0x9d, 0x1c, 0x0f, 0x4a, 0x9f, 0x70, 0x01, 0x9e, 0xa8, 0xbb, 0x54, 0xd9, 0x3a, + 0x40, 0xf8, 0x5a, 0x01, 0x5a, 0x67, 0x32, 0xd5, 0x40, 0x36, 0x71, 0xd3, 0xc2, 0xe8, 0x00, 0xc5, + 0x8d, 0xf6, 0x4a, 0xe7, 0x26, 0x2d, 0xf3, 0x4b, 0x6d, 0x55, 0xd7, 0x47, 0xc9, 0x76, 0x01, 0xaa, + 0x6e, 0xa1, 0x6e, 0x9f, 0x0a, 0xe5, 0x26, 0x16, 0xa8, 0xc6, 0xf8, 0xc6, 0x02, 0x0a, 0x54, 0x55, + 0xa1, 0x5b, 0x25, 0xf3, 0xff, 0x45, 0xca, 0x47, 0x84, 0xc3, 0xb2, 0xf9, 0xde, 0xcd, 0xc3, 0x23, + 0x6e, 0xda, 0x27, 0xb8, 0x79, 0x94, 0x9b, 0xbe, 0x54, 0xc9, 0xbe, 0x6d, 0x7c, 0xd6, 0xa2, 0xe0, + 0x18, 0x51, 0x50, 0x14, 0x05, 0x67, 0x25, 0x0a, 0xce, 0xad, 0xa8, 0xce, 0xcf, 0x06, 0xbe, 0x68, + 0x49, 0xc9, 0x7b, 0x84, 0x9b, 0x8e, 0x93, 0x1c, 0xc3, 0xf3, 0xe7, 0x21, 0x0e, 0xef, 0x54, 0x48, + 0xba, 0xa9, 0xad, 0xb5, 0x77, 0x5f, 0x7f, 0x1c, 0xd4, 0x23, 0xb2, 0xca, 0x4a, 0x6f, 0x0c, 0xbf, + 0xb1, 0x4f, 0x08, 0x5f, 0x2d, 0x7c, 0x5d, 0x84, 0x9d, 0x36, 0xe2, 0xc8, 0x39, 0x08, 0xd7, 0xab, + 0x17, 0x78, 0xb4, 0xfb, 0x16, 0x6d, 0x9d, 0xd0, 0x93, 0xd0, 0x98, 0x3f, 0x4d, 0xec, 0xad, 0xff, + 0x33, 0x5e, 0x82, 0x85, 0xca, 0xb0, 0xf0, 0xb7, 0xb0, 0xf0, 0x1f, 0xb0, 0x30, 0x87, 0x85, 0xf1, + 0xe3, 0x07, 0x5f, 0x26, 0x11, 0x3a, 0x9c, 0x44, 0xe8, 0xfb, 0x24, 0x42, 0x1f, 0xa6, 0x51, 0xed, + 0x70, 0x1a, 0xd5, 0xbe, 0x4d, 0xa3, 0xda, 0x8b, 0x35, 0x91, 0x98, 0x7e, 0xde, 0xa3, 0xbb, 0x72, + 0x38, 0xef, 0xe9, 0x7e, 0xee, 0xe9, 0x97, 0xaf, 0xd8, 0x1b, 0x37, 0xa0, 0xd7, 0xb4, 0xb7, 0xf9, + 0xe6, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x6b, 0x01, 0xa4, 0x75, 0x73, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -204,6 +433,14 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Returns list of `Authorization`, granted to the grantee by the granter. Grants(ctx context.Context, in *QueryGrantsRequest, opts ...grpc.CallOption) (*QueryGrantsResponse, error) + // GranterGrants returns list of `GrantAuthorization`, granted by granter. + // + // Since: cosmos-sdk 0.46 + GranterGrants(ctx context.Context, in *QueryGranterGrantsRequest, opts ...grpc.CallOption) (*QueryGranterGrantsResponse, error) + // GranteeGrants returns a list of `GrantAuthorization` by grantee. + // + // Since: cosmos-sdk 0.46 + GranteeGrants(ctx context.Context, in *QueryGranteeGrantsRequest, opts ...grpc.CallOption) (*QueryGranteeGrantsResponse, error) } type queryClient struct { @@ -223,10 +460,36 @@ func (c *queryClient) Grants(ctx context.Context, in *QueryGrantsRequest, opts . return out, nil } +func (c *queryClient) GranterGrants(ctx context.Context, in *QueryGranterGrantsRequest, opts ...grpc.CallOption) (*QueryGranterGrantsResponse, error) { + out := new(QueryGranterGrantsResponse) + err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Query/GranterGrants", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) GranteeGrants(ctx context.Context, in *QueryGranteeGrantsRequest, opts ...grpc.CallOption) (*QueryGranteeGrantsResponse, error) { + out := new(QueryGranteeGrantsResponse) + err := c.cc.Invoke(ctx, "/cosmos.authz.v1beta1.Query/GranteeGrants", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Returns list of `Authorization`, granted to the grantee by the granter. Grants(context.Context, *QueryGrantsRequest) (*QueryGrantsResponse, error) + // GranterGrants returns list of `GrantAuthorization`, granted by granter. + // + // Since: cosmos-sdk 0.46 + GranterGrants(context.Context, *QueryGranterGrantsRequest) (*QueryGranterGrantsResponse, error) + // GranteeGrants returns a list of `GrantAuthorization` by grantee. + // + // Since: cosmos-sdk 0.46 + GranteeGrants(context.Context, *QueryGranteeGrantsRequest) (*QueryGranteeGrantsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -236,6 +499,12 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Grants(ctx context.Context, req *QueryGrantsRequest) (*QueryGrantsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Grants not implemented") } +func (*UnimplementedQueryServer) GranterGrants(ctx context.Context, req *QueryGranterGrantsRequest) (*QueryGranterGrantsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GranterGrants not implemented") +} +func (*UnimplementedQueryServer) GranteeGrants(ctx context.Context, req *QueryGranteeGrantsRequest) (*QueryGranteeGrantsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GranteeGrants not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -259,6 +528,42 @@ func _Query_Grants_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } +func _Query_GranterGrants_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGranterGrantsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GranterGrants(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.authz.v1beta1.Query/GranterGrants", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GranterGrants(ctx, req.(*QueryGranterGrantsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_GranteeGrants_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGranteeGrantsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GranteeGrants(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.authz.v1beta1.Query/GranteeGrants", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GranteeGrants(ctx, req.(*QueryGranteeGrantsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "cosmos.authz.v1beta1.Query", HandlerType: (*QueryServer)(nil), @@ -267,6 +572,14 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Grants", Handler: _Query_Grants_Handler, }, + { + MethodName: "GranterGrants", + Handler: _Query_GranterGrants_Handler, + }, + { + MethodName: "GranteeGrants", + Handler: _Query_GranteeGrants_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "cosmos/authz/v1beta1/query.proto", @@ -377,6 +690,188 @@ func (m *QueryGrantsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *QueryGranterGrantsRequest) 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 *QueryGranterGrantsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGranterGrantsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Granter) > 0 { + i -= len(m.Granter) + copy(dAtA[i:], m.Granter) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Granter))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGranterGrantsResponse) 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 *QueryGranterGrantsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGranterGrantsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Grants) > 0 { + for iNdEx := len(m.Grants) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Grants[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryGranteeGrantsRequest) 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 *QueryGranteeGrantsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGranteeGrantsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Grantee) > 0 { + i -= len(m.Grantee) + copy(dAtA[i:], m.Grantee) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Grantee))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGranteeGrantsResponse) 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 *QueryGranteeGrantsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGranteeGrantsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Grants) > 0 { + for iNdEx := len(m.Grants) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Grants[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -432,6 +927,78 @@ func (m *QueryGrantsResponse) Size() (n int) { return n } +func (m *QueryGranterGrantsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Granter) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGranterGrantsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Grants) > 0 { + for _, e := range m.Grants { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGranteeGrantsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Grantee) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGranteeGrantsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Grants) > 0 { + for _, e := range m.Grants { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -740,6 +1307,482 @@ func (m *QueryGrantsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryGranterGrantsRequest) 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: QueryGranterGrantsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGranterGrantsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Granter", 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.Granter = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.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 *QueryGranterGrantsResponse) 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: QueryGranterGrantsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGranterGrantsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Grants", 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 + } + m.Grants = append(m.Grants, &GrantAuthorization{}) + if err := m.Grants[len(m.Grants)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.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 *QueryGranteeGrantsRequest) 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: QueryGranteeGrantsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGranteeGrantsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Grantee", 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.Grantee = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.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 *QueryGranteeGrantsResponse) 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: QueryGranteeGrantsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGranteeGrantsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Grants", 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 + } + m.Grants = append(m.Grants, &GrantAuthorization{}) + if err := m.Grants[len(m.Grants)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.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 skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/authz/query.pb.gw.go b/x/authz/query.pb.gw.go index 3278cb6ba..500a9b4a6 100644 --- a/x/authz/query.pb.gw.go +++ b/x/authz/query.pb.gw.go @@ -67,6 +67,150 @@ func local_request_Query_Grants_0(ctx context.Context, marshaler runtime.Marshal } +var ( + filter_Query_GranterGrants_0 = &utilities.DoubleArray{Encoding: map[string]int{"granter": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_GranterGrants_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGranterGrantsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["granter"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "granter") + } + + protoReq.Granter, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "granter", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GranterGrants_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GranterGrants(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GranterGrants_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGranterGrantsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["granter"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "granter") + } + + protoReq.Granter, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "granter", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GranterGrants_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GranterGrants(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_GranteeGrants_0 = &utilities.DoubleArray{Encoding: map[string]int{"grantee": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_GranteeGrants_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGranteeGrantsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["grantee"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "grantee") + } + + protoReq.Grantee, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "grantee", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GranteeGrants_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GranteeGrants(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GranteeGrants_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGranteeGrantsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["grantee"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "grantee") + } + + protoReq.Grantee, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "grantee", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GranteeGrants_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GranteeGrants(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -93,6 +237,46 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_GranterGrants_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GranterGrants_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GranterGrants_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GranteeGrants_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GranteeGrants_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GranteeGrants_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -154,13 +338,61 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_GranterGrants_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GranterGrants_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GranterGrants_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GranteeGrants_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GranteeGrants_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GranteeGrants_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } var ( pattern_Query_Grants_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "authz", "v1beta1", "grants"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GranterGrants_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "authz", "v1beta1", "grants", "granter"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GranteeGrants_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "authz", "v1beta1", "grants", "grantee"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Grants_0 = runtime.ForwardResponseMessage + + forward_Query_GranterGrants_0 = runtime.ForwardResponseMessage + + forward_Query_GranteeGrants_0 = runtime.ForwardResponseMessage )