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