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
@@ -0,0 +1,33 @@
1
+ import { GraphQLScalarType } from "graphql";
2
+
3
+ const symbol_type = new GraphQLScalarType({
4
+ description: `\`Symbol type\`
5
+
6
+ ---
7
+
8
+ An eosio symbol is an all uppercase string of 7 or less characters from [A-Z].
9
+
10
+ ### Symbol rules
11
+
12
+ - Ends with a symbol up to 7 characters long
13
+ - Symbol must be uppercase
14
+ - Maximum value (2^62 - 1)
15
+ - Maximum decimal precision of 18
16
+
17
+ `,
18
+ name: "symbol",
19
+ parseValue: (symbol) => {
20
+ if (!symbol.match(/^[0-9]{1,2},[A-Z]{1,7}$/gmu))
21
+ throw new Error(
22
+ "Invalid symbol format, correct format is <precision,code>"
23
+ );
24
+ const [precision] = symbol.split(",");
25
+
26
+ if (!(precision > -1 && precision < 18))
27
+ throw new RangeError("Invalid symbol precision, maximum 18");
28
+
29
+ return symbol;
30
+ }
31
+ });
32
+
33
+ export default symbol_type;
@@ -0,0 +1,12 @@
1
+ import { GraphQLScalarType } from "graphql";
2
+
3
+ const time_point_sec_type = new GraphQLScalarType({
4
+ description: `\`time point sec\`
5
+
6
+ Number of seconds since epoch (Unix time).
7
+ `,
8
+ name: "time_point_sec",
9
+ parseValue: (time) => time
10
+ });
11
+
12
+ export default time_point_sec_type;
@@ -0,0 +1,12 @@
1
+ import { GraphQLScalarType } from "graphql";
2
+
3
+ const time_point_type = new GraphQLScalarType({
4
+ description: `\`time point\`
5
+
6
+ Number of milliseconds since epoch (Unix time).
7
+ `,
8
+ name: "time_point",
9
+ parseValue: (time) => time
10
+ });
11
+
12
+ export default time_point_type;
@@ -0,0 +1,13 @@
1
+ import { GraphQLScalarType } from "graphql";
2
+
3
+ const varuint32_type = new GraphQLScalarType({
4
+ description: `\`varint32\`
5
+
6
+ A Signed LEB128 variable-length integer, limited to 32 bits (i.e., the values [-2^(32-1), +2^(32-1)-1]), represented by at most ceil(32/7) bytes that may contain padding 0x80 or 0xFF bytes.
7
+
8
+ `,
9
+ name: "varint32",
10
+ parseValue: (varint32) => varint32
11
+ });
12
+
13
+ export default varuint32_type;
@@ -0,0 +1,12 @@
1
+ import { GraphQLScalarType } from "graphql";
2
+
3
+ const varuint32_type = new GraphQLScalarType({
4
+ description: `\`varuint32\`
5
+
6
+ A LEB128 variable-length integer, limited to 32 bits (i.e., the values [0, 2^32-1]), represented by at most ceil(32/7) bytes that may contain padding 0x80 bytes.
7
+ `,
8
+ name: "varuint32",
9
+ parseValue: (varuint32) => varuint32
10
+ });
11
+
12
+ export default varuint32_type;
@@ -0,0 +1,59 @@
1
+ import { GraphQLString } from "graphql";
2
+
3
+ import asset from "./eosio_types/asset_type.mjs";
4
+ import block_timestamp_type from "./eosio_types/block_timestamp_type.mjs";
5
+ import bool from "./eosio_types/boolean_type.mjs";
6
+ import bytes from "./eosio_types/bytes_type.mjs";
7
+ import extended_asset from "./eosio_types/extended_asset_type.mjs";
8
+ import generate_checksum from "./eosio_types/generate_checksum_type.mjs";
9
+ import generate_float_type from "./eosio_types/generate_float_type.mjs";
10
+ import generate_int_type from "./eosio_types/generate_int_type.mjs";
11
+ import generate_uint_type from "./eosio_types/generate_uint_type.mjs";
12
+ import name from "./eosio_types/name_type.mjs";
13
+ import public_key from "./eosio_types/public_key_type.mjs";
14
+ import signature from "./eosio_types/signature_type.mjs";
15
+ import symbol_code from "./eosio_types/symbol_code_type.mjs";
16
+ import symbol from "./eosio_types/symbol_type.mjs";
17
+ import time_point_sec from "./eosio_types/time_point_sec_type.mjs";
18
+ import time_point from "./eosio_types/time_point_type.mjs";
19
+ import varint32 from "./eosio_types/varint32_type.mjs";
20
+ import varuint32 from "./eosio_types/varuint32_type.mjs";
21
+
22
+ /**
23
+ * An object containing EOSIO native types.
24
+ */
25
+ const eosio_types = {
26
+ asset,
27
+ block_timestamp_type,
28
+ bool,
29
+ bytes,
30
+ checksum160: generate_checksum(20),
31
+ checksum256: generate_checksum(32),
32
+ checksum512: generate_checksum(64),
33
+ extended_asset,
34
+ float32: generate_float_type(32),
35
+ float64: generate_float_type(64),
36
+ float128: generate_float_type(128),
37
+ int8: generate_int_type(8),
38
+ int16: generate_int_type(16),
39
+ int32: generate_int_type(32),
40
+ int64: generate_int_type(64),
41
+ int128: generate_int_type(128),
42
+ name,
43
+ public_key,
44
+ signature,
45
+ string: GraphQLString,
46
+ symbol,
47
+ symbol_code,
48
+ time_point,
49
+ time_point_sec,
50
+ uint8: generate_uint_type(8),
51
+ uint16: generate_uint_type(16),
52
+ uint32: generate_uint_type(32),
53
+ uint64: generate_uint_type(64),
54
+ uint128: generate_uint_type(128),
55
+ varint32,
56
+ varuint32
57
+ };
58
+
59
+ export default eosio_types;
@@ -0,0 +1,15 @@
1
+ import { GraphQLInputObjectType, GraphQLList, GraphQLNonNull } from "graphql";
2
+
3
+ const actions_type = (fields) =>
4
+ new GraphQLNonNull(
5
+ new GraphQLList(
6
+ new GraphQLNonNull(
7
+ new GraphQLInputObjectType({
8
+ name: "actions_type",
9
+ fields
10
+ })
11
+ )
12
+ )
13
+ );
14
+
15
+ export default actions_type;
@@ -0,0 +1,30 @@
1
+ import { GraphQLInputObjectType, GraphQLNonNull } from "graphql";
2
+
3
+ import name_type from "../eosio_types/name_type.mjs";
4
+
5
+ /**
6
+ * The action authorization type for action validation.
7
+ * @kind typedef
8
+ * @name authorization
9
+ * @type {Object}
10
+ * @prop {String} actor Name of the account that is trying to authorize.
11
+ * @prop {String} permission Name of the `permission` of the the `actor`
12
+ */
13
+
14
+ const authorization_type = new GraphQLInputObjectType({
15
+ name: "authorization",
16
+ description: "Authorization object type.",
17
+ fields: () => ({
18
+ actor: {
19
+ description: "The name of the account name to sign the transaction.",
20
+ type: new GraphQLNonNull(name_type)
21
+ },
22
+ permission: {
23
+ description: "The name of the account permission.",
24
+ type: name_type,
25
+ defaultValue: "active"
26
+ }
27
+ })
28
+ });
29
+
30
+ export default authorization_type;
@@ -0,0 +1,55 @@
1
+ // @ts-check
2
+
3
+ import { GraphQLInputObjectType, GraphQLInt } from "graphql";
4
+
5
+ const configuration_default_value = {
6
+ blocksBehind: 3,
7
+ expireSeconds: 30,
8
+ max_net_usage_words: 0,
9
+ max_cpu_usage_ms: 0,
10
+ delay_sec: 0
11
+ };
12
+
13
+ /**
14
+ * Handles various elements relating to the `EOSIO` transaction.
15
+ * @typedef {Object} configuration_type
16
+ * @param {Number} blocksBehind Number of blocks behind the current block (TaPoS protection).
17
+ * @param {Number} expireSeconds Seconds past before transaction is no longer valid (TaPoS protection)
18
+ * @param {Number} max_net_usage_words Maximum NET bandwidth usage a transaction can consume (0 there is no limit).
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
+ */
22
+ const configuration_type = new GraphQLInputObjectType({
23
+ name: "configuration_type",
24
+ description:
25
+ "Configuration input to control various aspects of the transaction.",
26
+ fields: () => ({
27
+ blocksBehind: {
28
+ description: "Number of blocks behind the current block",
29
+ type: GraphQLInt,
30
+ defaultValue: configuration_default_value.blocksBehind
31
+ },
32
+ expireSeconds: {
33
+ description: "Seconds past before transaction is no longer valid",
34
+ type: GraphQLInt,
35
+ defaultValue: configuration_default_value.expireSeconds
36
+ },
37
+ max_net_usage_words: {
38
+ description: `Maximum NET bandwidth usage a transaction can consume, \nwhen set to 0 there is no limit`,
39
+ type: GraphQLInt,
40
+ defaultValue: configuration_default_value.max_net_usage_words
41
+ },
42
+ max_cpu_usage_ms: {
43
+ description: `Maximum CPU bandwidth usage a transaction can consume, \nwhen set to 0 there is no limit`,
44
+ type: GraphQLInt,
45
+ 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
+ }
52
+ })
53
+ });
54
+
55
+ export default configuration_type;
@@ -0,0 +1,82 @@
1
+ import {
2
+ GraphQLEnumType,
3
+ GraphQLInputObjectType,
4
+ GraphQLInt,
5
+ GraphQLString
6
+ } from "graphql";
7
+
8
+ const index_position_enum_type = new GraphQLEnumType({
9
+ name: "index_position_enum_type",
10
+ values: {
11
+ primary: { value: "primary" },
12
+ secondary: { value: "secondary" }
13
+ }
14
+ });
15
+
16
+ const key_type_enum_type = new GraphQLEnumType({
17
+ name: "key_type_enum",
18
+ description: `Primary only supports i64. All others support i64, i128, i256, float64, float128, ripemd160, sha256.`,
19
+ values: {
20
+ name: { value: "name", description: "Indicates an account name." },
21
+ i64: { value: "i64" },
22
+ i128: { value: "i128" },
23
+ i256: { value: "i256" },
24
+ float64: { value: "float64" },
25
+ float128: { value: "float128" },
26
+ ripemd160: { value: "ripemd160" },
27
+ sha256: { value: "sha256" }
28
+ }
29
+ });
30
+
31
+ const encode_type_enum_type = new GraphQLEnumType({
32
+ name: "encode_type_enum",
33
+ description: `
34
+ \`dec\` for decimal encoding of (i[64|128|256] and float[64|128])
35
+ \`hex\` for hexadecimal encoding of (i256, ripemd160, sha256).`,
36
+ values: {
37
+ dec: { value: "dec" },
38
+ hex: { value: "hex" }
39
+ }
40
+ });
41
+
42
+ const query_arg_fields = new GraphQLInputObjectType({
43
+ name: "arguments",
44
+ fields: {
45
+ scope: {
46
+ type: GraphQLString,
47
+ description: `The scope within the table to query data from.`,
48
+ defaultValue: ""
49
+ },
50
+ index_position: {
51
+ type: index_position_enum_type,
52
+ description: "Position of the index used.",
53
+ defaultValue: "primary"
54
+ },
55
+ key_type: {
56
+ type: key_type_enum_type,
57
+ description: "The key type of `index_position`",
58
+ defaultValue: "name"
59
+ },
60
+ encode_type: {
61
+ type: encode_type_enum_type,
62
+ description: "`key_type` encoding",
63
+ defaultValue: "dec"
64
+ },
65
+ upper_bound: {
66
+ type: GraphQLString,
67
+ description:
68
+ "Filters results to return the first element that is greater than provided value in set."
69
+ },
70
+ lower_bound: {
71
+ type: GraphQLString,
72
+ description:
73
+ "Filters results to return the first element that is not less than provided value in set."
74
+ },
75
+ limit: {
76
+ type: GraphQLInt,
77
+ description: "The maximum number of items to return"
78
+ }
79
+ }
80
+ });
81
+
82
+ export default query_arg_fields;
@@ -0,0 +1,15 @@
1
+ import { GraphQLObjectType, GraphQLString } from "graphql";
2
+
3
+ const authorization_type = new GraphQLObjectType({
4
+ name: "authorization_type",
5
+ fields: () => ({
6
+ actor: {
7
+ type: GraphQLString
8
+ },
9
+ permission: {
10
+ type: GraphQLString
11
+ }
12
+ })
13
+ });
14
+
15
+ export default authorization_type;
@@ -0,0 +1,15 @@
1
+ import { GraphQLNonNull, GraphQLObjectType, GraphQLString } from "graphql";
2
+
3
+ const authorizing_account_type = new GraphQLObjectType({
4
+ name: "authorizing_account_type",
5
+ fields: () => ({
6
+ actor: {
7
+ type: new GraphQLNonNull(GraphQLString)
8
+ },
9
+ permission: {
10
+ type: GraphQLString
11
+ }
12
+ })
13
+ });
14
+
15
+ export default authorizing_account_type;
@@ -0,0 +1,32 @@
1
+ import { GraphQLObjectType, GraphQLString } from "graphql";
2
+
3
+ /**
4
+ * The packed transaction type.
5
+ * @kind typedef
6
+ * @name packed_transaction
7
+ * @type {Object}
8
+ * @prop {String} chain_id Hash representing the blockchain.
9
+ * @prop {String} transaction_header Hex string representing the serialized transaction header.
10
+ * @prop {String} transaction_body Hex string representing the serialized transaction body.
11
+
12
+ */
13
+ const packed_transaction_type = new GraphQLObjectType({
14
+ name: "packed_transaction",
15
+ 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 _(TaPoS protection)_."
24
+ },
25
+ transaction_body: {
26
+ type: GraphQLString,
27
+ description: "Serialized transaction body _(bytecode instructions)_."
28
+ }
29
+ }
30
+ });
31
+
32
+ export default packed_transaction_type;
@@ -0,0 +1,159 @@
1
+ import {
2
+ GraphQLBoolean,
3
+ GraphQLEnumType,
4
+ GraphQLID,
5
+ GraphQLInt,
6
+ GraphQLList,
7
+ GraphQLObjectType,
8
+ GraphQLString
9
+ } from "graphql";
10
+
11
+ import name_type from "../eosio_types/name_type.mjs";
12
+ import authorizing_account_type from "./authorization.mjs";
13
+
14
+ /**
15
+ * @typedef {Enumerator} Transaction_status
16
+ * @prop {String} executed succeed, no error handler executed.
17
+ * @prop {String} soft_fail objectively failed (not executed), error handler executed.
18
+ * @prop {String} hard_fail objectively failed and error handler objectively failed thus no state change.
19
+ * @prop {String} delayed transaction delayed/deferred/scheduled for future execution.
20
+ * @prop {String} expired transaction expired and storage space refunded to user.
21
+ */
22
+ const transaction_status = new GraphQLEnumType({
23
+ name: "transaction_receipt_status",
24
+ description: `Describes the status of the transaction.`,
25
+ values: {
26
+ executed: {
27
+ value: "executed",
28
+ description: "succeed, no error handler executed"
29
+ },
30
+ soft_fail: {
31
+ value: "soft_fail",
32
+ description: "objectively failed (not executed), error handler executed"
33
+ },
34
+ hard_fail: {
35
+ value: "hard_fail",
36
+ description:
37
+ "objectively failed and error handler objectively failed thus no state change"
38
+ },
39
+ delayed: {
40
+ value: "delayed",
41
+ description: "transaction delayed/deferred/scheduled for future execution"
42
+ },
43
+ expired: {
44
+ value: "expired",
45
+ description: "transaction expired and storage space refunded to user"
46
+ }
47
+ }
48
+ });
49
+
50
+ /**
51
+ * Bandwidth reciept for EOSIO transaction.
52
+ * @typedef {Object} Bandwidth_cost
53
+ * @prop {Number} net_usage_words Consumption of network bandwidth (bytes).
54
+ * @prop {Number} cpu_usage_us Consumption of CPU bandwidth (µs).
55
+ * @prop {Transaction_status} status Transaction receipt status Enum.
56
+ */
57
+ const bandwidth_cost_type = new GraphQLObjectType({
58
+ name: "bandwidth_cost",
59
+ fields: () => ({
60
+ cpu_usage_us: {
61
+ type: GraphQLInt,
62
+ resolve: ({ cpu_usage_us }) => cpu_usage_us
63
+ },
64
+ net_usage_words: {
65
+ type: GraphQLInt,
66
+ resolve: ({ net_usage_words }) => net_usage_words
67
+ },
68
+ status: {
69
+ type: transaction_status
70
+ }
71
+ })
72
+ });
73
+
74
+ const action_trace_type = new GraphQLObjectType({
75
+ name: "action_trace",
76
+ description: "list of actions that the transaction includes.",
77
+ fields: () => ({
78
+ account: {
79
+ type: name_type,
80
+ description: "Contract name of the action you are calling.",
81
+ resolve: ({ act }) => act.account
82
+ },
83
+ name: {
84
+ type: name_type,
85
+ description: "The action name of the contract.",
86
+ resolve: ({ act }) => act.name
87
+ },
88
+ authorization: {
89
+ type: new GraphQLList(authorizing_account_type),
90
+ description: "Action authorization",
91
+ resolve: ({ act }) => act.authorization
92
+ },
93
+ data: {
94
+ type: GraphQLString,
95
+ description: "JSON representation of the action data.",
96
+ resolve: ({ act }) => JSON.stringify(act.data)
97
+ },
98
+ inline_traces: {
99
+ description: "Inline action trace.",
100
+ type: new GraphQLList(action_trace_type),
101
+ resolve: ({ inline_traces }) => inline_traces
102
+ }
103
+ })
104
+ });
105
+
106
+ /**
107
+ * @typedef {Object} transaction_receipt
108
+ * @type {Object}
109
+ * @prop {String} transaction_id ID of the transaction.
110
+ * @prop {Number} block_num Block number where teh transaction can be found.
111
+ * @prop {Stiring} block_time The time of the transaction.
112
+ * @prop {String} producer_block_id The block producer ID that processed the transaction.
113
+ * @prop {Bandwidth_cost} resource_cost Network cost for the transaction.
114
+ * @prop {Boolean} scheduled Scheduled transactions are executed at a later time.
115
+ */
116
+ const transaction_receipt_type = new GraphQLObjectType({
117
+ name: "transaction_receipt",
118
+ description: "Receipt for the action (mutation) for a blockchain transaction",
119
+ fields: () => ({
120
+ transaction_id: {
121
+ type: GraphQLID,
122
+ description: "`eosio` blockchain transaction id “reciept”"
123
+ },
124
+ block_num: {
125
+ type: GraphQLInt,
126
+ description: "What block the transaction is located in",
127
+ resolve: ({ processed }) => processed.block_num
128
+ },
129
+ block_time: {
130
+ type: GraphQLString,
131
+ description: "transaction time (GMT)",
132
+ resolve: ({ processed }) => processed.block_time
133
+ },
134
+ producer_block_id: {
135
+ type: GraphQLString,
136
+ description: "Block producer ID that processed the transaction.",
137
+ resolve: ({ processed }) => processed.producer_block_id
138
+ },
139
+ resource_cost: {
140
+ description:
141
+ "A resource object for the network cost of running the transaction",
142
+ type: bandwidth_cost_type,
143
+ resolve: ({ processed }) => processed.receipt
144
+ },
145
+ scheduled: {
146
+ type: GraphQLBoolean,
147
+ description: "Scheduled transactions are executed at a later time.",
148
+ resolve: ({ processed }) => processed.scheduled
149
+ },
150
+ action_traces: {
151
+ description:
152
+ "A JSON string trace of the actions performed for the transaction.",
153
+ type: new GraphQLList(action_trace_type),
154
+ resolve: ({ processed }) => processed.action_traces
155
+ }
156
+ })
157
+ });
158
+
159
+ export default transaction_receipt_type;