antelopeql 2.0.0-rc.28 → 2.0.0-rc.30
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.
|
@@ -44,12 +44,20 @@ const get_ram_price = {
|
|
|
44
44
|
if (data.rows) {
|
|
45
45
|
// Connector Balance / (Smart Token’s Outstanding supply × Connector Weight)
|
|
46
46
|
const [RAM] = data.rows;
|
|
47
|
-
|
|
47
|
+
|
|
48
|
+
const CORE_ASSET = RAM.quote.balance;
|
|
49
|
+
const CORE_TOKEN = CORE_ASSET.match(/[\sA-Z]+/gmu);
|
|
50
|
+
|
|
51
|
+
const [, decimal] = String(
|
|
52
|
+
CORE_ASSET.replace(/[A-Za-z\s]+/gmu, "")
|
|
53
|
+
).split(".");
|
|
54
|
+
|
|
55
|
+
const precision = decimal?.length ?? 0;
|
|
48
56
|
|
|
49
57
|
const supply = RAM.base.balance.replace(" RAM", "");
|
|
50
58
|
const total_value = RAM.quote.balance.replace(CORE_TOKEN, "");
|
|
51
59
|
const byte_price = quantity * (total_value / supply);
|
|
52
|
-
return byte_price + CORE_TOKEN;
|
|
60
|
+
return parseFloat(byte_price).toFixed(precision) + CORE_TOKEN;
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import serializeName from "eosio-wasm-js/name.mjs";
|
|
1
2
|
import {
|
|
3
|
+
GraphQLEnumType,
|
|
2
4
|
GraphQLError,
|
|
3
5
|
GraphQLInt,
|
|
4
6
|
GraphQLList,
|
|
@@ -9,6 +11,13 @@ import {
|
|
|
9
11
|
|
|
10
12
|
import name_type from "../eosio_types/name_type.mjs";
|
|
11
13
|
|
|
14
|
+
function convertNameToSymbol(scope) {
|
|
15
|
+
return (serializeName(scope).match(/[0-9A-Fa-f]{2}/g) || [])
|
|
16
|
+
.map((hex) => String.fromCharCode(parseInt(hex, 16)))
|
|
17
|
+
.filter((x) => !!x.charCodeAt())
|
|
18
|
+
.join("");
|
|
19
|
+
}
|
|
20
|
+
|
|
12
21
|
const table_type = new GraphQLObjectType({
|
|
13
22
|
name: "table_type",
|
|
14
23
|
fields: {
|
|
@@ -17,7 +26,9 @@ const table_type = new GraphQLObjectType({
|
|
|
17
26
|
new GraphQLObjectType({
|
|
18
27
|
name: "table_rows_type",
|
|
19
28
|
fields: {
|
|
20
|
-
scope: {
|
|
29
|
+
scope: {
|
|
30
|
+
type: name_type
|
|
31
|
+
},
|
|
21
32
|
table_name: { type: name_type, resolve: ({ table }) => table },
|
|
22
33
|
ram_payer: {
|
|
23
34
|
type: name_type,
|
|
@@ -65,11 +76,21 @@ const get_table = {
|
|
|
65
76
|
description:
|
|
66
77
|
"Filters results to return the first element that is greater than provided value in the table.",
|
|
67
78
|
type: GraphQLString
|
|
79
|
+
},
|
|
80
|
+
scope_type: {
|
|
81
|
+
defaultValue: 0,
|
|
82
|
+
type: new GraphQLEnumType({
|
|
83
|
+
name: "scope_type",
|
|
84
|
+
values: {
|
|
85
|
+
name: { value: 0 },
|
|
86
|
+
symbol_code: { value: 1 }
|
|
87
|
+
}
|
|
88
|
+
})
|
|
68
89
|
}
|
|
69
90
|
},
|
|
70
91
|
async resolve(
|
|
71
92
|
root,
|
|
72
|
-
{ account_name, table_name, limit, lower_bound, upper_bound },
|
|
93
|
+
{ account_name, table_name, limit, lower_bound, upper_bound, scope_type },
|
|
73
94
|
getContext,
|
|
74
95
|
info
|
|
75
96
|
) {
|
|
@@ -82,6 +103,7 @@ const get_table = {
|
|
|
82
103
|
);
|
|
83
104
|
|
|
84
105
|
const uri = `${rpc_url}/v1/chain/get_table_by_scope`;
|
|
106
|
+
|
|
85
107
|
const data = await fetch(uri, {
|
|
86
108
|
method: "POST",
|
|
87
109
|
...fetchOptions,
|
|
@@ -97,8 +119,16 @@ const get_table = {
|
|
|
97
119
|
}).then((req) => req.json());
|
|
98
120
|
|
|
99
121
|
if (data.error) throw new GraphQLError(data.message, { extensions: data });
|
|
122
|
+
if (!scope_type) return data;
|
|
100
123
|
|
|
101
|
-
|
|
124
|
+
if (scope_type == 1)
|
|
125
|
+
return {
|
|
126
|
+
...data,
|
|
127
|
+
rows: data.rows.map((x) => ({
|
|
128
|
+
...x,
|
|
129
|
+
scope: convertNameToSymbol(x.scope)
|
|
130
|
+
}))
|
|
131
|
+
};
|
|
102
132
|
}
|
|
103
133
|
};
|
|
104
134
|
|
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.30",
|
|
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",
|