antelopeql 1.0.0 → 1.1.1

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.
package/antelopeql.mjs CHANGED
@@ -10,6 +10,7 @@ import {
10
10
 
11
11
  import blockchain_query_field from "./blockchain_query_field.mjs";
12
12
  import build_graphql_fields_from_abis from "./build_graphql_fields_from_abis.mjs";
13
+ import get_abis from "./get_abis.mjs";
13
14
  import actions from "./graphql_input_types/actions.mjs";
14
15
  import push_serialized_transaction from "./push_serialized_transaction.mjs";
15
16
  import push_transaction from "./push_transaction.mjs";
@@ -63,6 +64,7 @@ export default async function AntelopeQL({
63
64
  fetch,
64
65
  contracts = [],
65
66
  private_keys = [],
67
+ ABIs = [],
66
68
  rpc_url,
67
69
  headers,
68
70
  signal
@@ -76,35 +78,15 @@ export default async function AntelopeQL({
76
78
  if (headers) fetchOptions.headers = headers;
77
79
  if (signal) fetchOptions.signal = signal;
78
80
 
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
81
  const { mutation_fields, query_fields, ast_list } =
103
- build_graphql_fields_from_abis(ABIs);
82
+ build_graphql_fields_from_abis([
83
+ ...ABIs,
84
+ ...(await get_abis(contracts, { fetch, rpc_url, fetchOptions }))
85
+ ]);
104
86
 
105
87
  const queries = new GraphQLObjectType({
106
88
  name: "Query",
107
- description: "Query table data from EOSIO blockchain.",
89
+ description: "Query table data from Antelope blockchains.",
108
90
  fields: { blockchain: blockchain_query_field, ...query_fields }
109
91
  });
110
92
 
@@ -8,11 +8,11 @@ const deserialize_action_data = {
8
8
  type: GraphQLString,
9
9
  args: {
10
10
  code: {
11
- description: "Account name that holds the EOSIO smart contract.",
11
+ description: "Account name that holds the Antelope smart contract.",
12
12
  type: new GraphQLNonNull(name_type)
13
13
  },
14
14
  action: {
15
- description: "Action name on the EOSIO smart contract.",
15
+ description: "Action name on the Antelope smart contract.",
16
16
  type: new GraphQLNonNull(name_type)
17
17
  },
18
18
  binargs: {
@@ -81,7 +81,7 @@ const linked_actions_type = new GraphQLObjectType({
81
81
 
82
82
  const permission_type = new GraphQLObjectType({
83
83
  name: "permission_type",
84
- description: "EOS account permissions",
84
+ description: "Antelope account permissions",
85
85
  fields: {
86
86
  perm_name: { type: name_type },
87
87
  parent: { type: name_type },
@@ -94,6 +94,7 @@ const permission_type = new GraphQLObjectType({
94
94
 
95
95
  const account_type = new GraphQLObjectType({
96
96
  name: "account_type",
97
+ description: `Retreive details about a specific account on the blockchain.`,
97
98
  fields: () => ({
98
99
  account_name: {
99
100
  type: name_type
@@ -111,7 +112,7 @@ const account_type = new GraphQLObjectType({
111
112
  cpu_limit: { type: bandwidth_type },
112
113
  ram_usage: { type: GraphQLString },
113
114
  permissions: {
114
- description: "List of the EOS `account_name` permissions",
115
+ description: "List of the Antelope `account_name` permissions",
115
116
  type: new GraphQLList(permission_type)
116
117
  },
117
118
  total_resources: {
@@ -200,7 +201,6 @@ const account_type = new GraphQLObjectType({
200
201
  });
201
202
 
202
203
  const get_account = {
203
- description: `Retreive details about a specific account on the blockchain.`,
204
204
  type: account_type,
205
205
  args: {
206
206
  account_name: {
@@ -36,6 +36,8 @@ const authorized_accounts_type = new GraphQLObjectType({
36
36
 
37
37
  const accounts_by_authorizers_type = new GraphQLObjectType({
38
38
  name: "accounts_by_authorizers",
39
+ description:
40
+ "Fetch permissions authorities that are, in part or whole, satisfiable.",
39
41
  fields: () => ({
40
42
  accounts: {
41
43
  type: new GraphQLList(authorized_accounts_type)
@@ -44,8 +46,6 @@ const accounts_by_authorizers_type = new GraphQLObjectType({
44
46
  });
45
47
 
46
48
  const accounts_by_authorizers = {
47
- description:
48
- "Fetch permissions authorities that are, in part or whole, satisfiable.",
49
49
  type: accounts_by_authorizers_type,
50
50
  args: {
51
51
  accounts: {
@@ -43,7 +43,7 @@ const producer_type = new GraphQLObjectType({
43
43
  },
44
44
  block_signing_key: {
45
45
  type: GraphQLString,
46
- description: `Base58 encoded EOSIO public key.`
46
+ description: `Base58 encoded Antelope public key.`
47
47
  }
48
48
  })
49
49
  });
@@ -138,7 +138,7 @@ const transactions_type = new GraphQLObjectType({
138
138
 
139
139
  const block_type = new GraphQLObjectType({
140
140
  name: "block_type",
141
- description: "",
141
+ description: "Return info relating to a specific block.",
142
142
  fields: () => ({
143
143
  timestamp: {
144
144
  description: "Date/time string in the format `YYYY-MM-DDTHH:MM:SS.sss`",
@@ -179,7 +179,7 @@ const block_type = new GraphQLObjectType({
179
179
  },
180
180
  producer_signature: {
181
181
  type: GraphQLString,
182
- description: `Base58 encoded EOSIO cryptographic signature.`
182
+ description: `Base58 encoded Antelope cryptographic signature.`
183
183
  },
184
184
  transactions: {
185
185
  type: new GraphQLList(transactions_type),
@@ -205,7 +205,6 @@ const block_type = new GraphQLObjectType({
205
205
  });
206
206
 
207
207
  const get_block = {
208
- description: "Return info relating to a specific block.",
209
208
  type: block_type,
210
209
  args: {
211
210
  block_num_or_id: {
@@ -2,7 +2,7 @@ import { GraphQLError, GraphQLObjectType, GraphQLString } from "graphql";
2
2
 
3
3
  const info_type = new GraphQLObjectType({
4
4
  name: "info_type",
5
- description: "Returns various details about the EOS blockchain",
5
+ description: "Returns various details about the Antelope blockchain",
6
6
  fields: () => ({
7
7
  server_version: {
8
8
  type: GraphQLString,
@@ -56,9 +56,9 @@ const producers = new GraphQLObjectType({
56
56
  });
57
57
 
58
58
  const get_producers = {
59
- description: "Return info about block producers.",
59
+ description: "Return info about Antelope block producers.",
60
60
  type: new GraphQLObjectType({
61
- name: "blockchain_producers",
61
+ name: "antelope_producers",
62
62
  fields: {
63
63
  total_producer_vote_weight: {
64
64
  type: GraphQLString
@@ -13,9 +13,9 @@ import get_ram_price from "./blockchain/get_ram_price.mjs";
13
13
  import get_table from "./blockchain/get_table_by_scope.mjs";
14
14
 
15
15
  const blockchain_query_field = {
16
- description: `Retrieve infomation about the blockchain, cryptocurrency and accounts.`,
17
16
  type: new GraphQLObjectType({
18
- name: "blockchain",
17
+ name: "blockchain_type",
18
+ description: `Retrieve infomation about the blockchain, cryptocurrency and accounts.`,
19
19
  fields: {
20
20
  get_account,
21
21
  get_abi,
@@ -85,33 +85,35 @@ export default function build_graphql_fields_from_abis(abi_list) {
85
85
  name
86
86
  );
87
87
 
88
- contract_query_fields[name] = {
89
- name,
90
- type: new GraphQLObjectType({
91
- name: name + "_query",
92
- fields: query_fields
93
- }),
94
- resolve(__, _, { network: { rpc_url, fetch } = {} }, { fieldName }) {
95
- if (!fetch)
96
- throw new GraphQLError(
97
- "No fetch argument found on the context of the GraphQL.execute."
98
- );
88
+ if (Object.keys(query_fields).length)
89
+ contract_query_fields[name] = {
90
+ name,
91
+ type: new GraphQLObjectType({
92
+ name: name + "_query",
93
+ fields: query_fields
94
+ }),
95
+ resolve(__, _, { network: { rpc_url, fetch } = {} }, { fieldName }) {
96
+ if (!fetch)
97
+ throw new GraphQLError(
98
+ "No fetch argument found on the context of the GraphQL.execute."
99
+ );
99
100
 
100
- if (!rpc_url)
101
- throw new GraphQLError(
102
- "No rpc_url argument found on the context of the GraphQL.execute."
103
- );
101
+ if (!rpc_url)
102
+ throw new GraphQLError(
103
+ "No rpc_url argument found on the context of the GraphQL.execute."
104
+ );
104
105
 
105
- return { code: fieldName.replace(/_/gmu, ".") };
106
- }
107
- };
106
+ return { code: fieldName.replace(/_/gmu, ".") };
107
+ }
108
+ };
108
109
 
109
- contract_mutation_fields[name] = {
110
- type: new GraphQLInputObjectType({
111
- name,
112
- fields: mutation_fields
113
- })
114
- };
110
+ if (Object.keys(mutation_fields).length)
111
+ contract_mutation_fields[name] = {
112
+ type: new GraphQLInputObjectType({
113
+ name,
114
+ fields: mutation_fields
115
+ })
116
+ };
115
117
  }
116
118
 
117
119
  return {
@@ -182,13 +182,18 @@ export function get_graphql_fields_from_AST(AST, ABI, account_name = "") {
182
182
  let mutation_fields = {};
183
183
  const mutationTypes = {};
184
184
  for (const action of actions) {
185
- let { name: action_name, type: action_type } = action;
185
+ let {
186
+ name: action_name,
187
+ type: action_type,
188
+ ricardian_contract = ""
189
+ } = action;
186
190
  action_name = action_name.replace(/\./gmu, "_");
187
191
  const action_fields = AST[action_type];
188
192
 
189
193
  const buildQGL = (fields, acc = {}) => {
190
194
  for (const field of fields) {
191
195
  const { name, type, $info } = field;
196
+
192
197
  if ($info.object) {
193
198
  if (!GQL_MTYPES[type])
194
199
  GQL_MTYPES[type] = new GraphQLInputObjectType({
@@ -202,18 +207,24 @@ export function get_graphql_fields_from_AST(AST, ABI, account_name = "") {
202
207
  return acc;
203
208
  };
204
209
 
205
- if (!mutationTypes[action_type])
210
+ if (!mutationTypes[action_type]) {
206
211
  mutationTypes[action_type] = {
207
212
  type: new GraphQLInputObjectType({
208
213
  name: gql_account_name + action_type,
214
+ description: ricardian_contract
215
+ .replace(/(https?|http|ftp):\/\/[^\s$.?#].[^\s]*$/gmu, "")
216
+ .replace(/icon:/gmu, "")
217
+ .replace(/(\s)?nowrap(\s)?/gmu, ""),
209
218
  fields: {
210
219
  ...buildQGL(action_fields),
211
220
  authorization: {
221
+ description: "Authorization to sign the transaction",
212
222
  type: new GraphQLList(new GraphQLNonNull(authorization_type))
213
223
  }
214
224
  }
215
225
  })
216
226
  };
227
+ }
217
228
 
218
229
  mutation_fields[action_name] = mutationTypes[action_type];
219
230
  }
package/get_abis.mjs ADDED
@@ -0,0 +1,41 @@
1
+ import { GraphQLError } from "graphql";
2
+
3
+ export default async function get_abis(
4
+ contracts = [],
5
+ { fetch, rpc_url, fetchOptions = {} }
6
+ ) {
7
+ if (!contracts.length) [];
8
+
9
+ const uri = `${rpc_url}/v1/chain/get_abi`;
10
+
11
+ const abi_req = contracts.map((account_name) =>
12
+ fetch(uri, {
13
+ method: "POST",
14
+ ...fetchOptions,
15
+ body: JSON.stringify({ account_name, json: true })
16
+ }).then((req) => req.json())
17
+ );
18
+
19
+ const ABIs = await Promise.all(abi_req);
20
+
21
+ let errors = [];
22
+ ABIs.forEach(({ error, abi, account_name }, i) => {
23
+ if (error) {
24
+ try {
25
+ if (error.details[0]?.message.startsWith("unknown key ("))
26
+ errors.push({ message: `No account found for “${contracts[i]}”` });
27
+ } catch (err) {
28
+ throw new GraphQLError(ABIs[i].message, { extensions: ABIs[i] });
29
+ }
30
+ }
31
+ if (!abi)
32
+ errors.push({ message: `No contract found for “${account_name}”` });
33
+ });
34
+
35
+ if (errors.length)
36
+ throw new GraphQLError("Invalid Antelope smart contracts provided.", {
37
+ extensions: errors
38
+ });
39
+
40
+ return ABIs;
41
+ }
@@ -11,7 +11,7 @@ const configuration_default_value = {
11
11
  };
12
12
 
13
13
  /**
14
- * Handles various elements relating to the `EOSIO` transaction.
14
+ * Handles various elements relating to the `Antelope` transaction.
15
15
  * @typedef {Object} configuration_type
16
16
  * @param {Number} blocksBehind Number of blocks behind the current block (TaPoS protection).
17
17
  * @param {Number} expireSeconds Seconds past before transaction is no longer valid (TaPoS protection)
@@ -48,7 +48,7 @@ const transaction_status = new GraphQLEnumType({
48
48
  });
49
49
 
50
50
  /**
51
- * Bandwidth reciept for EOSIO transaction.
51
+ * Bandwidth reciept for Antelope transaction.
52
52
  * @typedef {Object} Bandwidth_cost
53
53
  * @prop {Number} net_usage_words Consumption of network bandwidth (bytes).
54
54
  * @prop {Number} cpu_usage_us Consumption of CPU bandwidth (µs).
@@ -119,7 +119,7 @@ const transaction_receipt_type = new GraphQLObjectType({
119
119
  fields: () => ({
120
120
  transaction_id: {
121
121
  type: GraphQLID,
122
- description: "`eosio` blockchain transaction id “reciept”"
122
+ description: "`Antelope` blockchain transaction id “reciept”"
123
123
  },
124
124
  block_num: {
125
125
  type: GraphQLInt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antelopeql",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "A GraphQL implementation for interacting with Antelope based blockchains.",
5
5
  "repository": "github:pur3miish/antelopeql",
6
6
  "bugs": "https://github.com/pur3miish/antelopeql/issues",
@@ -37,7 +37,8 @@
37
37
  "query_resolver.mjs",
38
38
  "serialize_transaction.mjs",
39
39
  "antelopeql.mjs",
40
- "types.mjs"
40
+ "types.mjs",
41
+ "get_abis.mjs"
41
42
  ],
42
43
  "sideEffects": false,
43
44
  "exports": {
@@ -56,7 +57,8 @@
56
57
  "./query_resolver.mjs": "./query_resolver.mjs",
57
58
  "./serialize_transaction.mjs": "./serialize_transaction.mjs",
58
59
  "./antelopeql.mjs": "./antelopeql.mjs",
59
- "./types.mjs": "./types.mjs"
60
+ "./types.mjs": "./types.mjs",
61
+ "./get_abis.mjs": "./get_abis.mjs"
60
62
  },
61
63
  "browserslist": [
62
64
  "> 0.5%, not OperaMini all, not IE > 0, not dead"
package/readme.md CHANGED
@@ -1,12 +1,18 @@
1
- ![antelopeql logo](https://raw.githubusercontent.com/pur3miish/antelope/main/static/antelopeql.svg)
1
+ ![antelopeql logo](https://raw.githubusercontent.com/pur3miish/antelopeql/main/static/antelopeql.svg)
2
2
 
3
3
  # AntelopeQL
4
4
 
5
5
  [![NPM Package](https://img.shields.io/npm/v/antelopeql.svg)](https://www.npmjs.org/package/antelopeql) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/pur3miish/antelopeql/blob/main/LICENSE)
6
6
 
7
- AntelopeQL is a [GraphQL](https://graphql.org/) implementation for interacting with [Antelope](https://antelope.io/) blockchains. Query and mutate your smart contracts with a GraphQL tool that provides comprehensive documentation about the entire blockchain.
7
+ AntelopeQL (_Antelope Query Language_)
8
8
 
9
- **For a live example of AntelopeQL GUI see: [antelope.relocke.io](https://antelope.relocke.io).**
9
+ AntelopeQL is a GraphQL client and server library that allows developers to interact with the Antelope blockchain using GraphQL. It provides a unified interface to communicate with different blockchains within the Antelope ecosystem, enabling developers to leverage the unique features and capabilities of each blockchain while still benefiting from a consistent development experience.
10
+
11
+ As a GraphQL client library, AntelopeQL simplifies the process of building and executing GraphQL queries and mutations, handling errors, and signing transactions. As a server library, it provides a framework for building GraphQL APIs that can interact with the Antelope blockchain and other data sources.
12
+
13
+ With AntelopeQL, developers can focus on building the frontend and business logic of their DApps, while relying on the library to handle the complexities of interacting with multiple blockchains in the Antelope ecosystem.
14
+
15
+ **For a live example of AntelopeQL GUI see: [antelopeql.relocke.io](https://antelopeql.relocke.io).**
10
16
 
11
17
  ![antelopeql screenshot](https://raw.githubusercontent.com/pur3miish/antelopeql/main/static/antelopeql-screen.png)
12
18