antelopeql 2.0.0-rc.2 → 2.0.0-rc.21
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 +9 -32
- package/blockchain/deserialize_action_data.mjs +5 -1
- package/blockchain/get_abi.mjs +5 -5
- package/blockchain/get_account.mjs +5 -18
- package/blockchain/get_accounts_by_authorizers.mjs +17 -6
- package/blockchain/get_block.mjs +5 -5
- package/blockchain/get_currency_balance.mjs +6 -3
- package/blockchain/get_currency_stats.mjs +5 -5
- package/blockchain/get_info.mjs +5 -1
- package/blockchain/get_producers.mjs +6 -2
- package/blockchain/get_ram_price.mjs +6 -6
- package/blockchain/get_required_keys.mjs +84 -11
- package/blockchain/get_smart_contract.mjs +5 -5
- package/blockchain/get_table_by_scope.mjs +11 -2
- package/blockchain_query_field.mjs +10 -11
- package/build_graphql_fields_from_abis.mjs +20 -9
- package/eosio_abi_to_graphql_ast.mjs +31 -29
- package/eosio_types/name_type.mjs +1 -1
- package/eosio_types/public_key_type.mjs +19 -5
- package/eosio_types/signature_type.mjs +1 -3
- package/eosio_types/symbol_type.mjs +1 -0
- package/graphql_input_types/actions.mjs +2 -2
- package/graphql_input_types/configuration.mjs +0 -6
- package/graphql_object_types/packed_transaction.mjs +82 -16
- package/mutation_resolver.mjs +6 -8
- package/package.json +20 -20
- package/query_resolver.mjs +3 -1
- package/readme.md +35 -61
- package/{push_serialized_transaction.mjs → send_serialized_transaction.mjs} +7 -6
- package/{push_transaction.mjs → send_transaction.mjs} +12 -6
- package/{push_transaction_rpc.mjs → send_transaction_rpc.mjs} +2 -2
- package/{blockchain/serialize_abi.mjs → serialize_abi.mjs} +62 -73
- package/serialize_transaction.mjs +15 -3
- package/blockchain/bandwidth_quote.mjs +0 -244
|
@@ -66,31 +66,26 @@ function handleStructs(structs) {
|
|
|
66
66
|
* @returns {Object} a GraphQL AST for a given smart contract.
|
|
67
67
|
*/
|
|
68
68
|
export function eosio_abi_to_graphql_ast(abi) {
|
|
69
|
-
const { types, variants } = abi;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}))
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (types?.length)
|
|
69
|
+
const { types, variants, structs } = abi;
|
|
70
|
+
const new_structs = structs;
|
|
71
|
+
|
|
72
|
+
if (variants?.length)
|
|
73
|
+
for (const { name, types: variant_types } of variants)
|
|
74
|
+
new_structs.push({
|
|
75
|
+
name,
|
|
76
|
+
base: "",
|
|
77
|
+
fields: variant_types.map((item) => ({ name: item, type: item + "$@" })) // @ indiacted a variant type and binary extention.
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (types?.length) {
|
|
83
81
|
for (const { type: real_type, new_type_name } of types)
|
|
84
|
-
|
|
85
|
-
...
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
: { name, type }
|
|
90
|
-
)
|
|
91
|
-
}));
|
|
82
|
+
new_structs.push({
|
|
83
|
+
...new_structs.find((x) => x.name == real_type),
|
|
84
|
+
name: new_type_name
|
|
85
|
+
});
|
|
86
|
+
}
|
|
92
87
|
|
|
93
|
-
const structs_ast = handleStructs(
|
|
88
|
+
const structs_ast = handleStructs(new_structs);
|
|
94
89
|
|
|
95
90
|
return Object.freeze(structs_ast);
|
|
96
91
|
}
|
|
@@ -117,7 +112,12 @@ function Wrap(type, { optional, list }) {
|
|
|
117
112
|
* @param {String} [account_name] Blockchain account name.
|
|
118
113
|
* @returns {Object} GraphQL query and mutation fields.
|
|
119
114
|
*/
|
|
120
|
-
export function get_graphql_fields_from_AST(
|
|
115
|
+
export function get_graphql_fields_from_AST(
|
|
116
|
+
AST,
|
|
117
|
+
ABI,
|
|
118
|
+
account_name = "",
|
|
119
|
+
chainName = ""
|
|
120
|
+
) {
|
|
121
121
|
const { tables, actions } = ABI;
|
|
122
122
|
const gql_account_name = account_name.replace(/\./gmu, "_") + "_";
|
|
123
123
|
|
|
@@ -127,6 +127,7 @@ export function get_graphql_fields_from_AST(AST, ABI, account_name = "") {
|
|
|
127
127
|
|
|
128
128
|
for (const table of tables) {
|
|
129
129
|
let { name: table_name, type: table_type } = table;
|
|
130
|
+
|
|
130
131
|
table_name = table_name.replace(/\./gmu, "_");
|
|
131
132
|
const table_fields = AST[table_type];
|
|
132
133
|
|
|
@@ -143,7 +144,7 @@ export function get_graphql_fields_from_AST(AST, ABI, account_name = "") {
|
|
|
143
144
|
if ($info.object) {
|
|
144
145
|
if (!GQL_TYPES[type])
|
|
145
146
|
GQL_TYPES[type] = new GraphQLObjectType({
|
|
146
|
-
name: gql_account_name + type,
|
|
147
|
+
name: gql_account_name + type + chainName,
|
|
147
148
|
fields: buildQGL(AST[type])
|
|
148
149
|
});
|
|
149
150
|
|
|
@@ -160,11 +161,11 @@ export function get_graphql_fields_from_AST(AST, ABI, account_name = "") {
|
|
|
160
161
|
return acc;
|
|
161
162
|
};
|
|
162
163
|
|
|
163
|
-
if (!queryTypes[table_type])
|
|
164
|
+
if (!queryTypes[table_type]) {
|
|
164
165
|
queryTypes[table_type] = {
|
|
165
166
|
type: new GraphQLList(
|
|
166
167
|
new GraphQLObjectType({
|
|
167
|
-
name: gql_account_name + table_type + "_query",
|
|
168
|
+
name: gql_account_name + table_type + "_query" + chainName,
|
|
168
169
|
fields: buildQGL(table_fields)
|
|
169
170
|
})
|
|
170
171
|
),
|
|
@@ -176,6 +177,7 @@ export function get_graphql_fields_from_AST(AST, ABI, account_name = "") {
|
|
|
176
177
|
},
|
|
177
178
|
resolve
|
|
178
179
|
};
|
|
180
|
+
}
|
|
179
181
|
|
|
180
182
|
query_fields[table_name] = queryTypes[table_type];
|
|
181
183
|
}
|
|
@@ -199,7 +201,7 @@ export function get_graphql_fields_from_AST(AST, ABI, account_name = "") {
|
|
|
199
201
|
if ($info.object) {
|
|
200
202
|
if (!GQL_MTYPES[type])
|
|
201
203
|
GQL_MTYPES[type] = new GraphQLInputObjectType({
|
|
202
|
-
name: gql_account_name + "input_" + type,
|
|
204
|
+
name: gql_account_name + "input_" + type + chainName,
|
|
203
205
|
fields: buildQGL(AST[type])
|
|
204
206
|
});
|
|
205
207
|
acc = { ...acc, [name]: { type: Wrap(GQL_MTYPES[type], $info) } };
|
|
@@ -212,7 +214,7 @@ export function get_graphql_fields_from_AST(AST, ABI, account_name = "") {
|
|
|
212
214
|
if (!mutationTypes[action_type]) {
|
|
213
215
|
mutationTypes[action_type] = {
|
|
214
216
|
type: new GraphQLInputObjectType({
|
|
215
|
-
name: gql_account_name + action_type,
|
|
217
|
+
name: gql_account_name + action_type + chainName,
|
|
216
218
|
description: ricardian_contract
|
|
217
219
|
.replace(/(https?|http|ftp):\/\/[^\s$.?#].[^\s]*$/gmu, "")
|
|
218
220
|
.replace(/icon:/gmu, "")
|
|
@@ -19,7 +19,7 @@ Names are unique identifiers on the blockchain.
|
|
|
19
19
|
parseValue(_name) {
|
|
20
20
|
if (_name == "") return _name;
|
|
21
21
|
|
|
22
|
-
if (!_name.match(/^[1-5a-z
|
|
22
|
+
if (!_name.match(/^[1-5a-z.]{0,11}[1-5a-z]{1}$/gmu))
|
|
23
23
|
throw new TypeError(`Invalid name “${_name}”.`);
|
|
24
24
|
|
|
25
25
|
return _name;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
+
import base58_to_binary from "base58-js/base58_to_binary.mjs";
|
|
2
|
+
import binary_to_base58 from "base58-js/binary_to_base58.mjs";
|
|
1
3
|
import { GraphQLScalarType } from "graphql";
|
|
4
|
+
import ripemd160 from "ripemd160-js/ripemd160.mjs";
|
|
2
5
|
|
|
3
6
|
const public_key_type = new GraphQLScalarType({
|
|
4
|
-
description: `\`Public key type\`
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
Public keys should begin with PUB_K1 (or EOS for legacy keys) and include base58 characters only.
|
|
8
|
-
`,
|
|
9
7
|
name: "public_key",
|
|
10
8
|
async parseValue(public_key) {
|
|
11
9
|
if (public_key == "") return "";
|
|
@@ -21,6 +19,22 @@ const public_key_type = new GraphQLScalarType({
|
|
|
21
19
|
);
|
|
22
20
|
|
|
23
21
|
return public_key;
|
|
22
|
+
},
|
|
23
|
+
async serialize(key) {
|
|
24
|
+
if (key.startsWith("EOS")) {
|
|
25
|
+
const public_key = base58_to_binary(key.replace(/^[A-Z]+/gmu, "")).slice(
|
|
26
|
+
0,
|
|
27
|
+
-4
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const hash = await ripemd160(Uint8Array.from([...public_key, 75, 49]));
|
|
31
|
+
const checksum = hash.slice(0, 4);
|
|
32
|
+
return (
|
|
33
|
+
"PUB_K1_" +
|
|
34
|
+
binary_to_base58(new Uint8Array([...public_key, ...checksum]))
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return key;
|
|
24
38
|
}
|
|
25
39
|
});
|
|
26
40
|
|
|
@@ -3,15 +3,13 @@ import { GraphQLScalarType } from "graphql";
|
|
|
3
3
|
const signature_type = new GraphQLScalarType({
|
|
4
4
|
description: `\`Signature type\`
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Antelope based signature, K1, R1 WA.`,
|
|
7
7
|
name: "signature",
|
|
8
8
|
parseValue(signature) {
|
|
9
9
|
if (signature == "") return "";
|
|
10
10
|
if (typeof signature !== "string")
|
|
11
11
|
throw new TypeError("Expected signature to be string");
|
|
12
12
|
|
|
13
|
-
if (signature.slice(0, 7) != "SIG_K1_")
|
|
14
|
-
throw new TypeError("Signature prefix is should be SIG_K1_.");
|
|
15
13
|
return signature;
|
|
16
14
|
}
|
|
17
15
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { GraphQLInputObjectType, GraphQLList, GraphQLNonNull } from "graphql";
|
|
2
2
|
|
|
3
|
-
const actions_type = (fields) =>
|
|
3
|
+
const actions_type = (fields, typeResolution = "") =>
|
|
4
4
|
new GraphQLNonNull(
|
|
5
5
|
new GraphQLList(
|
|
6
6
|
new GraphQLNonNull(
|
|
7
7
|
new GraphQLInputObjectType({
|
|
8
|
-
name: "actions_type",
|
|
8
|
+
name: "actions_type" + typeResolution,
|
|
9
9
|
fields
|
|
10
10
|
})
|
|
11
11
|
)
|
|
@@ -17,7 +17,6 @@ const configuration_default_value = {
|
|
|
17
17
|
* @param {Number} expireSeconds Seconds past before transaction is no longer valid (TaPoS protection)
|
|
18
18
|
* @param {Number} max_net_usage_words Maximum NET bandwidth usage a transaction can consume (0 there is no limit).
|
|
19
19
|
* @param {Number} max_cpu_usage_ms Maximum NET bandwidth usage a transaction can consume (0 there is no limit).
|
|
20
|
-
* @param {Number} delay_sec Number of seconds that the transaciton will be delayed by.
|
|
21
20
|
*/
|
|
22
21
|
const configuration_type = new GraphQLInputObjectType({
|
|
23
22
|
name: "configuration_type",
|
|
@@ -43,11 +42,6 @@ const configuration_type = new GraphQLInputObjectType({
|
|
|
43
42
|
description: `Maximum CPU bandwidth usage a transaction can consume, \nwhen set to 0 there is no limit`,
|
|
44
43
|
type: GraphQLInt,
|
|
45
44
|
defaultValue: configuration_default_value.max_cpu_usage_ms
|
|
46
|
-
},
|
|
47
|
-
delay_sec: {
|
|
48
|
-
type: GraphQLInt,
|
|
49
|
-
description: "Number of seconds that the transaciton will be delayed by",
|
|
50
|
-
defaultValue: configuration_default_value.delay_sec
|
|
51
45
|
}
|
|
52
46
|
})
|
|
53
47
|
});
|
|
@@ -1,4 +1,83 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GraphQLError, GraphQLList, GraphQLObjectType } from "graphql";
|
|
2
|
+
import sha256 from "universal-sha256-js/sha256.mjs";
|
|
3
|
+
|
|
4
|
+
import bytes_type from "../eosio_types/bytes_type.mjs";
|
|
5
|
+
import public_key_type from "../eosio_types/public_key_type.mjs";
|
|
6
|
+
|
|
7
|
+
export const packed_transaction_fields = {
|
|
8
|
+
chain_id: {
|
|
9
|
+
type: bytes_type,
|
|
10
|
+
description: "A unique ID that specifies which chain we are operating on."
|
|
11
|
+
},
|
|
12
|
+
transaction_header: {
|
|
13
|
+
type: bytes_type,
|
|
14
|
+
description: "Serialized transaction header."
|
|
15
|
+
},
|
|
16
|
+
transaction_body: {
|
|
17
|
+
type: bytes_type,
|
|
18
|
+
description: "Serialized transaction body _(bytecode instructions)_."
|
|
19
|
+
},
|
|
20
|
+
required_keys: {
|
|
21
|
+
type: new GraphQLList(public_key_type),
|
|
22
|
+
description: "List of public keys needed to authorize transaction",
|
|
23
|
+
async resolve({ available_keys, transaction }, args, getContext, info) {
|
|
24
|
+
const { network } = getContext(
|
|
25
|
+
{ available_keys, transaction },
|
|
26
|
+
args,
|
|
27
|
+
info
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
if (available_keys?.length) {
|
|
31
|
+
const keys = await Promise.all(available_keys);
|
|
32
|
+
|
|
33
|
+
const req = await fetch(
|
|
34
|
+
network.rpc_url + "/v1/chain/get_required_keys",
|
|
35
|
+
{
|
|
36
|
+
method: "post",
|
|
37
|
+
body: JSON.stringify({
|
|
38
|
+
transaction: {
|
|
39
|
+
...transaction,
|
|
40
|
+
// Transform the transaction.actions into appropriate form for get_required_keys.
|
|
41
|
+
actions: transaction.actions.map(({ hex_data, ...action }) => ({
|
|
42
|
+
...action,
|
|
43
|
+
data: hex_data
|
|
44
|
+
}))
|
|
45
|
+
},
|
|
46
|
+
available_keys: keys
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
).then((res) => res.json());
|
|
50
|
+
|
|
51
|
+
if (req.error)
|
|
52
|
+
throw new GraphQLError(req.message, { extensions: req.error });
|
|
53
|
+
return req.required_keys;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
hash: {
|
|
58
|
+
type: bytes_type,
|
|
59
|
+
description: "Transaction hash to sign to authorize transaction",
|
|
60
|
+
async resolve({ chain_id, transaction_header, transaction_body }) {
|
|
61
|
+
const transaction_bytes =
|
|
62
|
+
chain_id +
|
|
63
|
+
transaction_header +
|
|
64
|
+
transaction_body +
|
|
65
|
+
"0000000000000000000000000000000000000000000000000000000000000000";
|
|
66
|
+
|
|
67
|
+
const hash_to_sign = await sha256(
|
|
68
|
+
Uint8Array.from(
|
|
69
|
+
transaction_bytes
|
|
70
|
+
.match(/[a-fA-F0-9]{2}/gmu)
|
|
71
|
+
.map((i) => Number(`0x${i}`))
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return [...hash_to_sign]
|
|
76
|
+
.map((x) => Number(x).toString(16).padStart(2, "0"))
|
|
77
|
+
.join("");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
2
81
|
|
|
3
82
|
/**
|
|
4
83
|
* The packed transaction type.
|
|
@@ -8,25 +87,12 @@ import { GraphQLObjectType, GraphQLString } from "graphql";
|
|
|
8
87
|
* @prop {String} chain_id Hash representing the blockchain.
|
|
9
88
|
* @prop {String} transaction_header Hex string representing the serialized transaction header.
|
|
10
89
|
* @prop {String} transaction_body Hex string representing the serialized transaction body.
|
|
11
|
-
|
|
90
|
+
* @prop {String} transaction_body Hex string representing the serialized transaction body.
|
|
12
91
|
*/
|
|
13
92
|
const packed_transaction_type = new GraphQLObjectType({
|
|
14
93
|
name: "packed_transaction",
|
|
15
94
|
description: "Packed transaction, chain ID and transaction header",
|
|
16
|
-
fields:
|
|
17
|
-
chain_id: {
|
|
18
|
-
type: GraphQLString,
|
|
19
|
-
description: "A unique ID that specifies which chain we are operating on."
|
|
20
|
-
},
|
|
21
|
-
transaction_header: {
|
|
22
|
-
type: GraphQLString,
|
|
23
|
-
description: "Serialized transaction header."
|
|
24
|
-
},
|
|
25
|
-
transaction_body: {
|
|
26
|
-
type: GraphQLString,
|
|
27
|
-
description: "Serialized transaction body _(bytecode instructions)_."
|
|
28
|
-
}
|
|
29
|
-
}
|
|
95
|
+
fields: packed_transaction_fields
|
|
30
96
|
});
|
|
31
97
|
|
|
32
98
|
export default packed_transaction_type;
|
package/mutation_resolver.mjs
CHANGED
|
@@ -2,12 +2,11 @@ import serialize from "eosio-wasm-js/serialize.mjs";
|
|
|
2
2
|
import serialize_transaction_header from "eosio-wasm-js/transaction_header.mjs";
|
|
3
3
|
import { GraphQLError } from "graphql";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const default_config = {
|
|
6
6
|
blocksBehind: 3,
|
|
7
7
|
expireSeconds: 30,
|
|
8
8
|
max_net_usage_words: 0,
|
|
9
|
-
max_cpu_usage_ms: 0
|
|
10
|
-
delay_sec: 0
|
|
9
|
+
max_cpu_usage_ms: 0
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
const validate_actions = () => {
|
|
@@ -48,8 +47,7 @@ async function get_transaction_body(actions, ast_list) {
|
|
|
48
47
|
let _actions = [];
|
|
49
48
|
let _context_free_actions = [];
|
|
50
49
|
|
|
51
|
-
let transaction_extensions =
|
|
52
|
-
"000000000000000000000000000000000000000000000000000000000000000000";
|
|
50
|
+
let transaction_extensions = "00";
|
|
53
51
|
|
|
54
52
|
for (const action of actions_list_to_serialize) {
|
|
55
53
|
const {
|
|
@@ -164,7 +162,7 @@ async function get_transaction_body(actions, ast_list) {
|
|
|
164
162
|
* @returns {Object} Transaction object.
|
|
165
163
|
*/
|
|
166
164
|
async function mutation_resolver(
|
|
167
|
-
{ actions, configuration =
|
|
165
|
+
{ actions, configuration = default_config },
|
|
168
166
|
network,
|
|
169
167
|
ast_list
|
|
170
168
|
) {
|
|
@@ -213,10 +211,10 @@ async function mutation_resolver(
|
|
|
213
211
|
ref_block_prefix,
|
|
214
212
|
max_net_usage_words: configuration.max_net_usage_words,
|
|
215
213
|
max_cpu_usage_ms: configuration.max_cpu_usage_ms,
|
|
216
|
-
delay_sec:
|
|
214
|
+
delay_sec: 0
|
|
217
215
|
};
|
|
218
216
|
|
|
219
|
-
// Generates a transaction header for a
|
|
217
|
+
// Generates a transaction header for a Antelope transaction.
|
|
220
218
|
const transaction_header = serialize_transaction_header(txn_header);
|
|
221
219
|
txn_header.expiration = timestamp;
|
|
222
220
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "antelopeql",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.21",
|
|
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",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"eslint": "eslint .",
|
|
12
12
|
"prettier": "prettier -c .",
|
|
13
13
|
"prettier:readme": "prettier --write readme.md",
|
|
14
|
+
"server": "nodemon test/server.mjs",
|
|
14
15
|
"types": "tsc -p jsconfig.json",
|
|
15
16
|
"snapshot": "SAVE_SNAPSHOTS=1 coverage-node test/index.test.mjs",
|
|
16
17
|
"coverage": "coverage-node test/index.test.mjs",
|
|
@@ -19,26 +20,27 @@
|
|
|
19
20
|
"prepublishOnly": "npm test"
|
|
20
21
|
},
|
|
21
22
|
"engines": {
|
|
22
|
-
"node": "
|
|
23
|
+
"node": ">= 18.0.0"
|
|
23
24
|
},
|
|
24
25
|
"files": [
|
|
25
26
|
"blockchain/*.mjs",
|
|
26
27
|
"eosio_types/*.mjs",
|
|
27
28
|
"graphql_input_types/*.mjs",
|
|
28
29
|
"graphql_object_types/*.mjs",
|
|
30
|
+
"antelopeql.mjs",
|
|
29
31
|
"blockchain_query_field.mjs",
|
|
30
32
|
"build_graphql_fields_from_abis.mjs",
|
|
31
33
|
"eosio_abi_to_graphql_ast.mjs",
|
|
32
34
|
"eosio_types.mjs",
|
|
35
|
+
"get_abis.mjs",
|
|
33
36
|
"mutation_resolver.mjs",
|
|
34
|
-
"push_serialized_transaction.mjs",
|
|
35
|
-
"push_transaction_rpc.mjs",
|
|
36
|
-
"push_transaction.mjs",
|
|
37
37
|
"query_resolver.mjs",
|
|
38
|
+
"send_serialized_transaction.mjs",
|
|
39
|
+
"send_transaction_rpc.mjs",
|
|
40
|
+
"send_transaction.mjs",
|
|
41
|
+
"serialize_abi.mjs",
|
|
38
42
|
"serialize_transaction.mjs",
|
|
39
|
-
"
|
|
40
|
-
"types.mjs",
|
|
41
|
-
"get_abis.mjs"
|
|
43
|
+
"types.mjs"
|
|
42
44
|
],
|
|
43
45
|
"sideEffects": false,
|
|
44
46
|
"exports": {
|
|
@@ -46,19 +48,20 @@
|
|
|
46
48
|
"./eosio_types/*.mjs": "./eosio_types/*.mjs",
|
|
47
49
|
"./graphql_input_types/*.mjs": "./graphql_input_types/*.mjs",
|
|
48
50
|
"./graphql_object_types/*.mjs": "./graphql_object_types/*.mjs",
|
|
51
|
+
"./antelopeql.mjs": "./antelopeql.mjs",
|
|
49
52
|
"./blockchain_query_field.mjs": "./blockchain_query_field.mjs",
|
|
50
53
|
"./build_graphql_fields_from_abis.mjs": "./build_graphql_fields_from_abis.mjs",
|
|
51
54
|
"./eosio_abi_to_graphql_ast.mjs": "./eosio_abi_to_graphql_ast.mjs",
|
|
52
55
|
"./eosio_types.mjs": "./eosio_types.mjs",
|
|
56
|
+
"./get_abis.mjs": "./get_abis.mjs",
|
|
53
57
|
"./mutation_resolver.mjs": "./mutation_resolver.mjs",
|
|
54
|
-
"./push_serialized_transaction.mjs": "./push_serialized_transaction.mjs",
|
|
55
|
-
"./push_transaction_rpc.mjs": "./push_transaction_rpc.mjs",
|
|
56
|
-
"./push_transaction.mjs": "./push_transaction.mjs",
|
|
57
58
|
"./query_resolver.mjs": "./query_resolver.mjs",
|
|
59
|
+
"./send_serialized_transaction.mjs": "./send_serialized_transaction.mjs",
|
|
60
|
+
"./send_transaction_rpc.mjs": "./send_transaction_rpc.mjs",
|
|
61
|
+
"./send_transaction.mjs": "./send_transaction.mjs",
|
|
62
|
+
"./serialize_abi.mjs": "./serialize_abi.mjs",
|
|
58
63
|
"./serialize_transaction.mjs": "./serialize_transaction.mjs",
|
|
59
|
-
"./
|
|
60
|
-
"./types.mjs": "./types.mjs",
|
|
61
|
-
"./get_abis.mjs": "./get_abis.mjs"
|
|
64
|
+
"./types.mjs": "./types.mjs"
|
|
62
65
|
},
|
|
63
66
|
"browserslist": [
|
|
64
67
|
"> 0.5%, not OperaMini all, not IE > 0, not dead"
|
|
@@ -76,20 +79,17 @@
|
|
|
76
79
|
],
|
|
77
80
|
"devDependencies": {
|
|
78
81
|
"@types/node": "^18.13.0",
|
|
82
|
+
"antelope-ecc": "^2.0.0-rc.7",
|
|
79
83
|
"coverage-node": "^8.0.0",
|
|
80
84
|
"eslint": "^8.34.0",
|
|
81
85
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
82
|
-
"graphql": "^16.
|
|
83
|
-
"
|
|
84
|
-
"nodemon": "^2.0.20",
|
|
86
|
+
"graphql": "^16.8.0",
|
|
87
|
+
"nodemon": "^3.0.1",
|
|
85
88
|
"prettier": "^2.8.4",
|
|
86
89
|
"snapshot-assertion": "^5.0.0",
|
|
87
90
|
"test-director": "^10.0.0",
|
|
88
91
|
"typescript": "^4.9.5"
|
|
89
92
|
},
|
|
90
|
-
"peerDependencies": {
|
|
91
|
-
"graphql": "^16.6.0"
|
|
92
|
-
},
|
|
93
93
|
"dependencies": {
|
|
94
94
|
"base58-js": "^2.0.0",
|
|
95
95
|
"eosio-wasm-js": "^4.1.1",
|
package/query_resolver.mjs
CHANGED
|
@@ -14,9 +14,11 @@ import { GraphQLError } from "graphql";
|
|
|
14
14
|
export default async function query_resolver(
|
|
15
15
|
{ code },
|
|
16
16
|
{ arg },
|
|
17
|
-
|
|
17
|
+
getContext,
|
|
18
18
|
info
|
|
19
19
|
) {
|
|
20
|
+
const { network } = getContext({ code }, { arg }, info);
|
|
21
|
+
|
|
20
22
|
const { fetch, rpc_url, ...fetchOptions } = network;
|
|
21
23
|
const { fieldName: query_name } = info;
|
|
22
24
|
const table = query_name.replace(/_/gmu, ".");
|
package/readme.md
CHANGED
|
@@ -31,42 +31,35 @@ See the examples folder on how to run AntelopeQL as a [Node.js](https://nodejs.o
|
|
|
31
31
|
### Query a blockchain account
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
|
-
import fetch from "node-fetch";
|
|
35
34
|
import AntelopeQL from "antelopeql/antelopeql.mjs";
|
|
36
35
|
|
|
37
|
-
const { data } = await AntelopeQL(
|
|
38
|
-
{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
const { data } = await AntelopeQL({
|
|
37
|
+
query: /*GraphQL*/ `{
|
|
38
|
+
blockchain{
|
|
39
|
+
get_account(account_name:"relockeblock") {
|
|
40
|
+
core_liquid_balance
|
|
41
|
+
ram_quota
|
|
42
|
+
net_weight
|
|
43
|
+
cpu_weight
|
|
44
|
+
ram_usage
|
|
45
|
+
permissions {
|
|
46
|
+
linked_actions {
|
|
47
|
+
account
|
|
48
|
+
action
|
|
49
|
+
}
|
|
50
|
+
required_auth {
|
|
51
|
+
keys {
|
|
52
|
+
key
|
|
53
|
+
weight
|
|
54
|
+
}
|
|
55
|
+
threshold
|
|
56
56
|
}
|
|
57
|
-
threshold
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
rpc_url: "https://jungle.relocke.io",
|
|
65
|
-
headers: {
|
|
66
|
-
"content-type": "application/json"
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
);
|
|
60
|
+
}`,
|
|
61
|
+
rpc_url: "https://jungle.relocke.io"
|
|
62
|
+
});
|
|
70
63
|
|
|
71
64
|
console.log(data);
|
|
72
65
|
```
|
|
@@ -76,13 +69,13 @@ console.log(data);
|
|
|
76
69
|
### Transfer EOS cryptocurrency
|
|
77
70
|
|
|
78
71
|
```js
|
|
79
|
-
import fetch from "node-fetch";
|
|
80
72
|
import AntelopeQL from "antelopeql/antelopeql.mjs";
|
|
73
|
+
import sign_txn from "antelopeql-ecc/sign_txn.mjs";
|
|
81
74
|
|
|
82
75
|
const { data } = await AntelopeQL({
|
|
83
76
|
query: /*GraphQL*/ `
|
|
84
|
-
|
|
85
|
-
|
|
77
|
+
mutation {
|
|
78
|
+
send_transaction(actions: [{
|
|
86
79
|
eosio_token:{
|
|
87
80
|
transfer: {
|
|
88
81
|
authorization:{
|
|
@@ -98,18 +91,14 @@ const { data } = await AntelopeQL({
|
|
|
98
91
|
transaction_id
|
|
99
92
|
block_num
|
|
100
93
|
}
|
|
101
|
-
|
|
102
|
-
contracts: ["eosio.token"],
|
|
103
|
-
signTransaction: async () => {
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
return
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
rpc_url: "https://eos.relocke.io", // eos blockchain.
|
|
110
|
-
headers: {
|
|
111
|
-
"content-type": "application/json"
|
|
112
|
-
}
|
|
94
|
+
}`,
|
|
95
|
+
contracts: ["eosio.token", "eosio"], // List of smart contracts
|
|
96
|
+
signTransaction: async (hash) => {
|
|
97
|
+
const wif_private_key = "PVT_K1_…"; // your private key
|
|
98
|
+
const signature = await sign_txn({ hash, wif_private_key });
|
|
99
|
+
return [signature]; // signaures must return array
|
|
100
|
+
},
|
|
101
|
+
rpc_url: "https://eos.relocke.io" // eos blockchain url.
|
|
113
102
|
});
|
|
114
103
|
|
|
115
104
|
console.log(data);
|
|
@@ -134,24 +123,9 @@ console.log(data);
|
|
|
134
123
|
|
|
135
124
|
Supported runtime environments:
|
|
136
125
|
|
|
137
|
-
- [Node.js](https://nodejs.org) versions `>=
|
|
126
|
+
- [Node.js](https://nodejs.org) versions `>=18.0.0`.
|
|
138
127
|
- Browsers matching the [Browserslist](https://browsersl.ist) query [`> 0.5%, not OperaMini all, not dead`](https://browsersl.ist/?q=%3E+0.5%25%2C+not+OperaMini+all%2C+not+dead).
|
|
139
|
-
- [Deno](https://deno.land) version `>=1.30.0`.
|
|
140
128
|
|
|
141
129
|
## Exports
|
|
142
130
|
|
|
143
131
|
The [npm](https://npmjs.com) package [`AntelopeQL`](https://npm.im/antelopeql) features [optimal JavaScript module design](https://jaydenseric.com/blog/optimal-javascript-module-design). It doesn’t have a main index module, so use deep imports from the ECMAScript modules that are exported via the [`package.json`](./package.json) field [`exports`](https://nodejs.org/api/packages.html#exports):
|
|
144
|
-
|
|
145
|
-
- [`antelopeql.mjs`](./antelopeql.mjs)
|
|
146
|
-
- [`blockchain_query_field.mjs`](blockchain_query_field.mjs)
|
|
147
|
-
- [`build_graphql_fields_from_abis.mjs`](build_graphql_fields_from_abis.mjs)
|
|
148
|
-
- [`eosio_abi_to_graphql_ast.mjs`](eosio_abi_to_graphql_ast.mjs)
|
|
149
|
-
- [`eosio_types.mjs`](eosio_types.mjs)
|
|
150
|
-
- [`mutation_resolver.mjs`](mutation_resolver.mjs)
|
|
151
|
-
- [`push_serialized_transaction.mjs`](push_serialized_transaction.mjs)
|
|
152
|
-
- [`push_transaction_rpc.mjs`](push_transaction_rpc.mjs)
|
|
153
|
-
- [`push_transaction.mjs`](push_transaction.mjs)
|
|
154
|
-
- [`query_resolver.mjs`](query_resolver.mjs)
|
|
155
|
-
- [`serialize_transaction.mjs`](serialize_transaction.mjs)
|
|
156
|
-
- [`antelopeql.mjs`](antelopeql.mjs)
|
|
157
|
-
- [`types.mjs`](types.mjs)
|
|
@@ -3,22 +3,23 @@ import { GraphQLList, GraphQLNonNull } from "graphql";
|
|
|
3
3
|
import bytes_type from "./eosio_types/bytes_type.mjs";
|
|
4
4
|
import signature_type from "./eosio_types/signature_type.mjs";
|
|
5
5
|
import transaction_receipt from "./graphql_object_types/transaction_receipt.mjs";
|
|
6
|
-
import
|
|
6
|
+
import send_transaction_rpc from "./send_transaction_rpc.mjs";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Push transaction type.
|
|
10
10
|
*/
|
|
11
|
-
const
|
|
12
|
-
description: "
|
|
11
|
+
const send_serialized_transaction = {
|
|
12
|
+
description: "Sends a serialized transaction to the blockchain.",
|
|
13
13
|
type: new GraphQLNonNull(transaction_receipt),
|
|
14
14
|
args: {
|
|
15
15
|
transaction_header: { type: new GraphQLNonNull(bytes_type) },
|
|
16
16
|
transaction_body: { type: new GraphQLNonNull(bytes_type) },
|
|
17
17
|
signaures: { type: new GraphQLNonNull(new GraphQLList(signature_type)) }
|
|
18
18
|
},
|
|
19
|
-
resolve(
|
|
20
|
-
|
|
19
|
+
resolve(root, args, getContext, info) {
|
|
20
|
+
const { network } = getContext(root, args, info);
|
|
21
|
+
return send_transaction_rpc(args, network);
|
|
21
22
|
}
|
|
22
23
|
};
|
|
23
24
|
|
|
24
|
-
export default
|
|
25
|
+
export default send_serialized_transaction;
|