@xelis/sdk 0.11.31 → 0.11.33
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/dist/cjs/contract/contract.js +126 -84
- package/dist/cjs/contract/typed_contract.js +134 -88
- package/dist/cjs/contract/xvm_serializer.js +252 -29
- package/dist/cjs/daemon/rpc.js +21 -0
- package/dist/cjs/daemon/types.js +14 -2
- package/dist/cjs/daemon/websocket.js +21 -0
- package/dist/cjs/rpc/websocket.js +10 -4
- package/dist/esm/contract/contract.js +125 -83
- package/dist/esm/contract/typed_contract.js +131 -85
- package/dist/esm/contract/xvm_serializer.js +244 -27
- package/dist/esm/daemon/rpc.js +21 -0
- package/dist/esm/daemon/types.js +13 -1
- package/dist/esm/daemon/websocket.js +21 -0
- package/dist/esm/rpc/websocket.js +10 -4
- package/dist/types/contract/contract.d.ts +46 -10
- package/dist/types/contract/typed_contract.d.ts +50 -15
- package/dist/types/contract/xvm_serializer.d.ts +68 -4
- package/dist/types/daemon/rpc.d.ts +8 -1
- package/dist/types/daemon/types.d.ts +82 -2
- package/dist/types/daemon/websocket.d.ts +8 -1
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createContractDeployment = exports.createContractInvocation = exports.createDeposits = exports.
|
|
3
|
+
exports.createContractDeployment = exports.createContractInvocation = exports.createDeposits = exports.createVMParameter = exports.typeRegistry = exports.defineStruct = exports.defineEnum = exports.VMParam = exports.serialize_optional = exports.serialize_map = exports.serialize_array = exports.createVMPrimitive = void 0;
|
|
4
4
|
// Known opaque types that need special wrapping
|
|
5
|
-
const OPAQUE_TYPES = new Set(['Hash', 'Address', 'PublicKey', 'Blob'
|
|
5
|
+
const OPAQUE_TYPES = new Set(['Hash', 'Address', 'PublicKey', 'Blob']);
|
|
6
6
|
// Type validation and conversion helpers
|
|
7
7
|
const TYPE_VALIDATORS = {
|
|
8
8
|
'u256': (v) => {
|
|
@@ -76,12 +76,12 @@ const TYPE_VALIDATORS = {
|
|
|
76
76
|
* @param type - The type string (e.g., 'u64', 'Hash', 'string')
|
|
77
77
|
* @param validate - Whether to validate and convert the value (default: true)
|
|
78
78
|
*/
|
|
79
|
-
function
|
|
80
|
-
let
|
|
79
|
+
function createVMPrimitive(value, type, validate = true) {
|
|
80
|
+
let processed_value = value;
|
|
81
81
|
// Validate and convert value if requested
|
|
82
82
|
if (validate && TYPE_VALIDATORS[type]) {
|
|
83
83
|
try {
|
|
84
|
-
|
|
84
|
+
processed_value = TYPE_VALIDATORS[type](value);
|
|
85
85
|
}
|
|
86
86
|
catch (error) {
|
|
87
87
|
throw new Error(`Failed to create VM parameter for type ${type}: ${error}`);
|
|
@@ -90,64 +90,287 @@ function createVMParameter(value, type, validate = true) {
|
|
|
90
90
|
// Handle opaque types (Hash, Address, PublicKey)
|
|
91
91
|
if (OPAQUE_TYPES.has(type)) {
|
|
92
92
|
return {
|
|
93
|
-
type: "
|
|
93
|
+
type: "primitive",
|
|
94
94
|
value: {
|
|
95
95
|
type: "opaque",
|
|
96
96
|
value: {
|
|
97
97
|
type: type,
|
|
98
|
-
value:
|
|
98
|
+
value: processed_value
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
// Handle regular types
|
|
104
104
|
return {
|
|
105
|
-
type: "
|
|
105
|
+
type: "primitive",
|
|
106
106
|
value: {
|
|
107
107
|
type: type,
|
|
108
|
-
value:
|
|
108
|
+
value: processed_value
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
exports.
|
|
112
|
+
exports.createVMPrimitive = createVMPrimitive;
|
|
113
|
+
/**
|
|
114
|
+
* Serialize an array of values
|
|
115
|
+
*/
|
|
116
|
+
function serialize_array(items, item_type) {
|
|
117
|
+
const serialized_items = items.map(item => createVMParameter(item, item_type));
|
|
118
|
+
return {
|
|
119
|
+
type: "array",
|
|
120
|
+
value: serialized_items
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
exports.serialize_array = serialize_array;
|
|
124
|
+
/**
|
|
125
|
+
* Serialize a map
|
|
126
|
+
*/
|
|
127
|
+
function serialize_map(map, keyType, valueType) {
|
|
128
|
+
const entries = [];
|
|
129
|
+
for (const [key, value] of Object.entries(map)) {
|
|
130
|
+
const serialized_key = createVMParameter(key, keyType);
|
|
131
|
+
const serialized_value = createVMParameter(value, valueType);
|
|
132
|
+
entries.push([serialized_key, serialized_value]);
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
type: "map",
|
|
136
|
+
value: entries
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
exports.serialize_map = serialize_map;
|
|
140
|
+
/**
|
|
141
|
+
* Serialize an optional value
|
|
142
|
+
*/
|
|
143
|
+
function serialize_optional(value, inner_type) {
|
|
144
|
+
if (value === null || value === undefined) {
|
|
145
|
+
return {
|
|
146
|
+
type: "option",
|
|
147
|
+
value: null
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
type: "option",
|
|
152
|
+
value: createVMParameter(value, inner_type)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
exports.serialize_optional = serialize_optional;
|
|
113
156
|
/**
|
|
114
157
|
* Convenience functions for common types
|
|
115
158
|
*/
|
|
116
|
-
exports.
|
|
117
|
-
hash: (value) =>
|
|
118
|
-
address: (value) =>
|
|
119
|
-
|
|
120
|
-
blob: (value) =>
|
|
121
|
-
u64: (value) =>
|
|
122
|
-
u32: (value) =>
|
|
123
|
-
u16: (value) =>
|
|
124
|
-
u8: (value) =>
|
|
125
|
-
string: (value) =>
|
|
126
|
-
boolean: (value) =>
|
|
159
|
+
exports.VMParam = {
|
|
160
|
+
hash: (value) => createVMPrimitive(value, 'Hash'),
|
|
161
|
+
address: (value) => createVMPrimitive(value, 'Address'),
|
|
162
|
+
public_key: (value) => createVMPrimitive(value, 'PublicKey'),
|
|
163
|
+
blob: (value) => createVMPrimitive(value, 'Blob'),
|
|
164
|
+
u64: (value) => createVMPrimitive(value, 'u64'),
|
|
165
|
+
u32: (value) => createVMPrimitive(value, 'u32'),
|
|
166
|
+
u16: (value) => createVMPrimitive(value, 'u16'),
|
|
167
|
+
u8: (value) => createVMPrimitive(value, 'u8'),
|
|
168
|
+
string: (value) => createVMPrimitive(value, 'string'),
|
|
169
|
+
boolean: (value) => createVMPrimitive(value, 'boolean'),
|
|
127
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* Define an enum type from ABI schema
|
|
173
|
+
*/
|
|
174
|
+
function defineEnum(name, variants) {
|
|
175
|
+
const variantNames = variants.map(v => v.name);
|
|
176
|
+
return {
|
|
177
|
+
name,
|
|
178
|
+
// NEW: mark kind & expose a matcher
|
|
179
|
+
// (safe to add; SerializableType is duck-typed)
|
|
180
|
+
// @ts-ignore - widen at runtime
|
|
181
|
+
kind: 'enum',
|
|
182
|
+
// @ts-ignore
|
|
183
|
+
hasVariant: (vn) => variantNames.includes(vn),
|
|
184
|
+
to_VMParameter(value) {
|
|
185
|
+
const variant_index = variants.findIndex(v => v.name === value.type);
|
|
186
|
+
if (variant_index === -1) {
|
|
187
|
+
throw new Error(`Unknown variant '${value.type}' for enum '${name}'`);
|
|
188
|
+
}
|
|
189
|
+
const variant = variants[variant_index];
|
|
190
|
+
const expected_fields = new Set(variant.fields.map(f => f.name));
|
|
191
|
+
expected_fields.add('type');
|
|
192
|
+
for (const key of Object.keys(value)) {
|
|
193
|
+
if (!expected_fields.has(key)) {
|
|
194
|
+
throw new Error(`Unknown field '${key}' for variant '${value.type}' of enum '${name}'. ` +
|
|
195
|
+
`Expected fields: ${Array.from(expected_fields).filter(f => f !== 'type').join(', ')}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const params = [
|
|
199
|
+
exports.VMParam.u8(variant_index)
|
|
200
|
+
];
|
|
201
|
+
for (const field_schema of variant.fields) {
|
|
202
|
+
const field_value = value[field_schema.name];
|
|
203
|
+
if (field_value === undefined) {
|
|
204
|
+
throw new Error(`Missing field '${field_schema.name}' for variant '${value.type}' of enum '${name}'`);
|
|
205
|
+
}
|
|
206
|
+
params.push(createVMParameter(field_value, field_schema.type));
|
|
207
|
+
}
|
|
208
|
+
return { type: "object", value: params };
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
exports.defineEnum = defineEnum;
|
|
213
|
+
/**
|
|
214
|
+
* Define a struct type from ABI schema
|
|
215
|
+
*/
|
|
216
|
+
function defineStruct(name, fields) {
|
|
217
|
+
return {
|
|
218
|
+
name,
|
|
219
|
+
// NEW: mark kind for structs
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
kind: 'struct',
|
|
222
|
+
to_VMParameter(value) {
|
|
223
|
+
const expected_fields = new Set(fields.map(f => f.name));
|
|
224
|
+
for (const key of Object.keys(value)) {
|
|
225
|
+
if (!expected_fields.has(key)) {
|
|
226
|
+
throw new Error(`Unknown field '${key}' for struct '${name}'. ` +
|
|
227
|
+
`Expected fields: ${Array.from(expected_fields).join(', ')}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const params = [];
|
|
231
|
+
for (const field_schema of fields) {
|
|
232
|
+
const field_value = value[field_schema.name];
|
|
233
|
+
if (field_value === undefined) {
|
|
234
|
+
throw new Error(`Missing field '${field_schema.name}' for struct '${name}'`);
|
|
235
|
+
}
|
|
236
|
+
params.push(createVMParameter(field_value, field_schema.type));
|
|
237
|
+
}
|
|
238
|
+
return { type: "object", value: params };
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
exports.defineStruct = defineStruct;
|
|
243
|
+
/**
|
|
244
|
+
* Type registry - simple Map for custom types
|
|
245
|
+
*/
|
|
246
|
+
class TypeRegistry {
|
|
247
|
+
constructor() {
|
|
248
|
+
this.types = new Map();
|
|
249
|
+
}
|
|
250
|
+
register(definition) {
|
|
251
|
+
this.types.set(definition.name, definition);
|
|
252
|
+
return definition;
|
|
253
|
+
}
|
|
254
|
+
get(name) {
|
|
255
|
+
return this.types.get(name);
|
|
256
|
+
}
|
|
257
|
+
has(name) {
|
|
258
|
+
return this.types.has(name);
|
|
259
|
+
}
|
|
260
|
+
clear() {
|
|
261
|
+
this.types.clear();
|
|
262
|
+
}
|
|
263
|
+
all() {
|
|
264
|
+
return this.types.values();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
exports.typeRegistry = new TypeRegistry();
|
|
268
|
+
/**
|
|
269
|
+
* Enhanced parameter creation that handles both primitive and custom types
|
|
270
|
+
* @param value - The value to serialize
|
|
271
|
+
* @param type - The type string (primitive or custom type name)
|
|
272
|
+
* @param validate - Whether to validate primitive values (default: true)
|
|
273
|
+
*/
|
|
274
|
+
function createVMParameter(value, type, validate = true) {
|
|
275
|
+
// Pass-through already-serialized parameters
|
|
276
|
+
if (value && typeof value === 'object' && 'type' in value && 'value' in value) {
|
|
277
|
+
return value;
|
|
278
|
+
}
|
|
279
|
+
// Arrays
|
|
280
|
+
if (type.endsWith('[]')) {
|
|
281
|
+
const inner_type = type.slice(0, -2);
|
|
282
|
+
if (!Array.isArray(value)) {
|
|
283
|
+
throw new Error(`Expected array for type ${type}, got ${typeof value}`);
|
|
284
|
+
}
|
|
285
|
+
return serialize_array(value, inner_type);
|
|
286
|
+
}
|
|
287
|
+
// Optionals
|
|
288
|
+
if (type.startsWith('optional<') && type.endsWith('>')) {
|
|
289
|
+
const inner_type = type.slice(9, -1);
|
|
290
|
+
return serialize_optional(value, inner_type);
|
|
291
|
+
}
|
|
292
|
+
// Maps
|
|
293
|
+
const map_match = type.match(/^map<(.+),\s*(.+)>$/);
|
|
294
|
+
if (map_match) {
|
|
295
|
+
const [, keyType, valueType] = map_match;
|
|
296
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
297
|
+
throw new Error(`Expected object for type ${type}, got ${typeof value}`);
|
|
298
|
+
}
|
|
299
|
+
return serialize_map(value, keyType.trim(), valueType.trim());
|
|
300
|
+
}
|
|
301
|
+
// Generic enum/struct notations: enum<Foo>, struct<Bar>
|
|
302
|
+
const enumGeneric = type.match(/^enum<\s*([^>]+)\s*>$/i);
|
|
303
|
+
if (enumGeneric) {
|
|
304
|
+
const realType = enumGeneric[1].trim();
|
|
305
|
+
const custom = exports.typeRegistry.get(realType);
|
|
306
|
+
if (!custom)
|
|
307
|
+
throw new Error(`Unregistered enum type: ${realType}`);
|
|
308
|
+
return custom.to_VMParameter(value);
|
|
309
|
+
}
|
|
310
|
+
const structGeneric = type.match(/^struct<\s*([^>]+)\s*>$/i);
|
|
311
|
+
if (structGeneric) {
|
|
312
|
+
const realType = structGeneric[1].trim();
|
|
313
|
+
const custom = exports.typeRegistry.get(realType);
|
|
314
|
+
if (!custom)
|
|
315
|
+
throw new Error(`Unregistered struct type: ${realType}`);
|
|
316
|
+
return custom.to_VMParameter(value);
|
|
317
|
+
}
|
|
318
|
+
// Preferred: named custom type
|
|
319
|
+
const custom_type = exports.typeRegistry.get(type);
|
|
320
|
+
if (custom_type) {
|
|
321
|
+
return custom_type.to_VMParameter(value);
|
|
322
|
+
}
|
|
323
|
+
// **Fix for ABI that says literally "enum"/"struct"**
|
|
324
|
+
if (type === 'enum' && value && typeof value === 'object' && 'type' in value) {
|
|
325
|
+
const variantName = value.type;
|
|
326
|
+
for (const t of exports.typeRegistry.all()) {
|
|
327
|
+
const anyT = t;
|
|
328
|
+
if (anyT?.kind === 'enum' && typeof anyT.hasVariant === 'function' && anyT.hasVariant(variantName)) {
|
|
329
|
+
return t.to_VMParameter(value);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
throw new Error(`Cannot resolve enum type for variant '${variantName}'. Is it registered?`);
|
|
333
|
+
}
|
|
334
|
+
if (type === 'struct') {
|
|
335
|
+
// Best-effort: if your ABI truly says "struct" w/o a name, you’ll need a hint.
|
|
336
|
+
// You can add your own resolution heuristic here if you have one.
|
|
337
|
+
throw new Error(`Unknown struct subtype; ABI must specify struct<Foo> or a named type`);
|
|
338
|
+
}
|
|
339
|
+
// Primitive fallback
|
|
340
|
+
if (type in TYPE_VALIDATORS) {
|
|
341
|
+
return createVMPrimitive(value, type, validate);
|
|
342
|
+
}
|
|
343
|
+
console.error("[VMParam] unknown type", type, { value });
|
|
344
|
+
throw new Error(`Unknown type: ${type}`);
|
|
345
|
+
}
|
|
346
|
+
exports.createVMParameter = createVMParameter;
|
|
347
|
+
// ============================================================================
|
|
348
|
+
// Contract Invocation Helpers
|
|
349
|
+
// ============================================================================
|
|
128
350
|
/**
|
|
129
351
|
* Creates a deposits object for contract calls
|
|
130
352
|
* @param deposits - Object mapping token hashes to amounts
|
|
131
353
|
*/
|
|
132
354
|
function createDeposits(deposits) {
|
|
133
355
|
const result = {};
|
|
134
|
-
for (const [
|
|
356
|
+
for (const [token_hash, amount] of Object.entries(deposits)) {
|
|
135
357
|
// Validate hash format
|
|
136
|
-
if (!/^[0-9a-fA-F]{64}$/.test(
|
|
137
|
-
throw new Error(`Invalid token hash format: ${
|
|
358
|
+
if (!/^[0-9a-fA-F]{64}$/.test(token_hash)) {
|
|
359
|
+
throw new Error(`Invalid token hash format: ${token_hash}`);
|
|
138
360
|
}
|
|
139
|
-
result[
|
|
361
|
+
result[token_hash] = { amount };
|
|
140
362
|
}
|
|
141
363
|
return result;
|
|
142
364
|
}
|
|
143
365
|
exports.createDeposits = createDeposits;
|
|
144
366
|
function createContractInvocation(params) {
|
|
145
|
-
const { contract,
|
|
367
|
+
const { contract, chunk_id, parameters = [], deposits, permission, maxGas = 50000000 } = params;
|
|
146
368
|
const result = {
|
|
147
369
|
invoke_contract: {
|
|
148
370
|
contract,
|
|
149
371
|
max_gas: maxGas,
|
|
150
|
-
|
|
372
|
+
entry_id: chunk_id,
|
|
373
|
+
permission,
|
|
151
374
|
parameters
|
|
152
375
|
}
|
|
153
376
|
};
|
|
@@ -158,11 +381,11 @@ function createContractInvocation(params) {
|
|
|
158
381
|
}
|
|
159
382
|
exports.createContractInvocation = createContractInvocation;
|
|
160
383
|
function createContractDeployment(params) {
|
|
161
|
-
const { bytecode, hasConstructor = false, maxGas =
|
|
384
|
+
const { bytecode, hasConstructor = false, maxGas = 50000000 } = params;
|
|
162
385
|
const result = {
|
|
163
386
|
deploy_contract: {
|
|
164
387
|
module: bytecode,
|
|
165
|
-
...(hasConstructor && { invoke: {
|
|
388
|
+
...(hasConstructor && { invoke: { maxGas } })
|
|
166
389
|
}
|
|
167
390
|
};
|
|
168
391
|
return result;
|
package/dist/cjs/daemon/rpc.js
CHANGED
|
@@ -52,6 +52,18 @@ class RPC extends http_1.HttpRPC {
|
|
|
52
52
|
getTopBlock(params) {
|
|
53
53
|
return this.request(types_1.RPCMethod.GetTopBlock, params);
|
|
54
54
|
}
|
|
55
|
+
getBlockDifficultyByHash(params) {
|
|
56
|
+
return this.request(types_1.RPCMethod.GetBlockDifficultyByHash, params);
|
|
57
|
+
}
|
|
58
|
+
getBlockBaseFeeByHash(params) {
|
|
59
|
+
return this.request(types_1.RPCMethod.GetBlockBaseFeeByHash, params);
|
|
60
|
+
}
|
|
61
|
+
getBlockSummaryAtTopoheight(params) {
|
|
62
|
+
return this.request(types_1.RPCMethod.GetBlockSummaryAtTopoheight, params);
|
|
63
|
+
}
|
|
64
|
+
getBlockSummaryByHash(params) {
|
|
65
|
+
return this.request(types_1.RPCMethod.GetBlockSummaryByHash, params);
|
|
66
|
+
}
|
|
55
67
|
getBalance(params) {
|
|
56
68
|
return this.request(types_1.RPCMethod.GetBalance, params);
|
|
57
69
|
}
|
|
@@ -106,6 +118,9 @@ class RPC extends http_1.HttpRPC {
|
|
|
106
118
|
getTransactions(txHashes) {
|
|
107
119
|
return this.request(types_1.RPCMethod.GetTransactions, { tx_hashes: txHashes });
|
|
108
120
|
}
|
|
121
|
+
getTransactionsSummary(params) {
|
|
122
|
+
return this.request(types_1.RPCMethod.GetTransactionsSummary, params);
|
|
123
|
+
}
|
|
109
124
|
isTxExecutedInBlock(params) {
|
|
110
125
|
return this.request(types_1.RPCMethod.IsTxExecutedInBlock, params);
|
|
111
126
|
}
|
|
@@ -163,6 +178,9 @@ class RPC extends http_1.HttpRPC {
|
|
|
163
178
|
extractKeyFromAddress(params) {
|
|
164
179
|
return this.request(types_1.RPCMethod.ExtractKeyFromAddress, params);
|
|
165
180
|
}
|
|
181
|
+
keyToAddress(params) {
|
|
182
|
+
return this.request(types_1.RPCMethod.KeyToAddress, params);
|
|
183
|
+
}
|
|
166
184
|
makeIntegratedAddress(params) {
|
|
167
185
|
return this.request(types_1.RPCMethod.MakeIntegratedAddress, params);
|
|
168
186
|
}
|
|
@@ -190,6 +208,9 @@ class RPC extends http_1.HttpRPC {
|
|
|
190
208
|
getContractRegisteredExecutionsAtTopoheight(params) {
|
|
191
209
|
return this.request(types_1.RPCMethod.GetContractRegisteredExecutionsAtTopoheight, params);
|
|
192
210
|
}
|
|
211
|
+
getContractsOutputs(params) {
|
|
212
|
+
return this.request(types_1.RPCMethod.GetContractsOutputs);
|
|
213
|
+
}
|
|
193
214
|
getContractModule(params) {
|
|
194
215
|
return this.request(types_1.RPCMethod.GetContractModule, params);
|
|
195
216
|
}
|
package/dist/cjs/daemon/types.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RPCEvent = exports.RPCMethod = exports.BlockType = exports.BalanceType = void 0;
|
|
3
|
+
exports.RPCEvent = exports.RPCMethod = exports.BlockType = exports.BalanceType = exports.AddressType = void 0;
|
|
4
|
+
var AddressType;
|
|
5
|
+
(function (AddressType) {
|
|
6
|
+
AddressType["Normal"] = "normal";
|
|
7
|
+
AddressType["Data"] = "data";
|
|
8
|
+
})(AddressType = exports.AddressType || (exports.AddressType = {}));
|
|
4
9
|
var BalanceType;
|
|
5
10
|
(function (BalanceType) {
|
|
6
11
|
BalanceType["Input"] = "input";
|
|
@@ -32,6 +37,10 @@ var RPCMethod;
|
|
|
32
37
|
RPCMethod["GetBlocksAtHeight"] = "get_blocks_at_height";
|
|
33
38
|
RPCMethod["GetBlockByHash"] = "get_block_by_hash";
|
|
34
39
|
RPCMethod["GetTopBlock"] = "get_top_block";
|
|
40
|
+
RPCMethod["GetBlockDifficultyByHash"] = "get_block_difficulty_by_hash";
|
|
41
|
+
RPCMethod["GetBlockBaseFeeByHash"] = "get_block_base_fee_by_hash";
|
|
42
|
+
RPCMethod["GetBlockSummaryAtTopoheight"] = "get_block_summary_at_topoheight";
|
|
43
|
+
RPCMethod["GetBlockSummaryByHash"] = "get_block_summary_by_hash";
|
|
35
44
|
RPCMethod["GetBalance"] = "get_balance";
|
|
36
45
|
RPCMethod["GetStableBalance"] = "get_stable_balance";
|
|
37
46
|
RPCMethod["HasBalance"] = "has_balance";
|
|
@@ -50,9 +59,11 @@ var RPCMethod;
|
|
|
50
59
|
RPCMethod["GetTransactionExecutor"] = "get_transaction_executor";
|
|
51
60
|
RPCMethod["GetTransaction"] = "get_transaction";
|
|
52
61
|
RPCMethod["GetTransactions"] = "get_transactions";
|
|
62
|
+
RPCMethod["GetTransactionsSummary"] = "get_transactions_summary";
|
|
53
63
|
RPCMethod["IsTxExecutedInBlock"] = "is_tx_executed_in_block";
|
|
54
64
|
RPCMethod["P2PStatus"] = "p2p_status";
|
|
55
65
|
RPCMethod["GetPeers"] = "get_peers";
|
|
66
|
+
RPCMethod["GetP2PBlockPropagation"] = "get_p2p_block_propagation";
|
|
56
67
|
RPCMethod["GetMempool"] = "get_mempool";
|
|
57
68
|
RPCMethod["GetMempoolSummary"] = "get_mempool_summary";
|
|
58
69
|
RPCMethod["GetMempoolCache"] = "get_mempool_cache";
|
|
@@ -69,6 +80,7 @@ var RPCMethod;
|
|
|
69
80
|
RPCMethod["ValidateAddress"] = "validate_address";
|
|
70
81
|
RPCMethod["SplitAddress"] = "split_address";
|
|
71
82
|
RPCMethod["ExtractKeyFromAddress"] = "extract_key_from_address";
|
|
83
|
+
RPCMethod["KeyToAddress"] = "key_to_address";
|
|
72
84
|
RPCMethod["MakeIntegratedAddress"] = "make_integrated_address";
|
|
73
85
|
RPCMethod["DecryptExtraData"] = "decrypt_extra_data";
|
|
74
86
|
RPCMethod["GetMultisigAtTopoheight"] = "get_multisig_at_topoheight";
|
|
@@ -78,6 +90,7 @@ var RPCMethod;
|
|
|
78
90
|
RPCMethod["GetContractLogs"] = "get_contract_logs";
|
|
79
91
|
RPCMethod["GetContractScheduledExecutionsAtTopoheight"] = "get_contract_scheduled_executions_at_topoheight";
|
|
80
92
|
RPCMethod["GetContractRegisteredExecutionsAtTopoheight"] = "get_contract_registered_executions_at_topoheight";
|
|
93
|
+
RPCMethod["GetContractsOutputs"] = "get_contracts_outputs";
|
|
81
94
|
RPCMethod["GetContractModule"] = "get_contract_module";
|
|
82
95
|
RPCMethod["GetContractData"] = "get_contract_data";
|
|
83
96
|
RPCMethod["GetContractDataAtTopoheight"] = "get_contract_data_at_topoheight";
|
|
@@ -86,7 +99,6 @@ var RPCMethod;
|
|
|
86
99
|
RPCMethod["GetContractAssets"] = "get_contract_assets";
|
|
87
100
|
RPCMethod["GetContracts"] = "get_contracts";
|
|
88
101
|
RPCMethod["GetContractDataEntries"] = "get_contract_data_entries";
|
|
89
|
-
RPCMethod["GetP2PBlockPropagation"] = "get_p2p_block_propagation";
|
|
90
102
|
RPCMethod["GetBlockTemplate"] = "get_block_template";
|
|
91
103
|
RPCMethod["GetMinerWork"] = "get_miner_work";
|
|
92
104
|
RPCMethod["SubmitBlock"] = "submit_block";
|
|
@@ -71,6 +71,18 @@ class DaemonMethods {
|
|
|
71
71
|
getTopBlock(params) {
|
|
72
72
|
return this.dataCall(types_1.RPCMethod.GetTopBlock, params);
|
|
73
73
|
}
|
|
74
|
+
getBlockDifficultyByHash(params) {
|
|
75
|
+
return this.dataCall(types_1.RPCMethod.GetBlockDifficultyByHash, params);
|
|
76
|
+
}
|
|
77
|
+
getBlockBaseFeeByHash(params) {
|
|
78
|
+
return this.dataCall(types_1.RPCMethod.GetBlockBaseFeeByHash, params);
|
|
79
|
+
}
|
|
80
|
+
getBlockSummaryAtTopoheight(params) {
|
|
81
|
+
return this.dataCall(types_1.RPCMethod.GetBlockSummaryAtTopoheight, params);
|
|
82
|
+
}
|
|
83
|
+
getBlockSummaryByHash(params) {
|
|
84
|
+
return this.dataCall(types_1.RPCMethod.GetBlockSummaryByHash, params);
|
|
85
|
+
}
|
|
74
86
|
getBalance(params) {
|
|
75
87
|
return this.dataCall(types_1.RPCMethod.GetBalance, params);
|
|
76
88
|
}
|
|
@@ -125,6 +137,9 @@ class DaemonMethods {
|
|
|
125
137
|
getTransactions(txHashes) {
|
|
126
138
|
return this.dataCall(types_1.RPCMethod.GetTransactions, { tx_hashes: txHashes });
|
|
127
139
|
}
|
|
140
|
+
getTransactionsSummary(params) {
|
|
141
|
+
return this.dataCall(types_1.RPCMethod.GetTransactionsSummary, params);
|
|
142
|
+
}
|
|
128
143
|
isTxExecutedInBlock(params) {
|
|
129
144
|
return this.dataCall(types_1.RPCMethod.IsTxExecutedInBlock, params);
|
|
130
145
|
}
|
|
@@ -182,6 +197,9 @@ class DaemonMethods {
|
|
|
182
197
|
extractKeyFromAddress(params) {
|
|
183
198
|
return this.dataCall(types_1.RPCMethod.ExtractKeyFromAddress, params);
|
|
184
199
|
}
|
|
200
|
+
keyToAddress(params) {
|
|
201
|
+
return this.dataCall(types_1.RPCMethod.KeyToAddress, params);
|
|
202
|
+
}
|
|
185
203
|
makeIntegratedAddress(params) {
|
|
186
204
|
return this.dataCall(types_1.RPCMethod.MakeIntegratedAddress, params);
|
|
187
205
|
}
|
|
@@ -209,6 +227,9 @@ class DaemonMethods {
|
|
|
209
227
|
getContractRegisteredExecutionsAtTopoheight(params) {
|
|
210
228
|
return this.dataCall(types_1.RPCMethod.GetContractRegisteredExecutionsAtTopoheight, params);
|
|
211
229
|
}
|
|
230
|
+
getContractsOutputs(params) {
|
|
231
|
+
return this.dataCall(types_1.RPCMethod.GetContractsOutputs);
|
|
232
|
+
}
|
|
212
233
|
getContractModule(params) {
|
|
213
234
|
return this.dataCall(types_1.RPCMethod.GetContractModule, params);
|
|
214
235
|
}
|
|
@@ -40,8 +40,6 @@ class WSRPC {
|
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
42
|
let idRefObject = {};
|
|
43
|
-
await this.dataCall(`subscribe`, { notify: event }, idRefObject)
|
|
44
|
-
.catch(err => listener(null, err));
|
|
45
43
|
const onMessage = (msgEvent) => {
|
|
46
44
|
const eventData = this.events.get(event);
|
|
47
45
|
if (eventData && typeof msgEvent.data === `string`) {
|
|
@@ -64,8 +62,16 @@ class WSRPC {
|
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
64
|
};
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
try {
|
|
66
|
+
this.socket.addEventListener(`message`, onMessage);
|
|
67
|
+
this.events.set(event, { onMessage, listeners: [listener] });
|
|
68
|
+
await this.dataCall(`subscribe`, { notify: event }, idRefObject);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
this.socket.removeEventListener(`message`, onMessage);
|
|
72
|
+
this.events.delete(event);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
69
75
|
}
|
|
70
76
|
};
|
|
71
77
|
// make sure connection is open or wait
|