@talismn/scale 0.2.0 → 0.2.1
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.
|
@@ -383,6 +383,33 @@ const getStorageKeyPrefix = (palletName, storageName) => {
|
|
|
383
383
|
return utils.toHex(combined);
|
|
384
384
|
};
|
|
385
385
|
|
|
386
|
+
const getConstantValueFromMetadata = (metadata, pallet, constant) => {
|
|
387
|
+
const {
|
|
388
|
+
builder,
|
|
389
|
+
unifiedMetadata
|
|
390
|
+
} = typeof metadata === "string" ? parseMetadataRpc(metadata) : metadata;
|
|
391
|
+
return getConstantValueInner(builder, unifiedMetadata, pallet, constant);
|
|
392
|
+
};
|
|
393
|
+
const getConstantValueInner = (builder, unifiedMetadata, pallet, constant) => {
|
|
394
|
+
try {
|
|
395
|
+
const storageCodec = builder.buildConstant(pallet, constant);
|
|
396
|
+
const encodedValue = unifiedMetadata.pallets.find(({
|
|
397
|
+
name
|
|
398
|
+
}) => name === pallet)?.constants.find(({
|
|
399
|
+
name
|
|
400
|
+
}) => name === constant)?.value;
|
|
401
|
+
if (!encodedValue) throw new Error(`Constant ${pallet}.${constant} not found`);
|
|
402
|
+
return storageCodec.dec(encodedValue);
|
|
403
|
+
} catch (err) {
|
|
404
|
+
log.error("Failed to get constant value from metadata", {
|
|
405
|
+
err,
|
|
406
|
+
pallet,
|
|
407
|
+
constant
|
|
408
|
+
});
|
|
409
|
+
throw err;
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
386
413
|
Object.defineProperty(exports, "getDynamicBuilder", {
|
|
387
414
|
enumerable: true,
|
|
388
415
|
get: function () { return metadataBuilders.getDynamicBuilder; }
|
|
@@ -447,6 +474,7 @@ exports.compactMetadata = compactMetadata;
|
|
|
447
474
|
exports.decodeScale = decodeScale;
|
|
448
475
|
exports.encodeMetadata = encodeMetadata;
|
|
449
476
|
exports.encodeStateKey = encodeStateKey;
|
|
477
|
+
exports.getConstantValueFromMetadata = getConstantValueFromMetadata;
|
|
450
478
|
exports.getMetadataVersion = getMetadataVersion;
|
|
451
479
|
exports.getStorageKeyPrefix = getStorageKeyPrefix;
|
|
452
480
|
exports.magicNumber = magicNumber;
|
|
@@ -383,6 +383,33 @@ const getStorageKeyPrefix = (palletName, storageName) => {
|
|
|
383
383
|
return utils.toHex(combined);
|
|
384
384
|
};
|
|
385
385
|
|
|
386
|
+
const getConstantValueFromMetadata = (metadata, pallet, constant) => {
|
|
387
|
+
const {
|
|
388
|
+
builder,
|
|
389
|
+
unifiedMetadata
|
|
390
|
+
} = typeof metadata === "string" ? parseMetadataRpc(metadata) : metadata;
|
|
391
|
+
return getConstantValueInner(builder, unifiedMetadata, pallet, constant);
|
|
392
|
+
};
|
|
393
|
+
const getConstantValueInner = (builder, unifiedMetadata, pallet, constant) => {
|
|
394
|
+
try {
|
|
395
|
+
const storageCodec = builder.buildConstant(pallet, constant);
|
|
396
|
+
const encodedValue = unifiedMetadata.pallets.find(({
|
|
397
|
+
name
|
|
398
|
+
}) => name === pallet)?.constants.find(({
|
|
399
|
+
name
|
|
400
|
+
}) => name === constant)?.value;
|
|
401
|
+
if (!encodedValue) throw new Error(`Constant ${pallet}.${constant} not found`);
|
|
402
|
+
return storageCodec.dec(encodedValue);
|
|
403
|
+
} catch (err) {
|
|
404
|
+
log.error("Failed to get constant value from metadata", {
|
|
405
|
+
err,
|
|
406
|
+
pallet,
|
|
407
|
+
constant
|
|
408
|
+
});
|
|
409
|
+
throw err;
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
386
413
|
Object.defineProperty(exports, "getDynamicBuilder", {
|
|
387
414
|
enumerable: true,
|
|
388
415
|
get: function () { return metadataBuilders.getDynamicBuilder; }
|
|
@@ -447,6 +474,7 @@ exports.compactMetadata = compactMetadata;
|
|
|
447
474
|
exports.decodeScale = decodeScale;
|
|
448
475
|
exports.encodeMetadata = encodeMetadata;
|
|
449
476
|
exports.encodeStateKey = encodeStateKey;
|
|
477
|
+
exports.getConstantValueFromMetadata = getConstantValueFromMetadata;
|
|
450
478
|
exports.getMetadataVersion = getMetadataVersion;
|
|
451
479
|
exports.getStorageKeyPrefix = getStorageKeyPrefix;
|
|
452
480
|
exports.magicNumber = magicNumber;
|
|
@@ -380,4 +380,31 @@ const getStorageKeyPrefix = (palletName, storageName) => {
|
|
|
380
380
|
return toHex(combined);
|
|
381
381
|
};
|
|
382
382
|
|
|
383
|
-
|
|
383
|
+
const getConstantValueFromMetadata = (metadata, pallet, constant) => {
|
|
384
|
+
const {
|
|
385
|
+
builder,
|
|
386
|
+
unifiedMetadata
|
|
387
|
+
} = typeof metadata === "string" ? parseMetadataRpc(metadata) : metadata;
|
|
388
|
+
return getConstantValueInner(builder, unifiedMetadata, pallet, constant);
|
|
389
|
+
};
|
|
390
|
+
const getConstantValueInner = (builder, unifiedMetadata, pallet, constant) => {
|
|
391
|
+
try {
|
|
392
|
+
const storageCodec = builder.buildConstant(pallet, constant);
|
|
393
|
+
const encodedValue = unifiedMetadata.pallets.find(({
|
|
394
|
+
name
|
|
395
|
+
}) => name === pallet)?.constants.find(({
|
|
396
|
+
name
|
|
397
|
+
}) => name === constant)?.value;
|
|
398
|
+
if (!encodedValue) throw new Error(`Constant ${pallet}.${constant} not found`);
|
|
399
|
+
return storageCodec.dec(encodedValue);
|
|
400
|
+
} catch (err) {
|
|
401
|
+
log.error("Failed to get constant value from metadata", {
|
|
402
|
+
err,
|
|
403
|
+
pallet,
|
|
404
|
+
constant
|
|
405
|
+
});
|
|
406
|
+
throw err;
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
export { compactMetadata, decodeScale, encodeMetadata, encodeStateKey, getConstantValueFromMetadata, getMetadataVersion, getStorageKeyPrefix, magicNumber, papiParse, papiStringify, parseMetadataRpc };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talismn/scale",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"author": "Talisman",
|
|
5
5
|
"homepage": "https://talisman.xyz",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"/dist"
|
|
19
19
|
],
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
21
|
+
"node": ">=20"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@polkadot-api/metadata-builders": "0.12.2",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"jest": "^29.7",
|
|
34
34
|
"ts-jest": "^29.2.5",
|
|
35
35
|
"typescript": "^5.6.3",
|
|
36
|
-
"@talismn/
|
|
37
|
-
"@talismn/
|
|
36
|
+
"@talismn/eslint-config": "0.0.3",
|
|
37
|
+
"@talismn/tsconfig": "0.0.2"
|
|
38
38
|
},
|
|
39
39
|
"eslintConfig": {
|
|
40
40
|
"root": true,
|