koilib 5.6.0 → 5.7.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.
- package/dist/koinos.js +5056 -4042
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +4 -4
- package/lib/Contract.js +4 -4
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +42 -12
- package/lib/Provider.js +99 -6
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.d.ts +20 -0
- package/lib/Serializer.js +4 -0
- package/lib/Serializer.js.map +1 -1
- package/lib/Signer.d.ts +0 -10
- package/lib/Signer.js +1 -123
- package/lib/Signer.js.map +1 -1
- package/lib/Transaction.d.ts +3 -3
- package/lib/Transaction.js +4 -4
- package/lib/Transaction.js.map +1 -1
- package/lib/browser/Contract.d.ts +4 -4
- package/lib/browser/Contract.js +4 -4
- package/lib/browser/Contract.js.map +1 -1
- package/lib/browser/Provider.d.ts +42 -12
- package/lib/browser/Provider.js +99 -6
- package/lib/browser/Provider.js.map +1 -1
- package/lib/browser/Serializer.d.ts +20 -0
- package/lib/browser/Serializer.js +4 -0
- package/lib/browser/Serializer.js.map +1 -1
- package/lib/browser/Signer.d.ts +0 -10
- package/lib/browser/Signer.js +1 -123
- package/lib/browser/Signer.js.map +1 -1
- package/lib/browser/Transaction.d.ts +3 -3
- package/lib/browser/Transaction.js +4 -4
- package/lib/browser/Transaction.js.map +1 -1
- package/lib/browser/index.d.ts +1 -1
- package/lib/browser/index.js +2 -2
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/interface.d.ts +17 -2
- package/lib/browser/jsonDescriptors/chain-proto.json +74 -3
- package/lib/browser/jsonDescriptors/token-proto.json +5 -26
- package/lib/browser/protoModules/protocol-proto.js +823 -0
- package/lib/browser/protoModules/protocol-proto.js.map +1 -1
- package/lib/browser/utilsNode.d.ts +72 -117
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/interface.d.ts +17 -2
- package/lib/jsonDescriptors/chain-proto.json +74 -3
- package/lib/jsonDescriptors/token-proto.json +5 -26
- package/lib/protoModules/protocol-proto.js +823 -0
- package/lib/protoModules/protocol-proto.js.map +1 -1
- package/lib/utilsNode.d.ts +72 -117
- package/package.json +6 -6
- package/src/Contract.ts +6 -5
- package/src/Provider.ts +150 -20
- package/src/Serializer.ts +27 -0
- package/src/Signer.ts +1 -150
- package/src/Transaction.ts +8 -8
- package/src/index.ts +1 -1
- package/src/interface.ts +19 -2
- package/src/jsonDescriptors/chain-proto.json +74 -3
- package/src/jsonDescriptors/pow-proto.json +1 -1
- package/src/jsonDescriptors/token-proto.json +5 -26
- package/src/jsonDescriptors/value-proto.json +13 -23
- package/src/protoModules/protocol-proto.js +1043 -4
package/lib/utilsNode.d.ts
CHANGED
|
@@ -269,6 +269,22 @@ export declare const ChainTypes: {
|
|
|
269
269
|
go_package: string;
|
|
270
270
|
};
|
|
271
271
|
nested: {
|
|
272
|
+
object_space: {
|
|
273
|
+
fields: {
|
|
274
|
+
system: {
|
|
275
|
+
type: string;
|
|
276
|
+
id: number;
|
|
277
|
+
};
|
|
278
|
+
zone: {
|
|
279
|
+
type: string;
|
|
280
|
+
id: number;
|
|
281
|
+
};
|
|
282
|
+
id: {
|
|
283
|
+
type: string;
|
|
284
|
+
id: number;
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
};
|
|
272
288
|
event_data: {
|
|
273
289
|
fields: {
|
|
274
290
|
sequence: {
|
|
@@ -287,123 +303,7 @@ export declare const ChainTypes: {
|
|
|
287
303
|
id: number;
|
|
288
304
|
};
|
|
289
305
|
data: {
|
|
290
|
-
type: string;
|
|
291
|
-
* Function to encode genesis data in order to launch a
|
|
292
|
-
* new blockchain. The different values are serialized using
|
|
293
|
-
* protobuffers. One of the arguments is the dictionary which
|
|
294
|
-
* contains the relevant information to perform the serialization.
|
|
295
|
-
* By default the function contains the dictionary for the
|
|
296
|
-
* following keys:
|
|
297
|
-
*
|
|
298
|
-
* - "object_key::head_block"
|
|
299
|
-
* - "object_key::chain_id"
|
|
300
|
-
* - "object_key::genesis_key"
|
|
301
|
-
* - "object_key::resource_limit_data"
|
|
302
|
-
* - "object_key::max_account_resources"
|
|
303
|
-
* - "object_key::protocol_descriptor"
|
|
304
|
-
* - "object_key::compute_bandwidth_registry"
|
|
305
|
-
* - "object_key::block_hash_code"
|
|
306
|
-
*
|
|
307
|
-
* @param genesisDataDecoded - Genesis data where the values are
|
|
308
|
-
* objects.
|
|
309
|
-
* @param dictionary - Set of keys which contains the relevant
|
|
310
|
-
* information to perform the serialization
|
|
311
|
-
*
|
|
312
|
-
* @example
|
|
313
|
-
*
|
|
314
|
-
* ```ts
|
|
315
|
-
* const signer = Signer.fromSeed("seed");
|
|
316
|
-
* const genesisDataDecoded = {
|
|
317
|
-
* entries: [
|
|
318
|
-
* {
|
|
319
|
-
* space: { system: true },
|
|
320
|
-
* alias: "object_key::genesis_key",
|
|
321
|
-
* value: signer.address,
|
|
322
|
-
* },
|
|
323
|
-
* ],
|
|
324
|
-
* };
|
|
325
|
-
*
|
|
326
|
-
* const genesisData = await encodeGenesisData(genesisDataDecoded);
|
|
327
|
-
* console.log(genesisData);
|
|
328
|
-
*
|
|
329
|
-
* // {
|
|
330
|
-
* // entries: [
|
|
331
|
-
* // {
|
|
332
|
-
* // space: { system: true },
|
|
333
|
-
* // key: "EiC3nO+XbeKg4C8ugW7M7XdfmJKY4i3l91KoJWxosQPImA==",
|
|
334
|
-
* // value: "AMpASH7CjUHBpl2QR8E5lGKVjVLAvJRg5g==",
|
|
335
|
-
* // },
|
|
336
|
-
* // ],
|
|
337
|
-
* // }
|
|
338
|
-
* ```
|
|
339
|
-
*
|
|
340
|
-
* @example adding a custom dictionary
|
|
341
|
-
*
|
|
342
|
-
* ```ts
|
|
343
|
-
* const contractId = Signer.fromSeed("seed").address;
|
|
344
|
-
* const zone = encodeBase64(decodeBase58(contractId));
|
|
345
|
-
* const genesisDataDecoded = {
|
|
346
|
-
* entries: [
|
|
347
|
-
* {
|
|
348
|
-
* space: { system: true, zone, id: 1 },
|
|
349
|
-
* key: "difficulty_metadata_key",
|
|
350
|
-
* value: {
|
|
351
|
-
* target: encodeBase64url(toUint8Array("F".repeat(64))),
|
|
352
|
-
* last_block_time: "1641038400000",
|
|
353
|
-
* difficulty: encodeBase64url(toUint8Array("1".repeat(64))),
|
|
354
|
-
* target_block_interval: "10",
|
|
355
|
-
* },
|
|
356
|
-
* },
|
|
357
|
-
* ],
|
|
358
|
-
* };
|
|
359
|
-
*
|
|
360
|
-
* const powJson = {
|
|
361
|
-
* nested: {
|
|
362
|
-
* mypackage: {
|
|
363
|
-
* nested: {
|
|
364
|
-
* difficulty_metadata: {
|
|
365
|
-
* "fields": {
|
|
366
|
-
* "target": { "type": "bytes", "id": 1 },
|
|
367
|
-
* "last_block_time": { "type": "uint64", "id": 2,
|
|
368
|
-
* "options": { "jstype": "JS_STRING" }
|
|
369
|
-
* },
|
|
370
|
-
* "difficulty": { "type": "bytes", "id": 3 },
|
|
371
|
-
* "target_block_interval": { "type": "uint64", "id": 4,
|
|
372
|
-
* "options": { "jstype": "JS_STRING" }
|
|
373
|
-
* }
|
|
374
|
-
* }
|
|
375
|
-
* },
|
|
376
|
-
* }
|
|
377
|
-
* }
|
|
378
|
-
* }
|
|
379
|
-
* }
|
|
380
|
-
*
|
|
381
|
-
* const dic = {
|
|
382
|
-
* difficulty_metadata_key: {
|
|
383
|
-
* serializer: new Serializer(powJson),
|
|
384
|
-
* typeName: "difficulty_metadata",
|
|
385
|
-
* },
|
|
386
|
-
* };
|
|
387
|
-
*
|
|
388
|
-
* const genesisData = await encodeGenesisData(genesisDataDecoded, dic);
|
|
389
|
-
* console.log(genesisData);
|
|
390
|
-
*
|
|
391
|
-
* // {
|
|
392
|
-
* // entries: [
|
|
393
|
-
* // {
|
|
394
|
-
* // key: "difficulty_metadata_key",
|
|
395
|
-
* // space: {
|
|
396
|
-
* // id: 1,
|
|
397
|
-
* // system: true,
|
|
398
|
-
* // zone: "AMpASH7CjUHBpl2QR8E5lGKVjVLAvJRg5g==",
|
|
399
|
-
* // },
|
|
400
|
-
* // value:
|
|
401
|
-
* // "CiD//////////////////////////////////////////xCAlIus4S8aIBERERERERERERERERERERERERERERERERERERERERERIAo=",
|
|
402
|
-
* // },
|
|
403
|
-
* // ],
|
|
404
|
-
* // };
|
|
405
|
-
* ```
|
|
406
|
-
*/
|
|
306
|
+
type: string;
|
|
407
307
|
id: number;
|
|
408
308
|
};
|
|
409
309
|
impacted: {
|
|
@@ -684,6 +584,11 @@ export declare const ChainTypes: {
|
|
|
684
584
|
type: string;
|
|
685
585
|
id: number;
|
|
686
586
|
};
|
|
587
|
+
state_delta_entries: {
|
|
588
|
+
rule: string;
|
|
589
|
+
type: string;
|
|
590
|
+
id: number;
|
|
591
|
+
};
|
|
687
592
|
};
|
|
688
593
|
};
|
|
689
594
|
block_header: {
|
|
@@ -814,6 +719,56 @@ export declare const ChainTypes: {
|
|
|
814
719
|
type: string;
|
|
815
720
|
id: number;
|
|
816
721
|
};
|
|
722
|
+
disk_storage_charged: {
|
|
723
|
+
type: string;
|
|
724
|
+
id: number;
|
|
725
|
+
options: {
|
|
726
|
+
jstype: string;
|
|
727
|
+
};
|
|
728
|
+
};
|
|
729
|
+
network_bandwidth_charged: {
|
|
730
|
+
type: string;
|
|
731
|
+
id: number;
|
|
732
|
+
options: {
|
|
733
|
+
jstype: string;
|
|
734
|
+
};
|
|
735
|
+
};
|
|
736
|
+
compute_bandwidth_charged: {
|
|
737
|
+
type: string;
|
|
738
|
+
id: number;
|
|
739
|
+
options: {
|
|
740
|
+
jstype: string;
|
|
741
|
+
};
|
|
742
|
+
};
|
|
743
|
+
state_delta_entries: {
|
|
744
|
+
rule: string;
|
|
745
|
+
type: string;
|
|
746
|
+
id: number;
|
|
747
|
+
};
|
|
748
|
+
};
|
|
749
|
+
};
|
|
750
|
+
state_delta_entry: {
|
|
751
|
+
oneofs: {
|
|
752
|
+
_value: {
|
|
753
|
+
oneof: string[];
|
|
754
|
+
};
|
|
755
|
+
};
|
|
756
|
+
fields: {
|
|
757
|
+
object_space: {
|
|
758
|
+
type: string;
|
|
759
|
+
id: number;
|
|
760
|
+
};
|
|
761
|
+
key: {
|
|
762
|
+
type: string;
|
|
763
|
+
id: number;
|
|
764
|
+
};
|
|
765
|
+
value: {
|
|
766
|
+
type: string;
|
|
767
|
+
id: number;
|
|
768
|
+
options: {
|
|
769
|
+
proto3_optional: boolean;
|
|
770
|
+
};
|
|
771
|
+
};
|
|
817
772
|
};
|
|
818
773
|
};
|
|
819
774
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koilib",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.0",
|
|
4
4
|
"description": "JS Koinos Library",
|
|
5
5
|
"author": "Julian Gonzalez",
|
|
6
6
|
"repository": {
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
".": "./lib/index.js"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@noble/hashes": "^1.1
|
|
49
|
-
"@noble/secp256k1": "^1.
|
|
48
|
+
"@noble/hashes": "^1.3.1",
|
|
49
|
+
"@noble/secp256k1": "^1.7.1",
|
|
50
50
|
"@roamin/koinos-pb-to-proto": "^0.0.3",
|
|
51
51
|
"cross-fetch": "^3.1.5",
|
|
52
52
|
"multibase": "^4.0.6",
|
|
53
|
-
"protobufjs": "^7.
|
|
53
|
+
"protobufjs": "^7.2.4"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@tsconfig/node12": "^1.0.11",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"ts-node": "^10.9.1",
|
|
82
82
|
"typedoc": "^0.23.10",
|
|
83
83
|
"typescript": "^4.7.4",
|
|
84
|
-
"webpack": "^5.
|
|
85
|
-
"webpack-cli": "^
|
|
84
|
+
"webpack": "^5.88.2",
|
|
85
|
+
"webpack-cli": "^5.1.4"
|
|
86
86
|
}
|
|
87
87
|
}
|
package/src/Contract.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-await-in-loop */
|
|
2
|
-
import {
|
|
2
|
+
import { SignerInterface } from "./Signer";
|
|
3
3
|
import { Provider } from "./Provider";
|
|
4
4
|
import { Serializer } from "./Serializer";
|
|
5
5
|
import {
|
|
@@ -158,7 +158,7 @@ export class Contract {
|
|
|
158
158
|
abi?: Abi;
|
|
159
159
|
bytecode?: Uint8Array;
|
|
160
160
|
options?: CallContractOptions;
|
|
161
|
-
signer?:
|
|
161
|
+
signer?: SignerInterface;
|
|
162
162
|
provider?: Provider;
|
|
163
163
|
/**
|
|
164
164
|
* Set this option if you can not use _eval_ functions
|
|
@@ -256,7 +256,6 @@ export class Contract {
|
|
|
256
256
|
result?: T;
|
|
257
257
|
receipt?: TransactionReceipt;
|
|
258
258
|
}> => {
|
|
259
|
-
if (!this.provider) throw new Error("provider not found");
|
|
260
259
|
if (!this.abi || !this.abi.methods)
|
|
261
260
|
throw new Error("Methods are not defined");
|
|
262
261
|
if (!this.abi.methods[name])
|
|
@@ -286,6 +285,8 @@ export class Contract {
|
|
|
286
285
|
return { operation };
|
|
287
286
|
}
|
|
288
287
|
|
|
288
|
+
if (!this.provider) throw new Error("provider not found");
|
|
289
|
+
|
|
289
290
|
if (readOnly) {
|
|
290
291
|
if (!output) throw new Error(`No output defined for ${name}`);
|
|
291
292
|
// read contract
|
|
@@ -481,7 +482,7 @@ export class Contract {
|
|
|
481
482
|
* @returns Operation encoded
|
|
482
483
|
* @example
|
|
483
484
|
* ```ts
|
|
484
|
-
* const opEncoded = contract.encodeOperation({
|
|
485
|
+
* const opEncoded = await contract.encodeOperation({
|
|
485
486
|
* name: "transfer",
|
|
486
487
|
* args: {
|
|
487
488
|
* from: "12fN2CQnuJM8cMnWZ1hPtM4knjLME8E4PD",
|
|
@@ -529,7 +530,7 @@ export class Contract {
|
|
|
529
530
|
* Decodes a contract operation to be human readable
|
|
530
531
|
* @example
|
|
531
532
|
* ```ts
|
|
532
|
-
* const opDecoded = contract.decodeOperation({
|
|
533
|
+
* const opDecoded = await contract.decodeOperation({
|
|
533
534
|
* call_contract: {
|
|
534
535
|
* contract_id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
535
536
|
* entry_point: 0x27f576ca,
|
package/src/Provider.ts
CHANGED
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
CallContractOperationJson,
|
|
6
6
|
TransactionReceipt,
|
|
7
7
|
TransactionJsonWait,
|
|
8
|
+
BlockTopology,
|
|
8
9
|
} from "./interface";
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
11
|
// @ts-ignore
|
|
11
12
|
import { koinos } from "./protoModules/protocol-proto.js";
|
|
12
13
|
import { decodeBase64url, encodeBase64url } from "./utils";
|
|
14
|
+
import { Serializer } from "./Serializer";
|
|
13
15
|
|
|
14
16
|
/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
|
|
15
17
|
|
|
@@ -32,10 +34,7 @@ export class Provider {
|
|
|
32
34
|
*
|
|
33
35
|
* @example
|
|
34
36
|
* ```ts
|
|
35
|
-
* const provider = new Provider([
|
|
36
|
-
* "http://45.56.104.152:8080",
|
|
37
|
-
* "http://159.203.119.0:8080"
|
|
38
|
-
* ]);
|
|
37
|
+
* const provider = new Provider(["https://api.koinos.io"]);
|
|
39
38
|
*
|
|
40
39
|
* provider.onError = (error, node, newNode) => {
|
|
41
40
|
* console.log(`Error from node ${node}: ${error.message}`);
|
|
@@ -219,7 +218,13 @@ export class Provider {
|
|
|
219
218
|
});
|
|
220
219
|
}
|
|
221
220
|
|
|
222
|
-
async getBlocksById(
|
|
221
|
+
async getBlocksById(
|
|
222
|
+
blockIds: string[],
|
|
223
|
+
opts?: {
|
|
224
|
+
returnBlock: boolean;
|
|
225
|
+
returnReceipt: boolean;
|
|
226
|
+
}
|
|
227
|
+
): Promise<{
|
|
223
228
|
block_items: {
|
|
224
229
|
block_id: string;
|
|
225
230
|
block_height: string;
|
|
@@ -228,8 +233,10 @@ export class Provider {
|
|
|
228
233
|
}> {
|
|
229
234
|
return this.call("block_store.get_blocks_by_id", {
|
|
230
235
|
block_ids: blockIds,
|
|
231
|
-
return_block:
|
|
232
|
-
|
|
236
|
+
return_block:
|
|
237
|
+
opts && opts.returnBlock !== undefined ? opts.returnBlock : true,
|
|
238
|
+
return_receipt:
|
|
239
|
+
opts && opts.returnReceipt !== undefined ? opts.returnReceipt : false,
|
|
233
240
|
});
|
|
234
241
|
}
|
|
235
242
|
|
|
@@ -238,21 +245,13 @@ export class Provider {
|
|
|
238
245
|
*/
|
|
239
246
|
async getHeadInfo(): Promise<{
|
|
240
247
|
head_block_time: string;
|
|
241
|
-
head_topology:
|
|
242
|
-
id: string;
|
|
243
|
-
height: string;
|
|
244
|
-
previous: string;
|
|
245
|
-
};
|
|
248
|
+
head_topology: BlockTopology;
|
|
246
249
|
head_state_merkle_root: string;
|
|
247
250
|
last_irreversible_block: string;
|
|
248
251
|
}> {
|
|
249
252
|
return this.call<{
|
|
250
253
|
head_block_time: string;
|
|
251
|
-
head_topology:
|
|
252
|
-
id: string;
|
|
253
|
-
height: string;
|
|
254
|
-
previous: string;
|
|
255
|
-
};
|
|
254
|
+
head_topology: BlockTopology;
|
|
256
255
|
head_state_merkle_root: string;
|
|
257
256
|
last_irreversible_block: string;
|
|
258
257
|
}>("chain.get_head_info", {});
|
|
@@ -280,7 +279,11 @@ export class Provider {
|
|
|
280
279
|
async getBlocks(
|
|
281
280
|
height: number,
|
|
282
281
|
numBlocks = 1,
|
|
283
|
-
idRef?: string
|
|
282
|
+
idRef?: string,
|
|
283
|
+
opts?: {
|
|
284
|
+
returnBlock: boolean;
|
|
285
|
+
returnReceipt: boolean;
|
|
286
|
+
}
|
|
284
287
|
): Promise<
|
|
285
288
|
{
|
|
286
289
|
block_id: string;
|
|
@@ -310,8 +313,10 @@ export class Provider {
|
|
|
310
313
|
head_block_id: blockIdRef,
|
|
311
314
|
ancestor_start_height: height,
|
|
312
315
|
num_blocks: numBlocks,
|
|
313
|
-
return_block:
|
|
314
|
-
|
|
316
|
+
return_block:
|
|
317
|
+
opts && opts.returnBlock !== undefined ? opts.returnBlock : true,
|
|
318
|
+
return_receipt:
|
|
319
|
+
opts && opts.returnReceipt !== undefined ? opts.returnReceipt : false,
|
|
315
320
|
})
|
|
316
321
|
).block_items;
|
|
317
322
|
}
|
|
@@ -507,6 +512,131 @@ export class Provider {
|
|
|
507
512
|
}> {
|
|
508
513
|
return this.call("chain.read_contract", operation);
|
|
509
514
|
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Function to call "chain.get_fork_heads" to get fork heads
|
|
518
|
+
*/
|
|
519
|
+
async getForkHeads(): Promise<{
|
|
520
|
+
last_irreversible_block: BlockTopology;
|
|
521
|
+
fork_heads: BlockTopology[];
|
|
522
|
+
}> {
|
|
523
|
+
return this.call("chain.get_fork_heads", {});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Funciont to call "chain.get_resource_limits" to get
|
|
528
|
+
* resource limits
|
|
529
|
+
*/
|
|
530
|
+
async getResourceLimits(): Promise<{
|
|
531
|
+
resource_limit_data: {
|
|
532
|
+
disk_storage_limit: string;
|
|
533
|
+
disk_storage_cost: string;
|
|
534
|
+
network_bandwidth_limit: string;
|
|
535
|
+
network_bandwidth_cost: string;
|
|
536
|
+
compute_bandwidth_limit: string;
|
|
537
|
+
compute_bandwidth_cost: string;
|
|
538
|
+
};
|
|
539
|
+
}> {
|
|
540
|
+
return this.call("chain.get_resource_limits", {});
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Function to call "chain.invoke_system_call" to invoke a system
|
|
545
|
+
* call.
|
|
546
|
+
*/
|
|
547
|
+
async invokeSystemCall<T = Record<string, unknown>>(
|
|
548
|
+
serializer: Serializer,
|
|
549
|
+
nameOrId: string | number,
|
|
550
|
+
args: Record<string, unknown>,
|
|
551
|
+
callerData?: { caller: string; caller_privilege: number }
|
|
552
|
+
): Promise<T> {
|
|
553
|
+
if (!serializer.argumentsTypeName)
|
|
554
|
+
throw new Error("argumentsTypeName not defined");
|
|
555
|
+
if (!serializer.returnTypeName)
|
|
556
|
+
throw new Error("returnTypeName not defined");
|
|
557
|
+
const argsEncoded = await serializer.serialize(
|
|
558
|
+
args,
|
|
559
|
+
serializer.argumentsTypeName
|
|
560
|
+
);
|
|
561
|
+
const response = await this.call<{ value: string }>(
|
|
562
|
+
"chain.invoke_system_call",
|
|
563
|
+
{
|
|
564
|
+
...(typeof nameOrId === "number" && { id: nameOrId }),
|
|
565
|
+
...(typeof nameOrId === "string" && { name: nameOrId }),
|
|
566
|
+
args: encodeBase64url(argsEncoded),
|
|
567
|
+
caller_data: callerData,
|
|
568
|
+
}
|
|
569
|
+
);
|
|
570
|
+
if (!response || !response.value)
|
|
571
|
+
throw new Error("no value in the response");
|
|
572
|
+
const result = await serializer.deserialize(
|
|
573
|
+
response.value,
|
|
574
|
+
serializer.returnTypeName
|
|
575
|
+
);
|
|
576
|
+
return result as T;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
async invokeGetContractMetadata(contractId: string) {
|
|
580
|
+
const serializer = new Serializer(
|
|
581
|
+
{
|
|
582
|
+
nested: {
|
|
583
|
+
get_contract_metadata_arguments: {
|
|
584
|
+
fields: {
|
|
585
|
+
contract_id: {
|
|
586
|
+
type: "bytes",
|
|
587
|
+
id: 1,
|
|
588
|
+
options: {
|
|
589
|
+
"(koinos.btype)": "CONTRACT_ID",
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
},
|
|
593
|
+
},
|
|
594
|
+
get_contract_metadata_result: {
|
|
595
|
+
fields: {
|
|
596
|
+
value: {
|
|
597
|
+
type: "contract_metadata_object",
|
|
598
|
+
id: 1,
|
|
599
|
+
},
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
contract_metadata_object: {
|
|
603
|
+
fields: {
|
|
604
|
+
hash: {
|
|
605
|
+
type: "bytes",
|
|
606
|
+
id: 1,
|
|
607
|
+
options: {
|
|
608
|
+
"(koinos.btype)": "HEX",
|
|
609
|
+
},
|
|
610
|
+
},
|
|
611
|
+
system: {
|
|
612
|
+
type: "bool",
|
|
613
|
+
id: 2,
|
|
614
|
+
},
|
|
615
|
+
authorizes_call_contract: {
|
|
616
|
+
type: "bool",
|
|
617
|
+
id: 3,
|
|
618
|
+
},
|
|
619
|
+
authorizes_transaction_application: {
|
|
620
|
+
type: "bool",
|
|
621
|
+
id: 4,
|
|
622
|
+
},
|
|
623
|
+
authorizes_upload_contract: {
|
|
624
|
+
type: "bool",
|
|
625
|
+
id: 5,
|
|
626
|
+
},
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
argumentsTypeName: "get_contract_metadata_arguments",
|
|
633
|
+
returnTypeName: "get_contract_metadata_result",
|
|
634
|
+
}
|
|
635
|
+
);
|
|
636
|
+
return this.invokeSystemCall(serializer, "get_contract_metadata", {
|
|
637
|
+
contract_id: contractId,
|
|
638
|
+
});
|
|
639
|
+
}
|
|
510
640
|
}
|
|
511
641
|
|
|
512
642
|
export default Provider;
|
package/src/Serializer.ts
CHANGED
|
@@ -103,6 +103,18 @@ export class Serializer {
|
|
|
103
103
|
*/
|
|
104
104
|
defaultType?: Type;
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Type name for arguments when using
|
|
108
|
+
* [[Provider.invokeSystemCall]]
|
|
109
|
+
*/
|
|
110
|
+
argumentsTypeName?: string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Type name for the output when using
|
|
114
|
+
* [[Provider.invokeSystemCall]]
|
|
115
|
+
*/
|
|
116
|
+
returnTypeName?: string;
|
|
117
|
+
|
|
106
118
|
/**
|
|
107
119
|
* Preformat bytes for base64url, base58 or hex string
|
|
108
120
|
*/
|
|
@@ -126,6 +138,18 @@ export class Serializer {
|
|
|
126
138
|
*/
|
|
127
139
|
defaultTypeName?: string;
|
|
128
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Type name for arguments when using
|
|
143
|
+
* [[Provider.invokeSystemCall]]
|
|
144
|
+
*/
|
|
145
|
+
argumentsTypeName?: string;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Type name for the output when using
|
|
149
|
+
* [[Provider.invokeSystemCall]]
|
|
150
|
+
*/
|
|
151
|
+
returnTypeName?: string;
|
|
152
|
+
|
|
129
153
|
/**
|
|
130
154
|
* Bytes conversion. Option to preformat bytes
|
|
131
155
|
* when "(koinos_bytes_type)" is defined in the type
|
|
@@ -146,6 +170,9 @@ export class Serializer {
|
|
|
146
170
|
}
|
|
147
171
|
if (opts?.defaultTypeName)
|
|
148
172
|
this.defaultType = this.root.lookupType(opts.defaultTypeName);
|
|
173
|
+
if (opts?.argumentsTypeName)
|
|
174
|
+
this.argumentsTypeName = opts.argumentsTypeName;
|
|
175
|
+
if (opts?.returnTypeName) this.returnTypeName = opts.returnTypeName;
|
|
149
176
|
if (opts && typeof opts.bytesConversion !== "undefined")
|
|
150
177
|
this.bytesConversion = opts.bytesConversion;
|
|
151
178
|
}
|