polkadot-api 1.2.0 → 1.3.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/esm/compatibility.mjs +0 -1
- package/dist/esm/compatibility.mjs.map +1 -1
- package/dist/esm/constants.mjs +2 -0
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/event.mjs +7 -0
- package/dist/esm/event.mjs.map +1 -1
- package/dist/esm/runtime-call.mjs +6 -1
- package/dist/esm/runtime-call.mjs.map +1 -1
- package/dist/esm/storage.mjs +12 -5
- package/dist/esm/storage.mjs.map +1 -1
- package/dist/esm/tx/tx.mjs +26 -8
- package/dist/esm/tx/tx.mjs.map +1 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +51 -13
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -22,7 +22,6 @@ var OpType = /* @__PURE__ */ ((OpType2) => {
|
|
|
22
22
|
OpType2["Storage"] = "storage";
|
|
23
23
|
OpType2["Tx"] = "tx";
|
|
24
24
|
OpType2["Event"] = "events";
|
|
25
|
-
OpType2["Error"] = "errors";
|
|
26
25
|
OpType2["Const"] = "constants";
|
|
27
26
|
return OpType2;
|
|
28
27
|
})(OpType || {});
|
|
@@ -162,6 +161,8 @@ const createConstantEntry = (palletName, name, {
|
|
|
162
161
|
(p) => p.name === palletName
|
|
163
162
|
);
|
|
164
163
|
const constant = pallet?.constants.find((c) => c.name === name);
|
|
164
|
+
if (constant == null)
|
|
165
|
+
throw new Error(`Runtime entry Constant(${palletName}.${name}) not found`);
|
|
165
166
|
const result = ctx.dynamicBuilder.buildConstant(palletName, name).dec(constant.value);
|
|
166
167
|
cachedResults.set(ctx, result);
|
|
167
168
|
return result;
|
|
@@ -377,6 +378,13 @@ const createEventEntry = (pallet, name, chainHead, {
|
|
|
377
378
|
const shared$ = chainHead.finalized$.pipe(
|
|
378
379
|
withCompatibleRuntime(chainHead, (x) => x.hash),
|
|
379
380
|
rxjs.map(([block, runtime, ctx]) => {
|
|
381
|
+
const eventsIdx = ctx.lookup.metadata.pallets.find(
|
|
382
|
+
(p) => p.name === pallet
|
|
383
|
+
)?.events;
|
|
384
|
+
if (eventsIdx == null || ctx.lookup.metadata.lookup[eventsIdx].def.tag !== "variant" || ctx.lookup.metadata.lookup[eventsIdx].def.value.find(
|
|
385
|
+
(ev) => ev.name === name
|
|
386
|
+
) == null)
|
|
387
|
+
throw new Error(`Runtime entry Event(${pallet}.${name}) not found`);
|
|
380
388
|
if (!argsAreCompatible(runtime, ctx, null)) throw compatibilityError();
|
|
381
389
|
return [block, runtime, ctx];
|
|
382
390
|
}),
|
|
@@ -424,8 +432,13 @@ const createRuntimeCallEntry = (api, method, chainHead, {
|
|
|
424
432
|
const at = _at ?? null;
|
|
425
433
|
const result$ = compatibleRuntime$(chainHead, at).pipe(
|
|
426
434
|
rxjs.mergeMap(([runtime, ctx]) => {
|
|
435
|
+
let codecs;
|
|
436
|
+
try {
|
|
437
|
+
codecs = ctx.dynamicBuilder.buildRuntimeCall(api, method);
|
|
438
|
+
} catch {
|
|
439
|
+
throw new Error(`Runtime entry RuntimeCall(${callName}) not found`);
|
|
440
|
+
}
|
|
427
441
|
if (!argsAreCompatible(runtime, ctx, args)) throw compatibilityError();
|
|
428
|
-
const codecs = ctx.dynamicBuilder.buildRuntimeCall(api, method);
|
|
429
442
|
return chainHead.call$(at, callName, utils.toHex(codecs.args.enc(args))).pipe(
|
|
430
443
|
rxjs.map(codecs.value.dec),
|
|
431
444
|
rxjs.map((value) => {
|
|
@@ -453,6 +466,13 @@ const createStorageEntry = (pallet, name, chainHead, {
|
|
|
453
466
|
const isSystemNumber = pallet === "System" && name === "Number";
|
|
454
467
|
const incompatibleError = () => new Error(`Incompatible runtime entry Storage(${pallet}.${name})`);
|
|
455
468
|
const invalidArgs = (args) => new Error(`Invalid Arguments calling ${pallet}.${name}(${args})`);
|
|
469
|
+
const getCodec = (ctx) => {
|
|
470
|
+
try {
|
|
471
|
+
return ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
472
|
+
} catch {
|
|
473
|
+
throw new Error(`Runtime entry Storage(${pallet}.${name}) not found`);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
456
476
|
const watchValue = (...args) => {
|
|
457
477
|
const target = args[args.length - 1];
|
|
458
478
|
const actualArgs = target === "best" || target === "finalized" ? args.slice(0, -1) : args;
|
|
@@ -465,9 +485,9 @@ const createStorageEntry = (pallet, name, chainHead, {
|
|
|
465
485
|
rxjs.debounceTime(0),
|
|
466
486
|
withCompatibleRuntime(chainHead, (x) => x.hash),
|
|
467
487
|
raceMap(([block, runtime, ctx]) => {
|
|
488
|
+
const codecs = getCodec(ctx);
|
|
468
489
|
if (!argsAreCompatible(runtime, ctx, actualArgs))
|
|
469
490
|
throw incompatibleError();
|
|
470
|
-
const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
471
491
|
return chainHead.storage$(block.hash, "value", () => codecs.enc(...actualArgs)).pipe(
|
|
472
492
|
rxjs.map((val) => {
|
|
473
493
|
if (!valuesAreCompatible(runtime, ctx, val))
|
|
@@ -507,7 +527,7 @@ const createStorageEntry = (pallet, name, chainHead, {
|
|
|
507
527
|
at,
|
|
508
528
|
"value",
|
|
509
529
|
(ctx) => {
|
|
510
|
-
const codecs = ctx
|
|
530
|
+
const codecs = getCodec(ctx);
|
|
511
531
|
const actualArgs = args.length === codecs.len ? args : args.slice(0, -1);
|
|
512
532
|
if (args !== actualArgs && !isLastArgOptional) throw invalidArgs(args);
|
|
513
533
|
if (!argsAreCompatible(descriptors, ctx, actualArgs))
|
|
@@ -516,7 +536,7 @@ const createStorageEntry = (pallet, name, chainHead, {
|
|
|
516
536
|
},
|
|
517
537
|
null,
|
|
518
538
|
(data, ctx) => {
|
|
519
|
-
const codecs = ctx
|
|
539
|
+
const codecs = getCodec(ctx);
|
|
520
540
|
const value = data === null ? codecs.fallback : codecs.dec(data);
|
|
521
541
|
if (!valuesAreCompatible(descriptors, ctx, value))
|
|
522
542
|
throw incompatibleError();
|
|
@@ -536,9 +556,9 @@ const createStorageEntry = (pallet, name, chainHead, {
|
|
|
536
556
|
at,
|
|
537
557
|
"descendantsValues",
|
|
538
558
|
(ctx) => {
|
|
559
|
+
const codecs = getCodec(ctx);
|
|
539
560
|
if (minCompatLevel(getCompatibilityLevels(descriptors, ctx)) === metadataCompatibility.CompatibilityLevel.Incompatible)
|
|
540
561
|
throw incompatibleError();
|
|
541
|
-
const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
542
562
|
if (args.length > codecs.len) throw invalidArgs(args);
|
|
543
563
|
const actualArgs = args.length > 0 && isLastArgOptional ? args.slice(0, -1) : args;
|
|
544
564
|
if (args.length === codecs.len && actualArgs === args)
|
|
@@ -547,7 +567,7 @@ const createStorageEntry = (pallet, name, chainHead, {
|
|
|
547
567
|
},
|
|
548
568
|
null,
|
|
549
569
|
(values, ctx) => {
|
|
550
|
-
const codecs = ctx
|
|
570
|
+
const codecs = getCodec(ctx);
|
|
551
571
|
if (values.some(
|
|
552
572
|
({ value }) => !valuesAreCompatible(descriptors, ctx, value)
|
|
553
573
|
))
|
|
@@ -915,8 +935,6 @@ const submit = async (chainHead, broadcastTx$, transaction, at) => rxjs.lastValu
|
|
|
915
935
|
});
|
|
916
936
|
|
|
917
937
|
const accountIdEnc = substrateBindings.AccountId().enc;
|
|
918
|
-
const queryInfoRawDec = substrateBindings.Tuple(substrateBindings.compact, substrateBindings.compact, substrateBindings.u8, substrateBindings.u128).dec;
|
|
919
|
-
const queryInfoDec = (input) => queryInfoRawDec(input)[3];
|
|
920
938
|
const fakeSignature = new Uint8Array(64);
|
|
921
939
|
const getFakeSignature = () => fakeSignature;
|
|
922
940
|
const createTxEntry = (pallet, name, chainHead, broadcast, {
|
|
@@ -929,9 +947,15 @@ const createTxEntry = (pallet, name, chainHead, broadcast, {
|
|
|
929
947
|
const fn = (arg) => {
|
|
930
948
|
const getCallDataWithContext = (runtime, arg2, txOptions = {}) => {
|
|
931
949
|
const ctx = getCompatibilityApi(runtime).runtime();
|
|
950
|
+
const { dynamicBuilder, assetId, lookup } = ctx;
|
|
951
|
+
let codecs;
|
|
952
|
+
try {
|
|
953
|
+
codecs = dynamicBuilder.buildCall(pallet, name);
|
|
954
|
+
} catch {
|
|
955
|
+
throw new Error(`Runtime entry Tx(${pallet}.${name}) not found`);
|
|
956
|
+
}
|
|
932
957
|
if (checkCompatibility && !argsAreCompatible(runtime, ctx, arg2))
|
|
933
958
|
throw new Error(`Incompatible runtime entry Tx(${pallet}.${name})`);
|
|
934
|
-
const { dynamicBuilder, assetId, lookup } = ctx;
|
|
935
959
|
let returnOptions = txOptions;
|
|
936
960
|
if (txOptions.asset) {
|
|
937
961
|
if (assetId == null || !metadataCompatibility.isCompatible(
|
|
@@ -945,7 +969,7 @@ const createTxEntry = (pallet, name, chainHead, broadcast, {
|
|
|
945
969
|
asset: dynamicBuilder.buildDefinition(assetId).enc(txOptions.asset)
|
|
946
970
|
};
|
|
947
971
|
}
|
|
948
|
-
const { location, codec } =
|
|
972
|
+
const { location, codec } = codecs;
|
|
949
973
|
return {
|
|
950
974
|
callData: substrateBindings.Binary.fromBytes(
|
|
951
975
|
utils.mergeUint8(new Uint8Array(location), codec.enc(arg2))
|
|
@@ -990,7 +1014,7 @@ const createTxEntry = (pallet, name, chainHead, broadcast, {
|
|
|
990
1014
|
({ tx, block }) => submit$(chainHead, broadcast, tx, block.hash, true)
|
|
991
1015
|
)
|
|
992
1016
|
);
|
|
993
|
-
const
|
|
1017
|
+
const getPaymentInfo = async (from, _options) => {
|
|
994
1018
|
const fakeSigner = signer.getPolkadotSigner(
|
|
995
1019
|
from instanceof Uint8Array ? from : accountIdEnc(from),
|
|
996
1020
|
"Sr25519",
|
|
@@ -998,11 +1022,25 @@ const createTxEntry = (pallet, name, chainHead, broadcast, {
|
|
|
998
1022
|
);
|
|
999
1023
|
const encoded = utils.fromHex(await sign(fakeSigner, _options));
|
|
1000
1024
|
const args = utils.toHex(utils.mergeUint8(encoded, substrateBindings.u32.enc(encoded.length)));
|
|
1025
|
+
const decoder$ = chainHead.getRuntimeContext$(null).pipe(
|
|
1026
|
+
rxjs.map(
|
|
1027
|
+
({ dynamicBuilder: { buildRuntimeCall } }) => buildRuntimeCall("TransactionPaymentApi", "query_info").value[1]
|
|
1028
|
+
)
|
|
1029
|
+
);
|
|
1030
|
+
const call$ = chainHead.call$(
|
|
1031
|
+
null,
|
|
1032
|
+
"TransactionPaymentApi_query_info",
|
|
1033
|
+
args
|
|
1034
|
+
);
|
|
1001
1035
|
return rxjs.firstValueFrom(
|
|
1002
|
-
|
|
1036
|
+
rxjs.combineLatest([call$, decoder$]).pipe(
|
|
1037
|
+
rxjs.map(([result, decoder]) => decoder(result))
|
|
1038
|
+
)
|
|
1003
1039
|
);
|
|
1004
1040
|
};
|
|
1041
|
+
const getEstimatedFees = async (from, _options) => (await getPaymentInfo(from, _options)).partial_fee;
|
|
1005
1042
|
return {
|
|
1043
|
+
getPaymentInfo,
|
|
1006
1044
|
getEstimatedFees,
|
|
1007
1045
|
decodedCall: {
|
|
1008
1046
|
type: pallet,
|