/
queries.ts
59 lines (55 loc) · 1.81 KB
/
queries.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import {
QueryClientImpl,
QueryGranteeGrantsResponse,
QueryGranterGrantsResponse,
QueryGrantsResponse,
} from "cosmjs-types/cosmos/authz/v1beta1/query";
import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
export interface AuthzExtension {
readonly authz: {
readonly grants: (
granter: string,
grantee: string,
msgTypeUrl: string,
paginationKey?: Uint8Array,
) => Promise<QueryGrantsResponse>;
readonly granteeGrants: (
grantee: string,
paginationKey?: Uint8Array,
) => Promise<QueryGranteeGrantsResponse>;
readonly granterGrants: (
granter: string,
paginationKey?: Uint8Array,
) => Promise<QueryGranterGrantsResponse>;
};
}
export function setupAuthzExtension(base: QueryClient): AuthzExtension {
// Use this service to get easy typed access to query methods
// This cannot be used for proof verification
const rpc = createProtobufRpcClient(base);
const queryService = new QueryClientImpl(rpc);
return {
authz: {
grants: async (granter: string, grantee: string, msgTypeUrl: string, paginationKey?: Uint8Array) => {
return await queryService.Grants({
granter: granter,
grantee: grantee,
msgTypeUrl: msgTypeUrl,
pagination: createPagination(paginationKey),
});
},
granteeGrants: async (grantee: string, paginationKey?: Uint8Array) => {
return await queryService.GranteeGrants({
grantee: grantee,
pagination: createPagination(paginationKey),
});
},
granterGrants: async (granter: string, paginationKey?: Uint8Array) => {
return await queryService.GranterGrants({
granter: granter,
pagination: createPagination(paginationKey),
});
},
},
};
}