polkadot-api 1.8.0 → 1.8.2
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/bin/cli.mjs +1 -1
- package/dist/esm/client.mjs +17 -9
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/compatibility.mjs +16 -2
- package/dist/esm/compatibility.mjs.map +1 -1
- package/dist/esm/storage.mjs.map +1 -1
- package/dist/esm/tx/create-tx.mjs +24 -28
- package/dist/esm/tx/create-tx.mjs.map +1 -1
- package/dist/esm/utils/optional-arg.mjs +1 -1
- package/dist/esm/utils/optional-arg.mjs.map +1 -1
- package/dist/index.js +57 -37
- package/dist/index.js.map +1 -1
- package/dist/umd/index.min.js +3 -3
- package/dist/umd/logs-provider.min.js +1 -1
- package/dist/umd/pjs-signer.min.js +1 -1
- package/dist/umd/polkadot-sdk-compat.min.js +1 -1
- package/dist/umd/ws-provider_web.min.js +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -54,10 +54,18 @@ const createCompatibilityToken = (chainDefinition, chainHead) => {
|
|
|
54
54
|
compatibilityTokenApi.set(token, {
|
|
55
55
|
runtime,
|
|
56
56
|
getPalletEntryPoint(opType, pallet, name) {
|
|
57
|
-
|
|
57
|
+
const idx = descriptors[opType]?.[pallet]?.[name];
|
|
58
|
+
if (idx == null)
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Descriptor for ${opType} ${pallet}.${name} does not exist`
|
|
61
|
+
);
|
|
62
|
+
return entryPoints[idx];
|
|
58
63
|
},
|
|
59
64
|
getApiEntryPoint(name, method) {
|
|
60
|
-
|
|
65
|
+
const idx = descriptors.apis?.[name]?.[method];
|
|
66
|
+
if (idx == null)
|
|
67
|
+
throw new Error(`Descriptor for API ${name}.${method} does not exist`);
|
|
68
|
+
return entryPoints[idx];
|
|
61
69
|
},
|
|
62
70
|
typedefNodes
|
|
63
71
|
});
|
|
@@ -109,6 +117,11 @@ const compatibilityHelper = (descriptors, getDescriptorEntryPoint, getRuntimeEnt
|
|
|
109
117
|
ctx || (ctx = compatibilityApi.runtime());
|
|
110
118
|
const descriptorEntryPoint = getDescriptorEntryPoint(compatibilityApi);
|
|
111
119
|
const runtimeEntryPoint = getRuntimeEntryPoint(ctx);
|
|
120
|
+
if (runtimeEntryPoint == null)
|
|
121
|
+
return {
|
|
122
|
+
args: metadataCompatibility.CompatibilityLevel.Incompatible,
|
|
123
|
+
values: metadataCompatibility.CompatibilityLevel.Incompatible
|
|
124
|
+
};
|
|
112
125
|
const descriptorNodes = compatibilityApi.typedefNodes;
|
|
113
126
|
const cache = getMetadataCache(ctx);
|
|
114
127
|
return metadataCompatibility.entryPointsAreCompatible(
|
|
@@ -139,6 +152,7 @@ const compatibilityHelper = (descriptors, getDescriptorEntryPoint, getRuntimeEnt
|
|
|
139
152
|
if (levels.args > metadataCompatibility.CompatibilityLevel.Partial) return true;
|
|
140
153
|
if (levels.values === metadataCompatibility.CompatibilityLevel.Incompatible) return false;
|
|
141
154
|
const entryPoint = getRuntimeEntryPoint(ctx);
|
|
155
|
+
if (entryPoint == null) return false;
|
|
142
156
|
return metadataCompatibility.valueIsCompatibleWithDest(
|
|
143
157
|
entryPoint.args,
|
|
144
158
|
(id) => getRuntimeTypedef(ctx, id),
|
|
@@ -314,7 +328,7 @@ const continueWith = (mapper) => (source) => new rxjs.Observable((observer) => {
|
|
|
314
328
|
});
|
|
315
329
|
|
|
316
330
|
const isOptionalArg = (lastArg) => typeof lastArg === "object" && lastArg !== null && Object.entries(lastArg).every(
|
|
317
|
-
([k, v]) => k === "at" && (v ===
|
|
331
|
+
([k, v]) => k === "at" && (v === undefined || typeof v === "string") || k === "signal" && (v === undefined || v instanceof AbortSignal)
|
|
318
332
|
);
|
|
319
333
|
|
|
320
334
|
const selfDependent = () => {
|
|
@@ -704,23 +718,6 @@ var chainSignedExtensions = /*#__PURE__*/Object.freeze({
|
|
|
704
718
|
getNonce: getNonce
|
|
705
719
|
});
|
|
706
720
|
|
|
707
|
-
const empty$ = rxjs.of({
|
|
708
|
-
value: empty,
|
|
709
|
-
additionalSigned: empty
|
|
710
|
-
});
|
|
711
|
-
const getCustomSignExt = (obj, key, encoder) => {
|
|
712
|
-
if (!(key in obj)) return empty;
|
|
713
|
-
const x = obj[key];
|
|
714
|
-
return x instanceof Uint8Array ? x : encoder(x);
|
|
715
|
-
};
|
|
716
|
-
const getEncodedSignExtFromCustom = (custom, valueEnc, additionalSignedEnc) => rxjs.of({
|
|
717
|
-
value: getCustomSignExt(custom, "value", valueEnc),
|
|
718
|
-
additionalSigned: getCustomSignExt(
|
|
719
|
-
custom,
|
|
720
|
-
"additionalSigned",
|
|
721
|
-
additionalSignedEnc
|
|
722
|
-
)
|
|
723
|
-
});
|
|
724
721
|
const createTx = (chainHead, signer, callData, atBlock, customSignedExtensions, hinted = {}) => chainHead.getRuntimeContext$(atBlock.hash).pipe(
|
|
725
722
|
rxjs.take(1),
|
|
726
723
|
rxjs.mergeMap((ctx) => {
|
|
@@ -732,7 +729,7 @@ const createTx = (chainHead, signer, callData, atBlock, customSignedExtensions,
|
|
|
732
729
|
at: atBlock.hash,
|
|
733
730
|
from: signer.publicKey
|
|
734
731
|
};
|
|
735
|
-
const mortality = !hinted.mortality ? { period: 64, blockNumber: atBlock.number } : hinted.mortality.mortal ? { period: hinted.mortality.period, blockNumber: atBlock.number } :
|
|
732
|
+
const mortality = !hinted.mortality ? { period: 64, blockNumber: atBlock.number } : hinted.mortality.mortal ? { period: hinted.mortality.period, blockNumber: atBlock.number } : undefined;
|
|
736
733
|
return rxjs.combineLatest(
|
|
737
734
|
Object.fromEntries(
|
|
738
735
|
ctx.lookup.metadata.extrinsic.signedExtensions.map(({ identifier, type, additionalSigned }) => {
|
|
@@ -746,13 +743,28 @@ const createTx = (chainHead, signer, callData, atBlock, customSignedExtensions,
|
|
|
746
743
|
if (identifier === "CheckNonce" && "nonce" in hinted)
|
|
747
744
|
return getNonce(hinted.nonce);
|
|
748
745
|
const fn = chainSignedExtensions[identifier];
|
|
749
|
-
|
|
750
|
-
const
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
746
|
+
if (fn) return fn(signedExtensionsCtx);
|
|
747
|
+
const customEntry = customSignedExtensions[identifier];
|
|
748
|
+
const [[valueEnc], [additionalSignedEnc]] = [
|
|
749
|
+
type,
|
|
750
|
+
additionalSigned
|
|
751
|
+
].map(ctx.dynamicBuilder.buildDefinition);
|
|
752
|
+
try {
|
|
753
|
+
return rxjs.of(
|
|
754
|
+
utils.mapObject(
|
|
755
|
+
{
|
|
756
|
+
value: valueEnc,
|
|
757
|
+
additionalSigned: additionalSignedEnc
|
|
758
|
+
},
|
|
759
|
+
(encoder, key) => {
|
|
760
|
+
const input = customEntry?.[key];
|
|
761
|
+
return input instanceof Uint8Array ? input : encoder(input);
|
|
762
|
+
}
|
|
763
|
+
)
|
|
764
|
+
);
|
|
765
|
+
} catch {
|
|
766
|
+
return null;
|
|
767
|
+
}
|
|
756
768
|
};
|
|
757
769
|
return [identifier, stream()];
|
|
758
770
|
}).filter((x) => x[1])
|
|
@@ -1350,15 +1362,20 @@ const createApi = (compatibilityToken, chainHead, broadcast$) => {
|
|
|
1350
1362
|
compatibilityToken,
|
|
1351
1363
|
(r) => r.getPalletEntryPoint(OpType.Storage, pallet, name),
|
|
1352
1364
|
// TODO this is way sub-optimal. Needs some rethought - maybe a builder for entry points?.
|
|
1353
|
-
(ctx) =>
|
|
1354
|
-
getPallet(ctx, pallet)
|
|
1355
|
-
|
|
1365
|
+
(ctx) => {
|
|
1366
|
+
const item = getPallet(ctx, pallet)?.storage?.items.find(
|
|
1367
|
+
(s) => s.name === name
|
|
1368
|
+
);
|
|
1369
|
+
return item == null ? null : metadataCompatibility.storageEntryPoint(item);
|
|
1370
|
+
}
|
|
1356
1371
|
)
|
|
1357
1372
|
)
|
|
1358
1373
|
);
|
|
1359
1374
|
const getEnumEntry = (ctx, side, id, name) => {
|
|
1375
|
+
if (id == null) return null;
|
|
1360
1376
|
const entry = ctx.lookup(id);
|
|
1361
1377
|
if (entry.type !== "enum") throw new Error("Expected enum");
|
|
1378
|
+
if (entry.value[name] == null) return null;
|
|
1362
1379
|
const node = metadataCompatibility.enumValueEntryPointNode(entry.value[name]);
|
|
1363
1380
|
return {
|
|
1364
1381
|
args: side === "args" ? node : metadataCompatibility.voidEntryPointNode,
|
|
@@ -1374,7 +1391,7 @@ const createApi = (compatibilityToken, chainHead, broadcast$) => {
|
|
|
1374
1391
|
compatibilityHelper(
|
|
1375
1392
|
compatibilityToken,
|
|
1376
1393
|
(r) => r.getPalletEntryPoint(OpType.Tx, pallet, name),
|
|
1377
|
-
(ctx) => getEnumEntry(ctx, "args", getPallet(ctx, pallet)
|
|
1394
|
+
(ctx) => getEnumEntry(ctx, "args", getPallet(ctx, pallet)?.calls, name)
|
|
1378
1395
|
),
|
|
1379
1396
|
true
|
|
1380
1397
|
)
|
|
@@ -1387,7 +1404,7 @@ const createApi = (compatibilityToken, chainHead, broadcast$) => {
|
|
|
1387
1404
|
compatibilityHelper(
|
|
1388
1405
|
compatibilityToken,
|
|
1389
1406
|
(r) => r.getPalletEntryPoint(OpType.Event, pallet, name),
|
|
1390
|
-
(ctx) => getEnumEntry(ctx, "values", getPallet(ctx, pallet)
|
|
1407
|
+
(ctx) => getEnumEntry(ctx, "values", getPallet(ctx, pallet)?.events, name)
|
|
1391
1408
|
)
|
|
1392
1409
|
)
|
|
1393
1410
|
);
|
|
@@ -1398,9 +1415,12 @@ const createApi = (compatibilityToken, chainHead, broadcast$) => {
|
|
|
1398
1415
|
compatibilityHelper(
|
|
1399
1416
|
compatibilityToken,
|
|
1400
1417
|
(r) => r.getPalletEntryPoint(OpType.Const, pallet, name),
|
|
1401
|
-
(ctx) =>
|
|
1402
|
-
getPallet(ctx, pallet)
|
|
1403
|
-
|
|
1418
|
+
(ctx) => {
|
|
1419
|
+
const item = getPallet(ctx, pallet)?.constants.find(
|
|
1420
|
+
(c) => c.name === name
|
|
1421
|
+
)?.type;
|
|
1422
|
+
return item == null ? null : metadataCompatibility.singleValueEntryPoint(item);
|
|
1423
|
+
}
|
|
1404
1424
|
)
|
|
1405
1425
|
)
|
|
1406
1426
|
);
|
|
@@ -1433,7 +1453,7 @@ const createApi = (compatibilityToken, chainHead, broadcast$) => {
|
|
|
1433
1453
|
compatibilityHelper(
|
|
1434
1454
|
compatibilityToken,
|
|
1435
1455
|
(r) => r.getPalletEntryPoint(OpType.Tx, pallet, call),
|
|
1436
|
-
(ctx) => getEnumEntry(ctx, "args", getPallet(ctx, pallet)
|
|
1456
|
+
(ctx) => getEnumEntry(ctx, "args", getPallet(ctx, pallet)?.calls, call)
|
|
1437
1457
|
),
|
|
1438
1458
|
false
|
|
1439
1459
|
)(args);
|