antelopeql 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/antelopeql.mjs +159 -0
  3. package/blockchain/deserialize_action_data.mjs +41 -0
  4. package/blockchain/get_abi.mjs +172 -0
  5. package/blockchain/get_account.mjs +233 -0
  6. package/blockchain/get_accounts_by_authorizers.mjs +79 -0
  7. package/blockchain/get_block.mjs +238 -0
  8. package/blockchain/get_currency_balance.mjs +48 -0
  9. package/blockchain/get_currency_stats.mjs +60 -0
  10. package/blockchain/get_info.mjs +96 -0
  11. package/blockchain/get_producers.mjs +104 -0
  12. package/blockchain/get_ram_price.mjs +57 -0
  13. package/blockchain/get_table_by_scope.mjs +96 -0
  14. package/blockchain_query_field.mjs +44 -0
  15. package/build_graphql_fields_from_abis.mjs +122 -0
  16. package/eosio_abi_to_graphql_ast.mjs +222 -0
  17. package/eosio_types/asset_type.mjs +35 -0
  18. package/eosio_types/block_timestamp_type.mjs +14 -0
  19. package/eosio_types/boolean_type.mjs +10 -0
  20. package/eosio_types/bytes_type.mjs +17 -0
  21. package/eosio_types/eosio_key_type.mjs +13 -0
  22. package/eosio_types/extended_asset_type.mjs +19 -0
  23. package/eosio_types/generate_checksum_type.mjs +20 -0
  24. package/eosio_types/generate_float_type.mjs +16 -0
  25. package/eosio_types/generate_int_type.mjs +28 -0
  26. package/eosio_types/generate_uint_type.mjs +27 -0
  27. package/eosio_types/name_type.mjs +29 -0
  28. package/eosio_types/public_key_type.mjs +26 -0
  29. package/eosio_types/signature_type.mjs +19 -0
  30. package/eosio_types/symbol_code_type.mjs +13 -0
  31. package/eosio_types/symbol_type.mjs +33 -0
  32. package/eosio_types/time_point_sec_type.mjs +12 -0
  33. package/eosio_types/time_point_type.mjs +12 -0
  34. package/eosio_types/varint32_type.mjs +13 -0
  35. package/eosio_types/varuint32_type.mjs +12 -0
  36. package/eosio_types.mjs +59 -0
  37. package/graphql_input_types/actions.mjs +15 -0
  38. package/graphql_input_types/authorization.mjs +30 -0
  39. package/graphql_input_types/configuration.mjs +55 -0
  40. package/graphql_input_types/query_argument_fields.mjs +82 -0
  41. package/graphql_object_types/authorization.mjs +15 -0
  42. package/graphql_object_types/authorizing_account_type.mjs +15 -0
  43. package/graphql_object_types/packed_transaction.mjs +32 -0
  44. package/graphql_object_types/transaction_receipt.mjs +159 -0
  45. package/mutation_resolver.mjs +234 -0
  46. package/package.json +97 -0
  47. package/push_serialized_transaction.mjs +24 -0
  48. package/push_transaction.mjs +75 -0
  49. package/push_transaction_rpc.mjs +37 -0
  50. package/query_resolver.mjs +43 -0
  51. package/readme.md +164 -0
  52. package/serialize_transaction.mjs +23 -0
  53. package/types.mjs +64 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 H
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/antelopeql.mjs ADDED
@@ -0,0 +1,159 @@
1
+ import {
2
+ execute,
3
+ GraphQLError,
4
+ GraphQLObjectType,
5
+ GraphQLSchema,
6
+ parse,
7
+ Source,
8
+ validate
9
+ } from "graphql";
10
+
11
+ import blockchain_query_field from "./blockchain_query_field.mjs";
12
+ import build_graphql_fields_from_abis from "./build_graphql_fields_from_abis.mjs";
13
+ import actions from "./graphql_input_types/actions.mjs";
14
+ import push_serialized_transaction from "./push_serialized_transaction.mjs";
15
+ import push_transaction from "./push_transaction.mjs";
16
+ import serialize_transaction from "./serialize_transaction.mjs";
17
+
18
+ /**
19
+ * @typedef {Object} AntelopeQLArgument
20
+ * @property {String} query GraphQL query that will instruct AntelopeQL to perform a CRUD operation.
21
+ * @property {String} rpc_url Chain remote proceedure call (RPC) Uniform Resource Locator (URL).
22
+ * @property {*} [variableValues] GraphQL variables.
23
+ * @property {String} [operationName] GraphQL operation name (query resolution).
24
+ * @property {Function} [fetch] Custom fetch implementation.
25
+ * @property {Array<String>} [contracts] List of Antelope smart contracts.
26
+ * @property {Array<String>} [private_keys] List of private keys used to sign transactions.
27
+ * @property {Headers} [headers] Headers to pass to the network request.
28
+ * @property {AbortSignal} [signal] Abort controller signal.
29
+ */
30
+
31
+ /**
32
+ * @typedef {Object} AntelopeQLResult
33
+ * @property {*} [data] returned data
34
+ * @property {Array<*>} [errors] returned errors
35
+ */
36
+
37
+ /**
38
+ * AntelopeQL for interacting with Antelope based blockchains.
39
+ * @param {AntelopeQLArgument} Argument
40
+ * @returns {AntelopeQLResult}
41
+ * @example
42
+ * ```js
43
+ * import AntelopeQL from 'antelopeql/antelopeql.mjs'
44
+ * import fetch from 'node-fetch'
45
+ *
46
+ * const query = `{ eosio_token { accounts(arg: { scope: "relockeblock" }){ balance } } }`
47
+ *
48
+ * AntelopeQL({
49
+ * query,
50
+ * contracts: ["eosio.token"],
51
+ * fetch,
52
+ * rpc_url: "https://eos.relocke.io",
53
+ * headers: { "content-type": "application/json" }
54
+ * }).then(console.log);
55
+ * ```
56
+ * > Logged output was "data": {"eosio_token": {"accounts": [{"balance": "100.0211 EOS"}]}}}
57
+ */
58
+
59
+ export default async function AntelopeQL({
60
+ query,
61
+ variableValues,
62
+ operationName,
63
+ fetch,
64
+ contracts = [],
65
+ private_keys = [],
66
+ rpc_url,
67
+ headers,
68
+ signal
69
+ }) {
70
+ try {
71
+ if (!fetch && !(typeof window == "undefined")) fetch = window.fetch;
72
+ if (!fetch && typeof window == "undefined")
73
+ throw new GraphQLError("No fetch implementation provided");
74
+
75
+ const fetchOptions = {};
76
+ if (headers) fetchOptions.headers = headers;
77
+ if (signal) fetchOptions.signal = signal;
78
+
79
+ const uri = `${rpc_url}/v1/chain/get_abi`;
80
+
81
+ const abi_req = contracts.map((account_name) =>
82
+ fetch(uri, {
83
+ method: "POST",
84
+ ...fetchOptions,
85
+ body: JSON.stringify({
86
+ account_name,
87
+ json: true
88
+ })
89
+ }).then((/** @type {{ json: () => any; }} */ req) => req.json())
90
+ );
91
+
92
+ const ABIs = await Promise.all(abi_req);
93
+ for (let i = 0; i < contracts.length; i++) {
94
+ if (ABIs[i].error)
95
+ throw new GraphQLError(ABIs[i].message, { extensions: ABIs[i] });
96
+ if (!ABIs[i].abi)
97
+ throw new GraphQLError(
98
+ `No smart contract found for “${contracts[i]}”.`
99
+ );
100
+ }
101
+
102
+ const { mutation_fields, query_fields, ast_list } =
103
+ build_graphql_fields_from_abis(ABIs);
104
+
105
+ const queries = new GraphQLObjectType({
106
+ name: "Query",
107
+ description: "Query table data from EOSIO blockchain.",
108
+ fields: { blockchain: blockchain_query_field, ...query_fields }
109
+ });
110
+
111
+ let mutations;
112
+
113
+ if (Object.keys(mutation_fields).length) {
114
+ const action_fields = actions(mutation_fields);
115
+ mutations = new GraphQLObjectType({
116
+ name: "Mutation",
117
+ description: "Push transactions to the blockchain.",
118
+ fields: {
119
+ push_transaction: push_transaction(action_fields, ast_list),
120
+ serialize_transaction: serialize_transaction(action_fields, ast_list),
121
+ push_serialized_transaction
122
+ }
123
+ });
124
+ } else
125
+ mutations = new GraphQLObjectType({
126
+ name: "Mutation",
127
+ description: "Push transactions to the blockchain.",
128
+ fields: {
129
+ push_serialized_transaction
130
+ }
131
+ });
132
+
133
+ const schema = new GraphQLSchema({
134
+ query: queries,
135
+ mutation: mutations
136
+ });
137
+
138
+ const document = parse(new Source(query));
139
+ const queryErrors = validate(schema, document);
140
+ if (queryErrors.length) return { errors: queryErrors };
141
+
142
+ return execute({
143
+ schema,
144
+ document,
145
+ rootValue: "",
146
+ contextValue: {
147
+ network: { rpc_url, fetch, ...fetchOptions },
148
+ private_keys
149
+ },
150
+ variableValues,
151
+ operationName,
152
+ fieldResolver(rootValue, args, ctx, { fieldName }) {
153
+ return rootValue[fieldName];
154
+ }
155
+ });
156
+ } catch (err) {
157
+ return { errors: [err] };
158
+ }
159
+ }
@@ -0,0 +1,41 @@
1
+ import { GraphQLError, GraphQLNonNull, GraphQLString } from "graphql";
2
+
3
+ import bytes_type from "../eosio_types/bytes_type.mjs";
4
+ import name_type from "../eosio_types/name_type.mjs";
5
+
6
+ const deserialize_action_data = {
7
+ description: "Returns a JSON object containing deserialized action data.",
8
+ type: GraphQLString,
9
+ args: {
10
+ code: {
11
+ description: "Account name that holds the EOSIO smart contract.",
12
+ type: new GraphQLNonNull(name_type)
13
+ },
14
+ action: {
15
+ description: "Action name on the EOSIO smart contract.",
16
+ type: new GraphQLNonNull(name_type)
17
+ },
18
+ binargs: {
19
+ description: "Serialized action data.",
20
+ type: new GraphQLNonNull(bytes_type)
21
+ }
22
+ },
23
+ async resolve(_, args, { network: { fetch, rpc_url, ...fetchOptions } }) {
24
+ const uri = `${rpc_url}/v1/chain/abi_bin_to_json`;
25
+ const req = await fetch(uri, {
26
+ method: "POST",
27
+ ...fetchOptions,
28
+ body: JSON.stringify({
29
+ ...args,
30
+ json: true
31
+ })
32
+ });
33
+
34
+ const data = await req.json();
35
+
36
+ if (data.error) throw new GraphQLError(data.message, { extensions: data });
37
+ return JSON.stringify(data.args);
38
+ }
39
+ };
40
+
41
+ export default deserialize_action_data;
@@ -0,0 +1,172 @@
1
+ import {
2
+ GraphQLError,
3
+ GraphQLList,
4
+ GraphQLNonNull,
5
+ GraphQLObjectType,
6
+ GraphQLString
7
+ } from "graphql";
8
+
9
+ import name_type from "../eosio_types/name_type.mjs";
10
+
11
+ const variants_type = new GraphQLObjectType({
12
+ name: "abi_variant_type",
13
+ fields: () => ({
14
+ name: {
15
+ type: GraphQLString
16
+ },
17
+ types: {
18
+ type: new GraphQLList(GraphQLString)
19
+ }
20
+ })
21
+ });
22
+
23
+ const ricardian_clauses_type = new GraphQLObjectType({
24
+ name: "abi_richardian_clauses",
25
+ fields: () => ({
26
+ id: {
27
+ type: GraphQLString
28
+ },
29
+ body: {
30
+ type: GraphQLString
31
+ }
32
+ })
33
+ });
34
+
35
+ const tables_type = new GraphQLObjectType({
36
+ name: "abi_tables_type",
37
+ fields: () => ({
38
+ name: {
39
+ type: GraphQLString
40
+ },
41
+ index_type: {
42
+ type: GraphQLString
43
+ },
44
+ type: {
45
+ type: GraphQLString
46
+ },
47
+ key_names: {
48
+ type: new GraphQLList(GraphQLString)
49
+ },
50
+ key_types: {
51
+ type: new GraphQLList(GraphQLString)
52
+ }
53
+ })
54
+ });
55
+
56
+ const actions_type = new GraphQLObjectType({
57
+ name: "abi_actions_type",
58
+ fields: () => ({
59
+ name: {
60
+ type: GraphQLString
61
+ },
62
+ type: {
63
+ type: GraphQLString
64
+ },
65
+ ricardian_contract: {
66
+ type: GraphQLString
67
+ }
68
+ })
69
+ });
70
+
71
+ const types_type = new GraphQLObjectType({
72
+ name: "abi_types_type",
73
+ fields: () => ({
74
+ new_type_name: {
75
+ type: GraphQLString
76
+ },
77
+ type: {
78
+ desciption: "Native and blockchain types.",
79
+ type: GraphQLString
80
+ }
81
+ })
82
+ });
83
+
84
+ const field_type = new GraphQLObjectType({
85
+ name: "abi_field_type",
86
+ fields: () => ({
87
+ name: {
88
+ type: GraphQLString
89
+ },
90
+ type: {
91
+ type: GraphQLString
92
+ }
93
+ })
94
+ });
95
+
96
+ const struct_type = new GraphQLObjectType({
97
+ name: "abi_struct_type",
98
+ fields: () => ({
99
+ name: {
100
+ type: GraphQLString
101
+ },
102
+ base: {
103
+ type: GraphQLString
104
+ },
105
+ fields: {
106
+ type: new GraphQLList(field_type)
107
+ }
108
+ })
109
+ });
110
+
111
+ const abi_type = new GraphQLObjectType({
112
+ name: "abi_type",
113
+ description:
114
+ "The Application Binary Interface (ABI) is a JSON-based description on how to convert user actions between their JSON and Binary representations.",
115
+ fields: () => ({
116
+ actions: {
117
+ type: new GraphQLList(actions_type)
118
+ },
119
+ ricardian_clauses: {
120
+ description:
121
+ "Ricardian clauses describe the intended outcome of a particular actions. It may also be utilized to establish terms between the sender and the contract.",
122
+ type: new GraphQLList(ricardian_clauses_type)
123
+ },
124
+ structs: {
125
+ type: new GraphQLList(struct_type)
126
+ },
127
+ types: {
128
+ type: new GraphQLList(types_type)
129
+ },
130
+ tables: {
131
+ type: new GraphQLList(tables_type)
132
+ },
133
+ variants: {
134
+ type: new GraphQLList(variants_type)
135
+ },
136
+ version: {
137
+ type: GraphQLString
138
+ }
139
+ })
140
+ });
141
+
142
+ const get_abi = {
143
+ description: "Retrieve an application binary interface (ABI).",
144
+ type: abi_type,
145
+ args: {
146
+ account_name: {
147
+ description: "Account name of the smart contract holder.",
148
+ type: new GraphQLNonNull(name_type)
149
+ }
150
+ },
151
+ async resolve(
152
+ _,
153
+ { account_name },
154
+ { network: { fetch, rpc_url, ...fetchOptions } }
155
+ ) {
156
+ const uri = `${rpc_url}/v1/chain/get_abi`;
157
+ const req = await fetch(uri, {
158
+ method: "POST",
159
+ ...fetchOptions,
160
+ body: JSON.stringify({
161
+ account_name,
162
+ json: true
163
+ })
164
+ });
165
+ const data = await req.json();
166
+
167
+ if (data.error) throw new GraphQLError(data.message, { extensions: data });
168
+ return data.abi;
169
+ }
170
+ };
171
+
172
+ export default get_abi;
@@ -0,0 +1,233 @@
1
+ import {
2
+ GraphQLBoolean,
3
+ GraphQLError,
4
+ GraphQLInt,
5
+ GraphQLList,
6
+ GraphQLNonNull,
7
+ GraphQLObjectType,
8
+ GraphQLString
9
+ } from "graphql";
10
+
11
+ import asset_type from "../eosio_types/asset_type.mjs";
12
+ import EOSIO_key_type from "../eosio_types/eosio_key_type.mjs";
13
+ import name_type from "../eosio_types/name_type.mjs";
14
+
15
+ const resource_type = new GraphQLObjectType({
16
+ name: "resource_type",
17
+ fields: () => ({
18
+ owner: { type: name_type },
19
+ net_weight: { type: GraphQLString },
20
+ cpu_weight: { type: GraphQLString },
21
+ ram_bytes: { type: GraphQLString }
22
+ })
23
+ });
24
+
25
+ const bandwidth_type = new GraphQLObjectType({
26
+ name: "bandwith_type",
27
+ fields: () => ({
28
+ used: { type: GraphQLString },
29
+ available: { type: GraphQLString },
30
+ max: { type: GraphQLString }
31
+ })
32
+ });
33
+
34
+ const require_auth_type = new GraphQLObjectType({
35
+ name: "require_auth_type",
36
+ fields: () => ({
37
+ threshold: { type: GraphQLInt },
38
+ keys: { type: new GraphQLList(EOSIO_key_type) },
39
+ accounts: {
40
+ type: new GraphQLList(
41
+ new GraphQLObjectType({
42
+ name: "accounts_auth_type",
43
+ fields: () => ({
44
+ weight: { type: GraphQLInt },
45
+ permission: {
46
+ type: new GraphQLObjectType({
47
+ name: "account_auth_permission_type",
48
+ fields: () => ({
49
+ actor: { type: name_type },
50
+ permission: { type: name_type }
51
+ })
52
+ })
53
+ }
54
+ })
55
+ })
56
+ )
57
+ },
58
+ waits: {
59
+ type: new GraphQLList(
60
+ new GraphQLObjectType({
61
+ name: "account_auth_waits_type",
62
+ description:
63
+ "specifies that a transaction will not be executed without a required delay",
64
+ fields: () => ({
65
+ wait_sec: { type: GraphQLInt },
66
+ weight: { type: GraphQLInt }
67
+ })
68
+ })
69
+ )
70
+ }
71
+ })
72
+ });
73
+
74
+ const linked_actions_type = new GraphQLObjectType({
75
+ name: "linked_actions_type",
76
+ fields: {
77
+ account: { type: name_type },
78
+ action: { type: name_type }
79
+ }
80
+ });
81
+
82
+ const permission_type = new GraphQLObjectType({
83
+ name: "permission_type",
84
+ description: "EOS account permissions",
85
+ fields: {
86
+ perm_name: { type: name_type },
87
+ parent: { type: name_type },
88
+ required_auth: { type: require_auth_type },
89
+ linked_actions: {
90
+ type: new GraphQLList(linked_actions_type)
91
+ }
92
+ }
93
+ });
94
+
95
+ const account_type = new GraphQLObjectType({
96
+ name: "account_type",
97
+ fields: () => ({
98
+ account_name: {
99
+ type: name_type
100
+ },
101
+ head_block_num: { type: GraphQLString },
102
+ head_block_time: { type: GraphQLString },
103
+ privileged: { type: GraphQLBoolean },
104
+ last_code_update: { type: GraphQLString },
105
+ created: { type: GraphQLString },
106
+ core_liquid_balance: { type: asset_type },
107
+ ram_quota: { type: GraphQLString },
108
+ net_weight: { type: GraphQLString },
109
+ cpu_weight: { type: GraphQLString },
110
+ net_limit: { type: bandwidth_type },
111
+ cpu_limit: { type: bandwidth_type },
112
+ ram_usage: { type: GraphQLString },
113
+ permissions: {
114
+ description: "List of the EOS `account_name` permissions",
115
+ type: new GraphQLList(permission_type)
116
+ },
117
+ total_resources: {
118
+ type: resource_type
119
+ },
120
+ self_delegated_bandwidth: {
121
+ type: new GraphQLObjectType({
122
+ name: "self_delegated_badwidth",
123
+ description: "Lists the amount of bandwidth your account has delegated",
124
+ fields: () => ({
125
+ to: { type: name_type },
126
+ from: { type: name_type },
127
+ net_weight: { type: asset_type },
128
+ cpu_weight: { type: asset_type }
129
+ })
130
+ })
131
+ },
132
+ refund_request: {
133
+ type: new GraphQLObjectType({
134
+ name: "account_refund_request",
135
+ description: "",
136
+ fields: () => ({
137
+ owner: { type: name_type },
138
+ request_time: { type: GraphQLString },
139
+ net_amount: { type: asset_type },
140
+ cpu_amount: { type: asset_type }
141
+ })
142
+ })
143
+ },
144
+ voter_info: {
145
+ type: new GraphQLObjectType({
146
+ name: "voter_info_type",
147
+ fields: () => ({
148
+ owner: { type: GraphQLString },
149
+ proxy: { type: GraphQLString },
150
+ producers: {
151
+ type: new GraphQLList(GraphQLString)
152
+ },
153
+ staked: { type: GraphQLString },
154
+ last_vote_weight: { type: GraphQLString },
155
+ proxied_vote_weight: { type: GraphQLString },
156
+ is_proxy: { type: GraphQLInt },
157
+ flags1: { type: GraphQLInt },
158
+ reserved2: { type: GraphQLInt },
159
+ reserved3: { type: GraphQLString }
160
+ })
161
+ })
162
+ },
163
+ subjective_cpu_bill_limit: {
164
+ type: new GraphQLObjectType({
165
+ name: "subjective_cpu_bill_limit_type",
166
+ fields: {
167
+ used: { type: GraphQLString },
168
+ available: { type: GraphQLString },
169
+ max: { type: GraphQLString }
170
+ }
171
+ })
172
+ },
173
+ rex_info: {
174
+ type: new GraphQLObjectType({
175
+ name: "rex_info_type",
176
+ fields: {
177
+ version: { type: GraphQLString },
178
+ owner: { type: GraphQLString },
179
+ vote_stake: { type: GraphQLString },
180
+ rex_balance: { type: GraphQLString },
181
+ matured_rex: { type: GraphQLString },
182
+ rex_maturities: {
183
+ type: new GraphQLList(
184
+ new GraphQLObjectType({
185
+ name: "pair_time_point_sec_int64",
186
+ fields: {
187
+ key: { type: GraphQLString },
188
+ value: { type: GraphQLString }
189
+ }
190
+ })
191
+ )
192
+ }
193
+ }
194
+ })
195
+ },
196
+ eosio_any_linked_actions: {
197
+ type: new GraphQLList(linked_actions_type)
198
+ }
199
+ })
200
+ });
201
+
202
+ const get_account = {
203
+ description: `Retreive details about a specific account on the blockchain.`,
204
+ type: account_type,
205
+ args: {
206
+ account_name: {
207
+ type: new GraphQLNonNull(name_type)
208
+ }
209
+ },
210
+ async resolve(
211
+ _,
212
+ { account_name },
213
+ { network: { fetch, rpc_url, ...fetchOptions } }
214
+ ) {
215
+ const uri = `${rpc_url}/v1/chain/get_account`;
216
+ const req = await fetch(uri, {
217
+ method: "POST",
218
+ ...fetchOptions,
219
+ body: JSON.stringify({
220
+ account_name,
221
+ json: true
222
+ })
223
+ });
224
+
225
+ const data = await req.json();
226
+
227
+ if (data.error) throw new GraphQLError(data.message, { extensions: data });
228
+
229
+ return data;
230
+ }
231
+ };
232
+
233
+ export default get_account;
@@ -0,0 +1,79 @@
1
+ import {
2
+ GraphQLError,
3
+ GraphQLList,
4
+ GraphQLNonNull,
5
+ GraphQLObjectType,
6
+ GraphQLString
7
+ } from "graphql";
8
+
9
+ import name_type from "../eosio_types/name_type.mjs";
10
+ import public_key_type from "../eosio_types/public_key_type.mjs";
11
+ import authorizing_account_type from "../graphql_object_types/authorizing_account_type.mjs";
12
+
13
+ const authorized_accounts_type = new GraphQLObjectType({
14
+ name: "authorized_accounts_type",
15
+ fields: () => ({
16
+ account_name: {
17
+ type: name_type
18
+ },
19
+ permission_name: {
20
+ type: name_type
21
+ },
22
+ authorizing_key: {
23
+ type: public_key_type
24
+ },
25
+ authorizing_account: {
26
+ type: authorizing_account_type
27
+ },
28
+ weight: {
29
+ type: GraphQLString
30
+ },
31
+ threshold: {
32
+ type: GraphQLString
33
+ }
34
+ })
35
+ });
36
+
37
+ const accounts_by_authorizers_type = new GraphQLObjectType({
38
+ name: "accounts_by_authorizers",
39
+ fields: () => ({
40
+ accounts: {
41
+ type: new GraphQLList(authorized_accounts_type)
42
+ }
43
+ })
44
+ });
45
+
46
+ const accounts_by_authorizers = {
47
+ description:
48
+ "Fetch permissions authorities that are, in part or whole, satisfiable.",
49
+ type: accounts_by_authorizers_type,
50
+ args: {
51
+ accounts: {
52
+ type: new GraphQLList(new GraphQLNonNull(name_type))
53
+ },
54
+ keys: {
55
+ type: new GraphQLList(new GraphQLNonNull(public_key_type))
56
+ }
57
+ },
58
+ async resolve(
59
+ _,
60
+ { accounts = [], keys = [] },
61
+ { network: { fetch, rpc_url, ...fetchOptions } }
62
+ ) {
63
+ const uri = `${rpc_url}/v1/chain/get_accounts_by_authorizers`;
64
+ const data = await fetch(uri, {
65
+ method: "POST",
66
+ ...fetchOptions,
67
+ body: JSON.stringify({
68
+ keys: await Promise.all(keys),
69
+ accounts,
70
+ json: true
71
+ })
72
+ }).then((req) => req.json());
73
+
74
+ if (data.error) throw new GraphQLError(data.message, { extensions: data });
75
+ return data;
76
+ }
77
+ };
78
+
79
+ export default accounts_by_authorizers;