@talismn/scale 0.2.2 → 0.3.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.
- package/dist/{declarations/src/util/parseMetadataRpc.d.ts → index.d.mts} +124 -32
- package/dist/index.d.ts +927 -0
- package/dist/index.js +496 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +449 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +23 -19
- package/dist/declarations/src/index.d.ts +0 -2
- package/dist/declarations/src/log.d.ts +0 -2
- package/dist/declarations/src/papito.d.ts +0 -8
- package/dist/declarations/src/util/Prettify.d.ts +0 -3
- package/dist/declarations/src/util/compactMetadata.d.ts +0 -26
- package/dist/declarations/src/util/decodeScale.d.ts +0 -4
- package/dist/declarations/src/util/encodeMetadata.d.ts +0 -2
- package/dist/declarations/src/util/encodeStateKey.d.ts +0 -3
- package/dist/declarations/src/util/getConstantValueFromMetadata.d.ts +0 -5
- package/dist/declarations/src/util/getMetadataVersion.d.ts +0 -6
- package/dist/declarations/src/util/getStorageKeyPrefix.d.ts +0 -1
- package/dist/declarations/src/util/hash.d.ts +0 -1
- package/dist/declarations/src/util/index.d.ts +0 -10
- package/dist/declarations/src/util/serdePapi.d.ts +0 -30
- package/dist/talismn-scale.cjs.d.ts +0 -1
- package/dist/talismn-scale.cjs.dev.js +0 -483
- package/dist/talismn-scale.cjs.js +0 -7
- package/dist/talismn-scale.cjs.prod.js +0 -483
- package/dist/talismn-scale.esm.js +0 -410
|
@@ -1,4 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
import * as _polkadot_api_metadata_builders from '@polkadot-api/metadata-builders';
|
|
2
|
+
import { getDynamicBuilder } from '@polkadot-api/metadata-builders';
|
|
3
|
+
export { MetadataLookup, getDynamicBuilder, getLookupFn } from '@polkadot-api/metadata-builders';
|
|
4
|
+
import * as _polkadot_api_substrate_bindings from '@polkadot-api/substrate-bindings';
|
|
5
|
+
import { Metadata, UnifiedMetadata } from '@polkadot-api/substrate-bindings';
|
|
6
|
+
export { Binary, Blake2128, Blake2128Concat, Blake2256, Blake3256, Blake3256Concat, Codec, FixedSizeBinary, Twox128, Twox256, Twox64Concat, UnifiedMetadata, decAnyMetadata, metadata, unifyMetadata } from '@polkadot-api/substrate-bindings';
|
|
7
|
+
import * as scale_ts from 'scale-ts';
|
|
8
|
+
export { fromHex, mergeUint8, toHex } from '@polkadot-api/utils';
|
|
9
|
+
|
|
10
|
+
/** Constant: https://docs.substrate.io/build/application-development/#metadata-format */
|
|
11
|
+
declare const magicNumber = 1635018093;
|
|
12
|
+
type MetadataBuilder = ReturnType<typeof getDynamicBuilder>;
|
|
13
|
+
|
|
14
|
+
type MetadataType = SupportedMetadata["lookup"][number];
|
|
15
|
+
type MetadataPallet = SupportedMetadata["pallets"][number];
|
|
16
|
+
type MetadataStorageItem = NonNullable<MetadataPallet["storage"]>["items"][number];
|
|
17
|
+
type SupportedMetadata = Extract<Metadata["metadata"], {
|
|
18
|
+
tag: SupportedMetadataVersion;
|
|
19
|
+
}>["value"];
|
|
20
|
+
type SupportedMetadataVersion = "v14" | "v15" | "v16";
|
|
21
|
+
/**
|
|
22
|
+
* Converts a `Metadata` into a `MiniMetadata`.
|
|
23
|
+
*
|
|
24
|
+
* A `MiniMetadata` only contains the types inside of its `lookup` which are relevant for
|
|
25
|
+
* the storage queries specified in `palletsAndItems`.
|
|
26
|
+
*
|
|
27
|
+
* E.g. if `palletsAndItems` is `{ pallet: "System", items: ["Account"] }`, then only the
|
|
28
|
+
* types used in the `System.Account` storage query will remain inside of metadata.lookups.
|
|
29
|
+
*/
|
|
30
|
+
declare const compactMetadata: (anyMetadata: Metadata, palletsAndItems?: Array<{
|
|
31
|
+
pallet: string;
|
|
32
|
+
constants?: string[];
|
|
33
|
+
items: string[];
|
|
34
|
+
}>, runtimeApisAndMethods?: Array<{
|
|
35
|
+
runtimeApi: string;
|
|
36
|
+
methods: string[];
|
|
37
|
+
}>, extraKeepTypes?: number[]) => void;
|
|
38
|
+
|
|
39
|
+
type ScaleStorageCoder$1 = ReturnType<MetadataBuilder["buildStorage"]>;
|
|
40
|
+
declare const decodeScale: <T>(scaleCoder: ScaleStorageCoder$1 | undefined, change: string | null, error?: string) => T | null;
|
|
41
|
+
|
|
42
|
+
declare const encodeMetadata: (metadata: Metadata) => `0x${string}`;
|
|
43
|
+
|
|
44
|
+
type ScaleStorageCoder = ReturnType<MetadataBuilder["buildStorage"]>;
|
|
45
|
+
declare const encodeStateKey: (scaleCoder: ScaleStorageCoder | undefined, error?: string, ...args: unknown[]) => `0x${string}` | undefined;
|
|
46
|
+
|
|
47
|
+
declare const getConstantValueFromMetadata: <T>(metadata: `0x${string}` | {
|
|
48
|
+
builder: MetadataBuilder;
|
|
49
|
+
unifiedMetadata: UnifiedMetadata;
|
|
50
|
+
}, pallet: string, constant: string) => T;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Extracts the `version` u8 from a SCALE-encoded metadata blob and returns it as a `number`.
|
|
54
|
+
*
|
|
55
|
+
* Only reads the first 40 bytes of the blob.
|
|
56
|
+
*/
|
|
57
|
+
declare const getMetadataVersion: (metadataRpc: string | Uint8Array | ArrayBuffer) => number;
|
|
58
|
+
|
|
59
|
+
declare const getStorageKeyPrefix: (palletName: string, storageName: string) => string;
|
|
60
|
+
|
|
61
|
+
declare const parseMetadataRpc: (metadataRpc: `0x${string}`) => {
|
|
2
62
|
metadata: {
|
|
3
63
|
magicNumber: number;
|
|
4
64
|
metadata: {
|
|
@@ -186,7 +246,7 @@ export declare const parseMetadataRpc: (metadataRpc: `0x${string}`) => {
|
|
|
186
246
|
tag: "plain";
|
|
187
247
|
value: number;
|
|
188
248
|
};
|
|
189
|
-
fallback:
|
|
249
|
+
fallback: _polkadot_api_substrate_bindings.HexString;
|
|
190
250
|
docs: string[];
|
|
191
251
|
}[];
|
|
192
252
|
} | undefined;
|
|
@@ -195,7 +255,7 @@ export declare const parseMetadataRpc: (metadataRpc: `0x${string}`) => {
|
|
|
195
255
|
constants: {
|
|
196
256
|
name: string;
|
|
197
257
|
type: number;
|
|
198
|
-
value:
|
|
258
|
+
value: _polkadot_api_substrate_bindings.HexString;
|
|
199
259
|
docs: string[];
|
|
200
260
|
}[];
|
|
201
261
|
errors: number | undefined;
|
|
@@ -395,7 +455,7 @@ export declare const parseMetadataRpc: (metadataRpc: `0x${string}`) => {
|
|
|
395
455
|
tag: "plain";
|
|
396
456
|
value: number;
|
|
397
457
|
};
|
|
398
|
-
fallback:
|
|
458
|
+
fallback: _polkadot_api_substrate_bindings.HexString;
|
|
399
459
|
docs: string[];
|
|
400
460
|
}[];
|
|
401
461
|
} | undefined;
|
|
@@ -404,7 +464,7 @@ export declare const parseMetadataRpc: (metadataRpc: `0x${string}`) => {
|
|
|
404
464
|
constants: {
|
|
405
465
|
name: string;
|
|
406
466
|
type: number;
|
|
407
|
-
value:
|
|
467
|
+
value: _polkadot_api_substrate_bindings.HexString;
|
|
408
468
|
docs: string[];
|
|
409
469
|
}[];
|
|
410
470
|
errors: number | undefined;
|
|
@@ -443,7 +503,7 @@ export declare const parseMetadataRpc: (metadataRpc: `0x${string}`) => {
|
|
|
443
503
|
};
|
|
444
504
|
custom: [string, {
|
|
445
505
|
type: number;
|
|
446
|
-
value:
|
|
506
|
+
value: _polkadot_api_substrate_bindings.HexString;
|
|
447
507
|
}][];
|
|
448
508
|
};
|
|
449
509
|
} | {
|
|
@@ -601,7 +661,7 @@ export declare const parseMetadataRpc: (metadataRpc: `0x${string}`) => {
|
|
|
601
661
|
tag: "plain";
|
|
602
662
|
value: number;
|
|
603
663
|
};
|
|
604
|
-
fallback:
|
|
664
|
+
fallback: _polkadot_api_substrate_bindings.HexString;
|
|
605
665
|
docs: string[];
|
|
606
666
|
}[];
|
|
607
667
|
} | undefined;
|
|
@@ -640,7 +700,7 @@ export declare const parseMetadataRpc: (metadataRpc: `0x${string}`) => {
|
|
|
640
700
|
constants: {
|
|
641
701
|
name: string;
|
|
642
702
|
type: number;
|
|
643
|
-
value:
|
|
703
|
+
value: _polkadot_api_substrate_bindings.HexString;
|
|
644
704
|
docs: string[];
|
|
645
705
|
deprecationInfo: {
|
|
646
706
|
tag: "NotDeprecated";
|
|
@@ -698,7 +758,7 @@ export declare const parseMetadataRpc: (metadataRpc: `0x${string}`) => {
|
|
|
698
758
|
}[];
|
|
699
759
|
output: number;
|
|
700
760
|
docs: string[];
|
|
701
|
-
id:
|
|
761
|
+
id: _polkadot_api_substrate_bindings.HexString;
|
|
702
762
|
}[];
|
|
703
763
|
index: number;
|
|
704
764
|
docs: string[];
|
|
@@ -775,61 +835,93 @@ export declare const parseMetadataRpc: (metadataRpc: `0x${string}`) => {
|
|
|
775
835
|
};
|
|
776
836
|
custom: [string, {
|
|
777
837
|
type: number;
|
|
778
|
-
value:
|
|
838
|
+
value: _polkadot_api_substrate_bindings.HexString;
|
|
779
839
|
}][];
|
|
780
840
|
};
|
|
781
841
|
};
|
|
782
842
|
};
|
|
783
|
-
unifiedMetadata:
|
|
784
|
-
lookupFn:
|
|
843
|
+
unifiedMetadata: _polkadot_api_substrate_bindings.UnifiedMetadata<14 | 15 | 16>;
|
|
844
|
+
lookupFn: _polkadot_api_metadata_builders.MetadataLookup;
|
|
785
845
|
builder: {
|
|
786
|
-
buildDefinition: (id: number) =>
|
|
846
|
+
buildDefinition: (id: number) => scale_ts.Codec<any>;
|
|
787
847
|
buildStorage: (pallet: string, entry: string) => {
|
|
788
|
-
args: [
|
|
789
|
-
enc:
|
|
790
|
-
dec:
|
|
848
|
+
args: [scale_ts.Encoder<any[]>, scale_ts.Decoder<any[]>] & {
|
|
849
|
+
enc: scale_ts.Encoder<any[]>;
|
|
850
|
+
dec: scale_ts.Decoder<any[]>;
|
|
791
851
|
} & {
|
|
792
|
-
inner:
|
|
852
|
+
inner: scale_ts.Codec<any>[];
|
|
793
853
|
};
|
|
794
854
|
keys: {
|
|
795
855
|
enc: (...args: any[]) => string;
|
|
796
856
|
dec: (value: string) => any[];
|
|
797
857
|
};
|
|
798
|
-
value:
|
|
858
|
+
value: scale_ts.Codec<any>;
|
|
799
859
|
len: number;
|
|
800
860
|
fallback: any;
|
|
801
861
|
};
|
|
802
862
|
buildEvent: (pallet: string, name: string) => {
|
|
803
|
-
codec:
|
|
863
|
+
codec: scale_ts.Codec<any>;
|
|
804
864
|
location: [number, number];
|
|
805
865
|
};
|
|
806
866
|
buildError: (pallet: string, name: string) => {
|
|
807
|
-
codec:
|
|
867
|
+
codec: scale_ts.Codec<any>;
|
|
808
868
|
location: [number, number];
|
|
809
869
|
};
|
|
810
870
|
buildViewFn: (pallet: string, entry: string) => {
|
|
811
|
-
args: [
|
|
812
|
-
enc:
|
|
813
|
-
dec:
|
|
871
|
+
args: [scale_ts.Encoder<any[]>, scale_ts.Decoder<any[]>] & {
|
|
872
|
+
enc: scale_ts.Encoder<any[]>;
|
|
873
|
+
dec: scale_ts.Decoder<any[]>;
|
|
814
874
|
} & {
|
|
815
|
-
inner:
|
|
875
|
+
inner: scale_ts.Codec<any>[];
|
|
816
876
|
};
|
|
817
|
-
value:
|
|
877
|
+
value: scale_ts.Codec<any>;
|
|
818
878
|
};
|
|
819
879
|
buildRuntimeCall: (api: string, method: string) => {
|
|
820
|
-
args: [
|
|
821
|
-
enc:
|
|
822
|
-
dec:
|
|
880
|
+
args: [scale_ts.Encoder<any[]>, scale_ts.Decoder<any[]>] & {
|
|
881
|
+
enc: scale_ts.Encoder<any[]>;
|
|
882
|
+
dec: scale_ts.Decoder<any[]>;
|
|
823
883
|
} & {
|
|
824
|
-
inner:
|
|
884
|
+
inner: scale_ts.Codec<any>[];
|
|
825
885
|
};
|
|
826
|
-
value:
|
|
886
|
+
value: scale_ts.Codec<any>;
|
|
827
887
|
};
|
|
828
888
|
buildCall: (pallet: string, name: string) => {
|
|
829
|
-
codec:
|
|
889
|
+
codec: scale_ts.Codec<any>;
|
|
830
890
|
location: [number, number];
|
|
831
891
|
};
|
|
832
|
-
buildConstant: (pallet: string, constantName: string) =>
|
|
892
|
+
buildConstant: (pallet: string, constantName: string) => scale_ts.Codec<any>;
|
|
833
893
|
ss58Prefix: number | undefined;
|
|
834
894
|
};
|
|
835
895
|
};
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* For the substrate-tokens (and other) modules, we configure the `onChainId` field in chaindata to tell the module how to query each token.
|
|
899
|
+
* These queries are made to the tokens pallet.
|
|
900
|
+
* E.g. api.query.Tokens.Account(accountAddress, papiParse(onChainId))
|
|
901
|
+
*
|
|
902
|
+
* The `onChainId` field on chaindata must be a JSON-parseable string, but for some SCALE types (especially the Binary type) we must
|
|
903
|
+
* use specific `polkadot-api` classes to handle SCALE-encoding the statekey.
|
|
904
|
+
*
|
|
905
|
+
* Some examples:
|
|
906
|
+
* Input: `5`
|
|
907
|
+
* Output: `5`
|
|
908
|
+
*
|
|
909
|
+
* Input: `{ type: "DexShare", value: [ { type: "Token", value: { type: "ACA" } }, { type: "Token", value: { type: "AUSD" } } ] }`
|
|
910
|
+
* Output: `Enum("DexShare", [Enum("Token", Enum("ACA")), Enum("Token", Enum("AUSD"))])`
|
|
911
|
+
*
|
|
912
|
+
* Input: `{ type: "LiquidCrowdloan", value: 13 }`
|
|
913
|
+
* Output: `Enum("LiquidCrowdloan", 13)`
|
|
914
|
+
*
|
|
915
|
+
* Input: `{ type: "NativeToken", value: "bigint:2" }`
|
|
916
|
+
* Output: `Enum("NativeToken", 2n)`
|
|
917
|
+
*
|
|
918
|
+
* Input: `{ type: "Erc20", value: "hex:0x07df96d1341a7d16ba1ad431e2c847d978bc2bce" }`
|
|
919
|
+
* Output: `Enum("Erc20", Binary.fromHex("0x07df96d1341a7d16ba1ad431e2c847d978bc2bce"))`
|
|
920
|
+
*
|
|
921
|
+
* Input: `{ type: "Stellar", value: { code: "bin:TZS", issuer: "hex:0x34c94b2a4ba9e8b57b22547dcbb30f443c4cb02da3829a89aa1bd4780e4466ba" } }`
|
|
922
|
+
* Output: `Enum("Stellar", { code: Binary.fromText("TZS"), issuer: Binary.fromHex("0x34c94b2a4ba9e8b57b22547dcbb30f443c4cb02da3829a89aa1bd4780e4466ba") })`
|
|
923
|
+
*/
|
|
924
|
+
declare const papiParse: <T = unknown>(text: string | T) => T;
|
|
925
|
+
declare const papiStringify: (value: unknown, space?: string | number) => string;
|
|
926
|
+
|
|
927
|
+
export { type MetadataBuilder, type MetadataPallet, type MetadataStorageItem, type MetadataType, type ScaleStorageCoder, compactMetadata, decodeScale, encodeMetadata, encodeStateKey, getConstantValueFromMetadata, getMetadataVersion, getStorageKeyPrefix, magicNumber, papiParse, papiStringify, parseMetadataRpc };
|