Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@polkadot-api/metadata-builders

Package Overview
Dependencies
Maintainers
2
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polkadot-api/metadata-builders - npm Package Compare versions

Comparing version 0.0.1-eb86fc91637c525cde1c49d99eb3e8eb04ca0f96.1.0 to 0.0.1-ec31ff2f4abd322f732d9950196b5da5c9e75c11.1.0

187

dist/index.d.ts
import * as scale from '@polkadot-api/substrate-bindings';
import { StringRecord, V15, Codec, Decoder, HexString, ResultPayload } from '@polkadot-api/substrate-bindings';
export { Decoder, HexString, StringRecord, V15 } from '@polkadot-api/substrate-bindings';
import { StringRecord, V15, Codec } from '@polkadot-api/substrate-bindings';
type VoidVar = {
type: "primitive";
value: "_void";
};
type MetadataPrimitives = "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256";

@@ -13,6 +8,9 @@ type PrimitiveVar = {

value: MetadataPrimitives;
} | VoidVar;
};
type VoidVar = {
type: "void";
};
type CompactVar = {
type: "compact";
isBig: boolean;
isBig: boolean | null;
};

@@ -25,3 +23,3 @@ type BitSequenceVar = {

};
type TerminalVar = PrimitiveVar | CompactVar | BitSequenceVar | AccountId32;
type TerminalVar = PrimitiveVar | VoidVar | CompactVar | BitSequenceVar | AccountId32;
type TupleVar = {

@@ -39,3 +37,6 @@ type: "tuple";

type: "enum";
value: StringRecord<(TupleVar | StructVar | VoidVar) & {
value: StringRecord<({
type: "lookupEntry";
value: LookupEntry;
} | VoidVar | TupleVar | StructVar) & {
idx: number;

@@ -219,167 +220,5 @@ }>;

buildNamedTuple: (input: StructVar) => string | null;
getAllGeneratedChecksums: () => string[];
};
type UnshapedDecoder = {
shape: Shape;
decoder: Decoder<Decoded>;
};
type VariantBasedBuild = (pallet: string, name: string) => {
view: UnshapedDecoder;
location: [number, number];
};
type GetViewBuilder = (metadata: V15) => {
buildDefinition: (idx: number) => {
shape: Shape;
decoder: Decoder<Decoded>;
};
callDecoder: Decoder<DecodedCall>;
buildEvent: VariantBasedBuild;
buildError: VariantBasedBuild;
buildCall: VariantBasedBuild;
buildConstant: (pallet: string, name: string) => UnshapedDecoder;
};
interface DecodedCall {
pallet: {
value: {
name: string;
idx: number;
};
input: HexString;
};
call: {
value: {
name: string;
idx: number;
};
input: HexString;
docs: string[];
};
args: {
value: StructDecoded;
shape: Shape;
};
}
type WithInputAndPath<T> = T & {
input: HexString;
path?: string[];
};
type VoidDecoded = WithInputAndPath<{
codec: "_void";
value: undefined;
}>;
type BoolDecoded = WithInputAndPath<{
codec: "bool";
value: boolean;
}>;
type StringDecoded = WithInputAndPath<{
codec: "str" | "char";
value: string;
}>;
type NumberDecoded = WithInputAndPath<{
codec: "u8" | "u16" | "u32" | "i8" | "i16" | "i32" | "compactNumber";
value: number;
}>;
type BigNumberDecoded = WithInputAndPath<{
codec: "u64" | "u128" | "u256" | "i64" | "i128" | "i256" | "compactBn";
value: bigint;
}>;
type BitSequenceDecoded = WithInputAndPath<{
codec: "bitSequence";
value: {
bitsLen: number;
bytes: Uint8Array;
};
}>;
type BytesSequenceDecoded = WithInputAndPath<{
codec: "Bytes";
value: HexString;
}>;
type BytesArrayDecoded = WithInputAndPath<{
codec: "BytesArray";
value: HexString;
len: number;
}>;
type AccountIdDecoded = WithInputAndPath<{
codec: "AccountId";
value: {
ss58Prefix: number;
address: string;
};
}>;
type PrimitiveDecoded = VoidDecoded | BoolDecoded | StringDecoded | NumberDecoded | BigNumberDecoded | BitSequenceDecoded | BytesSequenceDecoded | BytesArrayDecoded | AccountIdDecoded;
type SequenceDecoded = WithInputAndPath<{
codec: "Sequence";
value: Array<Decoded>;
}>;
type ArrayDecoded = WithInputAndPath<{
codec: "Array";
value: Array<Decoded>;
}>;
type OptionDecoded = WithInputAndPath<{
codec: "Option";
value: Decoded;
}>;
type ResultDecoded = WithInputAndPath<{
codec: "Result";
value: ResultPayload<Decoded, Decoded>;
}>;
type TupleDecoded = WithInputAndPath<{
codec: "Tuple";
value: Array<Decoded>;
innerDocs: Array<string[]>;
}>;
type StructDecoded = WithInputAndPath<{
codec: "Struct";
value: StringRecord<Decoded>;
innerDocs: StringRecord<string[]>;
}>;
type EnumDecoded = WithInputAndPath<{
codec: "Enum";
value: {
type: string;
value: Decoded;
};
docs: string[];
}>;
type ComplexDecoded = SequenceDecoded | ArrayDecoded | TupleDecoded | StructDecoded | OptionDecoded | ResultDecoded | EnumDecoded;
type Decoded = PrimitiveDecoded | ComplexDecoded;
interface SequenceShape {
codec: "Sequence";
shape: Shape;
}
interface ArrayShape {
codec: "Array";
len: number;
shape: Shape;
}
interface TupleShape {
codec: "Tuple";
shape: Array<Shape>;
}
interface StructShape {
codec: "Struct";
shape: StringRecord<Shape>;
}
interface OptionShape {
codec: "Option";
shape: Shape;
}
interface ResultShape {
codec: "Result";
shape: {
ok: Shape;
ko: Shape;
};
}
interface EnumShape {
codec: "Enum";
shape: StringRecord<Shape>;
}
type ComplexShape = SequenceShape | ArrayShape | TupleShape | StructShape | OptionShape | ResultShape | EnumShape;
type Shape = {
codec: PrimitiveDecoded["codec"];
} | ComplexShape;
declare const getViewBuilder: GetViewBuilder;
export { type AccountId32, type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives, type NumberDecoded, type OptionDecoded, type OptionShape, type OptionVar, type PrimitiveDecoded, type PrimitiveVar, type ResultDecoded, type ResultShape, type ResultVar, type SequenceDecoded, type SequenceShape, type SequenceVar, type Shape, type StringDecoded, type StructDecoded, type StructShape, type StructVar, type TerminalVar, type TupleDecoded, type TupleShape, type TupleVar, type UnshapedDecoder, type Var, type VoidDecoded, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn, getViewBuilder };
export { type AccountId32, type ArrayVar, type BitSequenceVar, type CompactVar, type ComposedVar, type EnumVar, type LookupEntry, type MetadataPrimitives, type OptionVar, type PrimitiveVar, type ResultVar, type SequenceVar, type StructVar, type TerminalVar, type TupleVar, type Var, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn };

@@ -35,4 +35,3 @@ "use strict";

getDynamicBuilder: () => getDynamicBuilder,
getLookupFn: () => getLookupFn,
getViewBuilder: () => getViewBuilder
getLookupFn: () => getLookupFn
});

@@ -42,3 +41,2 @@ module.exports = __toCommonJS(src_exports);

// src/lookups.ts
var voidVar = { type: "primitive", value: "_void" };
var getLookupFn = (lookupData) => {

@@ -80,3 +78,3 @@ const lookups = /* @__PURE__ */ new Map();

if (def.value.length === 0)
return voidVar;
return { type: "void" };
if (def.value.length === 1) {

@@ -111,4 +109,4 @@ if (isAccountId32SearchOn && path.join(",") === "sp_core,crypto,AccountId32") {

const value = getLookupEntryDef(params[0].type);
return value.type === "primitive" && value.value === "_void" ? (
// Option(_void) would return a Codec<undefined> which makes no sense
return value.type === "void" ? (
// Option<void> would return a Codec<undefined> which makes no sense
// Therefore, we better treat it as a bool

@@ -131,3 +129,3 @@ { type: "primitive", value: "bool" }

if (def.value.length === 0)
return voidVar;
return { type: "void" };
const enumValue = {};

@@ -139,5 +137,13 @@ const enumDocs = {};

if (x.fields.length === 0) {
enumValue[key] = { ...voidVar, idx: x.index };
enumValue[key] = { type: "void", idx: x.index };
return;
}
if (x.fields.length === 1 && !x.fields[0].name) {
enumValue[key] = {
type: "lookupEntry",
value: getLookupEntryDef(x.fields[0].type),
idx: x.index
};
return;
}
let allKey = true;

@@ -178,3 +184,8 @@ const values = {};

if (def.tag === "array") {
const { len } = def.value;
const value = getLookupEntryDef(def.value.type);
if (len === 0)
return { type: "void" };
if (len === 1)
return value;
return {

@@ -188,3 +199,3 @@ type: "array",

if (def.value.length === 0)
return voidVar;
return { type: "void" };
if (def.value.length === 1)

@@ -194,2 +205,10 @@ return getLookupEntryDef(def.value[0]);

const innerDocs = def.value.map((x) => lookupData[x].docs);
const areAllSame = value.every((v) => v.id === value[0].id);
if (areAllSame && innerDocs.every((doc) => doc.length === 0)) {
return {
type: "array",
value: value[0],
len: value.length
};
}
return {

@@ -209,2 +228,4 @@ type: "tuple",

const translated = getLookupEntryDef(def.value);
if (translated.type === "void")
return { type: "compact", isBig: null };
const isBig = Number(translated.value.slice(1)) > 32;

@@ -251,2 +272,4 @@ return {

return scale[input.value];
if (input.type === "void")
return scale._void;
if (input.type === "AccountId32")

@@ -258,5 +281,2 @@ return _accountId;

return scale.bitSequence;
if (input.type === "sequence" && input.value.type === "primitive" && input.value.value === "u8") {
return _bytes;
}
const buildNextCodec = (nextInput) => buildCodec(nextInput, cache, stack, _accountId);

@@ -274,2 +294,5 @@ const buildVector = (inner2, len) => {

};
if (input.type === "sequence" && input.value.type === "primitive" && input.value.value === "u8") {
return _bytes;
}
if (input.type === "array") {

@@ -294,6 +317,6 @@ if (input.value.type === "primitive" && input.value.value === "u8")

const dependencies = Object.values(input.value).map((v) => {
if (v.type === "primitive")
if (v.type === "void")
return scale._void;
if (v.type === "tuple" && v.value.length === 1)
return buildNextCodec(v.value[0]);
if (v.type === "lookupEntry")
return buildNextCodec(v.value);
return v.type === "tuple" ? buildTuple(v.value) : buildStruct(v.value);

@@ -361,6 +384,6 @@ });

const buildEnumEntry = (entry) => {
if (entry.type === "primitive")
if (entry.type === "void")
return scale._void;
if (entry.type === "tuple" && entry.value.length === 1)
return buildDefinition(entry.value[0].id);
if (entry.type === "lookupEntry")
return buildDefinition(entry.value.id);
return entry.type === "tuple" ? scale.Tuple(

@@ -427,3 +450,4 @@ ...Object.values(entry.value).map((l) => buildDefinition(l.id))

result: 5n,
enum: 6n
enum: 6n,
void: 7n
};

@@ -444,3 +468,2 @@ var runtimePrimitiveIds = {

var metadataPrimitiveIds = {
_void: runtimePrimitiveIds.undefined,
bool: runtimePrimitiveIds.boolean,

@@ -484,4 +507,6 @@ char: runtimePrimitiveIds.string,

const children = Object.values(entry.value).flatMap((value) => {
if (value.type === "primitive")
if (value.type === "void")
return [];
if (value.type === "lookupEntry")
return value.value;
if (value.type === "struct")

@@ -524,12 +549,11 @@ return Object.values(value.value);

return getChecksum([shapeIds.primitive, metadataPrimitiveIds[input.value]]);
if (input.type === "void")
return getChecksum([shapeIds.void]);
if (input.type === "compact")
return getChecksum([
shapeIds.primitive,
runtimePrimitiveIds[input.isBig ? "bigint" : "number"]
runtimePrimitiveIds[input.isBig || input.isBig === null ? "bigint" : "number"]
]);
if (input.type === "bitSequence")
return getChecksum([shapeIds.primitive, runtimePrimitiveIds.bitSequence]);
if (input.type === "sequence" && input.value.type === "primitive" && input.value.value === "u8") {
return getChecksum([shapeIds.primitive, runtimePrimitiveIds.byteSequence]);
}
if (input.type === "AccountId32") {

@@ -539,7 +563,19 @@ return getChecksum([shapeIds.primitive, runtimePrimitiveIds.accountId]);

if (input.type === "array") {
const innerChecksum = buildNextChecksum(input.value);
const innerValue = input.value;
if (innerValue.type === "primitive" && innerValue.value === "u8") {
return getChecksum([
shapeIds.primitive,
runtimePrimitiveIds.byteSequence,
BigInt(input.len)
]);
}
const innerChecksum = buildNextChecksum(innerValue);
return getChecksum([shapeIds.vector, innerChecksum, BigInt(input.len)]);
}
if (input.type === "sequence") {
const innerChecksum = buildNextChecksum(input.value);
const innerValue = input.value;
if (innerValue.type === "primitive" && innerValue.value === "u8") {
return getChecksum([shapeIds.primitive, runtimePrimitiveIds.byteSequence]);
}
const innerChecksum = buildNextChecksum(innerValue);
return getChecksum([shapeIds.vector, innerChecksum]);

@@ -562,5 +598,7 @@ }

return structLikeBuilder(shapeIds.enum, input.value, (entry) => {
if (entry.type === "lookupEntry")
return buildNextChecksum(entry.value);
switch (entry.type) {
case "primitive":
return metadataPrimitiveIds._void;
case "void":
return getChecksum([shapeIds.void]);
case "tuple":

@@ -742,3 +780,3 @@ return buildTuple(entry.value);

const buildComposite = (input) => {
if (input.type === "primitive")
if (input.type === "void")
return getChecksum([0n]);

@@ -767,8 +805,10 @@ if (input.type === "tuple") {

const palletEntry = metadata.pallets.find((x) => x.name === pallet);
const callsLookup = getLookupEntryDef(
const enumLookup = getLookupEntryDef(
palletEntry[variantType]
);
if (callsLookup.type !== "enum")
buildDefinition(enumLookup.id);
if (enumLookup.type !== "enum")
throw null;
return buildComposite(callsLookup.value[name]);
const entry = enumLookup.value[name];
return entry.type === "lookupEntry" ? buildDefinition(entry.value.id) : buildComposite(entry);
} catch (_) {

@@ -796,304 +836,6 @@ return null;

buildComposite: toStringEnhancer(buildComposite),
buildNamedTuple: toStringEnhancer(buildNamedTuple)
buildNamedTuple: toStringEnhancer(buildNamedTuple),
getAllGeneratedChecksums: () => Array.from(cache.values()).map((v) => v.toString(32))
};
};
// src/view-builder/view-builder.ts
var import_utils3 = require("@polkadot-api/utils");
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
// src/view-builder/shaped-decoders.ts
var import_utils2 = require("@polkadot-api/utils");
var scale2 = __toESM(require("@polkadot-api/substrate-bindings"));
var toHex = import_utils2.toHex;
var createInputValueDecoder = (dec, rest) => scale2.createDecoder((_bytes2) => {
const bytes = _bytes2;
const start = bytes.i;
const value = dec(bytes);
const input = toHex(new Uint8Array(bytes.buffer.slice(start, bytes.i)));
return { ...rest, value, input };
});
var primitiveShapedDecoder = (codec, input, rest) => {
const decoder = createInputValueDecoder(input, { codec, ...rest });
return Object.assign(decoder, {
shape: { codec }
});
};
var complexShapedDecoder = (shape, input, rest) => {
const decoder = createInputValueDecoder(input, { codec: shape.codec, ...rest });
return Object.assign(decoder, {
shape
});
};
var AccountIdShaped = (ss58Prefix = 42) => {
const enhanced = scale2.enhanceDecoder(
scale2.AccountId(ss58Prefix).dec,
(address) => ({
address,
ss58Prefix
})
);
return primitiveShapedDecoder("AccountId", enhanced, {});
};
var BytesArray = (len) => primitiveShapedDecoder("BytesArray", scale2.Hex.dec(len), { len });
var _primitives = [
"_void",
"bool",
"char",
"str",
"u8",
"u16",
"u32",
"i8",
"i16",
"i32",
"u64",
"u128",
"u256",
"i64",
"i128",
"i256",
"compactNumber",
"compactBn",
"bitSequence"
];
var corePrimitives = Object.fromEntries(
_primitives.map((x) => [x, primitiveShapedDecoder(x, scale2[x].dec)])
);
var primitives = {
...corePrimitives,
Bytes: primitiveShapedDecoder("Bytes", scale2.Hex.dec()),
BytesArray,
AccountId: AccountIdShaped()
};
var Sequence = (input) => complexShapedDecoder(
{ codec: "Sequence", shape: input.shape },
scale2.Vector.dec(input)
);
var ArrayDec = (input, len) => complexShapedDecoder(
{ codec: "Array", shape: input.shape, len },
scale2.Vector.dec(input, len)
);
var TupleDec = (...input) => complexShapedDecoder(
{ codec: "Tuple", shape: input.map((x) => x.shape) },
scale2.Tuple.dec(...input)
);
var StructDec = (input) => complexShapedDecoder(
{ codec: "Struct", shape: (0, import_utils2.mapStringRecord)(input, (x) => x.shape) },
scale2.Struct.dec(input)
);
var EnumDec = (input, args) => complexShapedDecoder(
{ codec: "Enum", shape: (0, import_utils2.mapStringRecord)(input, (x) => x.shape) },
scale2.Variant.dec(input, args)
);
var OptionDec = (input) => complexShapedDecoder(
{ codec: "Option", shape: input.shape },
scale2.Option.dec(input)
);
var ResultDec = (ok, ko) => complexShapedDecoder(
{ codec: "Result", shape: { ok: ok.shape, ko: ko.shape } },
scale2.Result.dec(ok, ko)
);
var selfDecoder = (value) => {
let cache = (x) => {
const decoder = value();
const result2 = decoder;
cache = decoder;
return result2(x);
};
const result = (x) => cache(x);
result.shape = { codec: "_void" };
return result;
};
var complex = {
Sequence,
Array: ArrayDec,
Tuple: TupleDec,
Struct: StructDec,
Enum: EnumDec,
Option: OptionDec,
Result: ResultDec
};
// src/view-builder/view-builder.ts
var emptyTuple = complex.Tuple();
var toUnshapedDecoder = (fn) => (...args) => {
const value = fn(...args);
return {
shape: value.shape,
decoder: value
};
};
var withProp = (input, propName, propValue) => {
const decoder = (0, import_substrate_bindings2.enhanceDecoder)(input, (x) => ({
...x,
[propName]: propValue
}));
decoder.shape = input.shape;
return decoder;
};
var addPath = (fn) => (input, cache, stack, lookupData, ...rest) => {
const { path } = lookupData[input.id];
const base = fn(input, cache, stack, lookupData, ...rest);
return path.length ? withProp(base, "path", path) : base;
};
var _buildShapedDecoder = (input, cache, stack, lookupData, _accountId) => {
if (input.type === "primitive")
return primitives[input.value];
if (input.type === "AccountId32")
return _accountId;
if (input.type === "compact")
return input.isBig ? primitives.compactBn : primitives.compactNumber;
if (input.type === "bitSequence")
return primitives.bitSequence;
if (input.type === "sequence" && input.value.type === "primitive" && input.value.value === "u8") {
return primitives.Bytes;
}
const buildNext = (nextInput) => buildShapedDecoder(nextInput, cache, stack, lookupData, _accountId);
const buildVector = (inner2, len) => {
const _inner = buildNext(inner2);
return len ? complex.Array(_inner, len) : complex.Sequence(_inner);
};
const buildTuple = (value, innerDocs) => withProp(complex.Tuple(...value.map(buildNext)), "innerDocs", innerDocs);
const buildStruct = (value, innerDocs) => withProp(
complex.Struct((0, import_utils3.mapStringRecord)(value, buildNext)),
"innerDocs",
innerDocs
);
if (input.type === "array") {
if (input.value.type === "primitive" && input.value.value === "u8") {
return primitives.BytesArray(input.len);
}
return buildVector(input.value, input.len);
}
if (input.type === "sequence")
return buildVector(input.value);
if (input.type === "tuple")
return buildTuple(input.value, input.innerDocs);
if (input.type === "struct")
return buildStruct(input.value, input.innerDocs);
if (input.type === "option")
return complex.Option(buildNext(input.value));
if (input.type === "result")
return complex.Result(buildNext(input.value.ok), buildNext(input.value.ko));
const dependencies = Object.values(input.value).map((v) => {
if (v.type === "primitive")
return primitives._void;
if (v.type === "tuple" && v.value.length === 1) {
return buildNext(v.value[0]);
}
return v.type === "tuple" ? buildTuple(v.value, v.innerDocs) : buildStruct(v.value, v.innerDocs);
});
const inner = Object.fromEntries(
Object.keys(input.value).map((key, idx) => [key, dependencies[idx]])
);
const indexes = Object.values(input.value).map((x) => x.idx);
const areIndexesSorted = indexes.every((idx, i) => idx === i);
const withoutDocs = areIndexesSorted ? complex.Enum(inner) : complex.Enum(inner, indexes);
const withDocs = (0, import_substrate_bindings2.enhanceDecoder)(withoutDocs, (val) => {
const docs = input.innerDocs[val.value.type];
return {
...val,
docs
};
});
withDocs.shape = withoutDocs.shape;
return withDocs;
};
var withPath = addPath(_buildShapedDecoder);
var buildShapedDecoder = withCache(withPath, selfDecoder, (outter, inner) => {
inner.shape = outter.shape;
return outter;
});
var hexStrFromByte = (input) => `0x${input.toString(16).padEnd(2, "0")}`;
var getViewBuilder = (metadata) => {
const lookupData = metadata.lookup;
const cache = /* @__PURE__ */ new Map();
const getDecoder = (id) => buildShapedDecoder(
getLookupEntryDef(id),
cache,
/* @__PURE__ */ new Set(),
lookupData,
_accountId
);
const getLookupEntryDef = getLookupFn(lookupData);
let _accountId = primitives.AccountId;
const prefix = metadata.pallets.find((x) => x.name === "System")?.constants.find((x) => x.name === "SS58Prefix");
if (prefix) {
try {
const prefixVal = getDecoder(prefix.type)(prefix.value).value;
if (typeof prefixVal === "number")
_accountId = AccountIdShaped(prefixVal);
} catch (_) {
}
}
const buildDefinition = toUnshapedDecoder(getDecoder);
const callDecoder = (0, import_substrate_bindings2.createDecoder)((bytes) => {
const palletIdx = import_substrate_bindings2.u8.dec(bytes);
const palletEntry = metadata.pallets.find((x) => x.index === palletIdx);
if (!palletEntry)
throw new Error("Invalid Pallet");
const pallet = {
value: {
name: palletEntry.name,
idx: palletIdx
},
input: hexStrFromByte(bytes[0])
};
const callsDecoder = getDecoder(palletEntry.calls);
const decoded = callsDecoder(bytes);
if (decoded.codec !== "Enum")
throw null;
const call = {
value: {
name: decoded.value.type,
idx: bytes[1]
},
input: hexStrFromByte(bytes[1]),
docs: decoded.docs
};
return {
pallet,
call,
args: { value: decoded.value.value, shape: callsDecoder.shape }
};
});
const buildEnumEntry = toUnshapedDecoder(
(entry, forceTuple = false) => {
if (entry.type === "primitive")
return forceTuple ? emptyTuple : primitives._void;
return entry.type === "tuple" ? complex.Tuple(
...Object.values(entry.value).map((l) => getDecoder(l.id))
) : complex.Struct(
(0, import_utils3.mapObject)(
entry.value,
(x) => getDecoder(x.id)
)
);
}
);
const buildVariant = (type) => (pallet, name) => {
const palletEntry = metadata.pallets.find((x) => x.name === pallet);
const lookup = getLookupEntryDef(palletEntry[type]);
if (lookup.type !== "enum")
throw null;
const event = lookup.value[name];
return {
location: [palletEntry.index, event.idx],
view: buildEnumEntry(event, type === "calls")
};
};
const buildConstant = (pallet, constantName) => {
const storageEntry = metadata.pallets.find((x) => x.name === pallet).constants.find((s) => s.name === constantName);
return buildDefinition(storageEntry.type);
};
return {
buildDefinition,
callDecoder,
buildEvent: buildVariant("events"),
buildError: buildVariant("errors"),
buildCall: buildVariant("calls"),
buildConstant
};
};
//# sourceMappingURL=index.js.map
import * as scale from '@polkadot-api/substrate-bindings';
import { StringRecord, V15, Codec, Decoder, HexString, ResultPayload } from '@polkadot-api/substrate-bindings';
export { Decoder, HexString, StringRecord, V15 } from '@polkadot-api/substrate-bindings';
import { StringRecord, V15, Codec } from '@polkadot-api/substrate-bindings';
type VoidVar = {
type: "primitive";
value: "_void";
};
type MetadataPrimitives = "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256";

@@ -13,6 +8,9 @@ type PrimitiveVar = {

value: MetadataPrimitives;
} | VoidVar;
};
type VoidVar = {
type: "void";
};
type CompactVar = {
type: "compact";
isBig: boolean;
isBig: boolean | null;
};

@@ -25,3 +23,3 @@ type BitSequenceVar = {

};
type TerminalVar = PrimitiveVar | CompactVar | BitSequenceVar | AccountId32;
type TerminalVar = PrimitiveVar | VoidVar | CompactVar | BitSequenceVar | AccountId32;
type TupleVar = {

@@ -39,3 +37,6 @@ type: "tuple";

type: "enum";
value: StringRecord<(TupleVar | StructVar | VoidVar) & {
value: StringRecord<({
type: "lookupEntry";
value: LookupEntry;
} | VoidVar | TupleVar | StructVar) & {
idx: number;

@@ -219,167 +220,5 @@ }>;

buildNamedTuple: (input: StructVar) => string | null;
getAllGeneratedChecksums: () => string[];
};
type UnshapedDecoder = {
shape: Shape;
decoder: Decoder<Decoded>;
};
type VariantBasedBuild = (pallet: string, name: string) => {
view: UnshapedDecoder;
location: [number, number];
};
type GetViewBuilder = (metadata: V15) => {
buildDefinition: (idx: number) => {
shape: Shape;
decoder: Decoder<Decoded>;
};
callDecoder: Decoder<DecodedCall>;
buildEvent: VariantBasedBuild;
buildError: VariantBasedBuild;
buildCall: VariantBasedBuild;
buildConstant: (pallet: string, name: string) => UnshapedDecoder;
};
interface DecodedCall {
pallet: {
value: {
name: string;
idx: number;
};
input: HexString;
};
call: {
value: {
name: string;
idx: number;
};
input: HexString;
docs: string[];
};
args: {
value: StructDecoded;
shape: Shape;
};
}
type WithInputAndPath<T> = T & {
input: HexString;
path?: string[];
};
type VoidDecoded = WithInputAndPath<{
codec: "_void";
value: undefined;
}>;
type BoolDecoded = WithInputAndPath<{
codec: "bool";
value: boolean;
}>;
type StringDecoded = WithInputAndPath<{
codec: "str" | "char";
value: string;
}>;
type NumberDecoded = WithInputAndPath<{
codec: "u8" | "u16" | "u32" | "i8" | "i16" | "i32" | "compactNumber";
value: number;
}>;
type BigNumberDecoded = WithInputAndPath<{
codec: "u64" | "u128" | "u256" | "i64" | "i128" | "i256" | "compactBn";
value: bigint;
}>;
type BitSequenceDecoded = WithInputAndPath<{
codec: "bitSequence";
value: {
bitsLen: number;
bytes: Uint8Array;
};
}>;
type BytesSequenceDecoded = WithInputAndPath<{
codec: "Bytes";
value: HexString;
}>;
type BytesArrayDecoded = WithInputAndPath<{
codec: "BytesArray";
value: HexString;
len: number;
}>;
type AccountIdDecoded = WithInputAndPath<{
codec: "AccountId";
value: {
ss58Prefix: number;
address: string;
};
}>;
type PrimitiveDecoded = VoidDecoded | BoolDecoded | StringDecoded | NumberDecoded | BigNumberDecoded | BitSequenceDecoded | BytesSequenceDecoded | BytesArrayDecoded | AccountIdDecoded;
type SequenceDecoded = WithInputAndPath<{
codec: "Sequence";
value: Array<Decoded>;
}>;
type ArrayDecoded = WithInputAndPath<{
codec: "Array";
value: Array<Decoded>;
}>;
type OptionDecoded = WithInputAndPath<{
codec: "Option";
value: Decoded;
}>;
type ResultDecoded = WithInputAndPath<{
codec: "Result";
value: ResultPayload<Decoded, Decoded>;
}>;
type TupleDecoded = WithInputAndPath<{
codec: "Tuple";
value: Array<Decoded>;
innerDocs: Array<string[]>;
}>;
type StructDecoded = WithInputAndPath<{
codec: "Struct";
value: StringRecord<Decoded>;
innerDocs: StringRecord<string[]>;
}>;
type EnumDecoded = WithInputAndPath<{
codec: "Enum";
value: {
type: string;
value: Decoded;
};
docs: string[];
}>;
type ComplexDecoded = SequenceDecoded | ArrayDecoded | TupleDecoded | StructDecoded | OptionDecoded | ResultDecoded | EnumDecoded;
type Decoded = PrimitiveDecoded | ComplexDecoded;
interface SequenceShape {
codec: "Sequence";
shape: Shape;
}
interface ArrayShape {
codec: "Array";
len: number;
shape: Shape;
}
interface TupleShape {
codec: "Tuple";
shape: Array<Shape>;
}
interface StructShape {
codec: "Struct";
shape: StringRecord<Shape>;
}
interface OptionShape {
codec: "Option";
shape: Shape;
}
interface ResultShape {
codec: "Result";
shape: {
ok: Shape;
ko: Shape;
};
}
interface EnumShape {
codec: "Enum";
shape: StringRecord<Shape>;
}
type ComplexShape = SequenceShape | ArrayShape | TupleShape | StructShape | OptionShape | ResultShape | EnumShape;
type Shape = {
codec: PrimitiveDecoded["codec"];
} | ComplexShape;
declare const getViewBuilder: GetViewBuilder;
export { type AccountId32, type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives, type NumberDecoded, type OptionDecoded, type OptionShape, type OptionVar, type PrimitiveDecoded, type PrimitiveVar, type ResultDecoded, type ResultShape, type ResultVar, type SequenceDecoded, type SequenceShape, type SequenceVar, type Shape, type StringDecoded, type StructDecoded, type StructShape, type StructVar, type TerminalVar, type TupleDecoded, type TupleShape, type TupleVar, type UnshapedDecoder, type Var, type VoidDecoded, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn, getViewBuilder };
export { type AccountId32, type ArrayVar, type BitSequenceVar, type CompactVar, type ComposedVar, type EnumVar, type LookupEntry, type MetadataPrimitives, type OptionVar, type PrimitiveVar, type ResultVar, type SequenceVar, type StructVar, type TerminalVar, type TupleVar, type Var, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn };

2

dist/min/index.js

@@ -1,2 +0,2 @@

"use strict";var se=Object.create;var W=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var pe=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var me=(e,t)=>{for(var i in t)W(e,i,{get:t[i],enumerable:!0})},z=(e,t,i,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of de(t))!le.call(e,n)&&n!==i&&W(e,n,{get:()=>t[n],enumerable:!(c=ue(t,n))||c.enumerable});return e};var K=(e,t,i)=>(i=e!=null?se(pe(e)):{},z(t||!e||!e.__esModule?W(i,"default",{value:e,enumerable:!0}):i,e)),ye=e=>z(W({},"__esModule",{value:!0}),e);var Me={};me(Me,{getChecksumBuilder:()=>ke,getDynamicBuilder:()=>Se,getLookupFn:()=>L,getViewBuilder:()=>ne});module.exports=ye(Me);var q={type:"primitive",value:"_void"},L=e=>{let t=new Map,i=new Set,c=d=>r=>{let p=t.get(r);if(p)return p;if(i.has(r)){let m={id:r};return t.set(r,m),m}i.add(r);let h=d(r);return p=t.get(r),p?Object.assign(p,h):(p={id:r,...h},t.set(r,p)),i.delete(r),p},n=!0,a=c(d=>{let{def:r,path:p,params:h}=e[d];if(r.tag==="composite"){if(r.value.length===0)return q;if(r.value.length===1)return n&&p.join(",")==="sp_core,crypto,AccountId32"?(n=!1,{type:"AccountId32"}):a(r.value[0].type);let m=!0,b={},o={};return r.value.forEach((l,s)=>{m=m&&!!l.name;let u=l.name||s;b[u]=a(l.type),o[u]=l.docs}),m?{type:"struct",value:b,innerDocs:o}:{type:"tuple",value:Object.values(b),innerDocs:Object.values(o)}}if(r.tag==="variant"){if(p.length===1&&p[0]==="Option"&&h.length===1&&h[0].name==="T"){let o=a(h[0].type);return o.type==="primitive"&&o.value==="_void"?{type:"primitive",value:"bool"}:{type:"option",value:o}}if(p.length===1&&p[0]==="Result"&&h.length===2&&h[0].name==="T"&&h[1].name==="E")return{type:"result",value:{ok:a(h[0].type),ko:a(h[1].type)}};if(r.value.length===0)return q;let m={},b={};return r.value.forEach(o=>{let l=o.name;if(b[l]=o.docs,o.fields.length===0){m[l]={...q,idx:o.index};return}let s=!0,u={},y={};o.fields.forEach((v,g)=>{s=s&&!!v.name;let k=v.name||g;u[k]=a(v.type),y[k]=v.docs}),m[l]=s?{type:"struct",value:u,innerDocs:y,idx:o.index}:{type:"tuple",value:Object.values(u),innerDocs:Object.values(y),idx:o.index}}),{type:"enum",value:m,innerDocs:b}}if(r.tag==="sequence")return{type:"sequence",value:a(r.value)};if(r.tag==="array")return{type:"array",value:a(r.value.type),len:r.value.len};if(r.tag==="tuple"){if(r.value.length===0)return q;if(r.value.length===1)return a(r.value[0]);let m=r.value.map(o=>a(o)),b=r.value.map(o=>e[o].docs);return{type:"tuple",value:m,innerDocs:b}}if(r.tag==="primitive")return{type:"primitive",value:r.value.tag};if(r.tag==="compact"){let m=a(r.value);return{type:"compact",isBig:Number(m.value.slice(1))>32}}return{type:r.tag}});return a};var S=K(require("@polkadot-api/substrate-bindings"));var I=(e,t,i)=>(c,n,a,...d)=>{let{id:r}=c;if(n.has(r))return n.get(r);if(a.has(r)){let h=t(()=>n.get(r),c,...d);return n.set(r,h),h}a.add(r);let p=e(c,n,a,...d);return a.delete(r),n.has(r)&&(p=i(p,n.get(r),c,...d)),n.set(r,p),p};var $=require("@polkadot-api/utils"),he=S.Bin(),ve=(e,t,i,c)=>{if(e.type==="primitive")return S[e.value];if(e.type==="AccountId32")return c;if(e.type==="compact")return S.compact;if(e.type==="bitSequence")return S.bitSequence;if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return he;let n=o=>J(o,t,i,c),a=(o,l)=>{let s=n(o);return l?S.Vector(s,l):S.Vector(s)},d=o=>S.Tuple(...o.map(n)),r=o=>{let l=Object.fromEntries(Object.entries(o).map(([s,u])=>[s,n(u)]));return S.Struct(l)};if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?S.Bin(e.len):a(e.value,e.len);if(e.type==="sequence")return a(e.value);if(e.type==="tuple")return d(e.value);if(e.type==="struct")return r(e.value);if(e.type==="option")return S.Option(n(e.value));if(e.type==="result")return S.Result(n(e.value.ok),n(e.value.ko));let p=Object.values(e.value).map(o=>o.type==="primitive"?S._void:o.type==="tuple"&&o.value.length===1?n(o.value[0]):o.type==="tuple"?d(o.value):r(o.value)),h=Object.fromEntries(Object.keys(e.value).map((o,l)=>[o,p[l]])),m=Object.values(e.value).map(o=>o.idx);return m.every((o,l)=>o===l)?S.Variant(h):S.Variant(h,m)},J=I(ve,S.Self,e=>e),Se=e=>{let t=e.lookup,i=L(t),c=S.AccountId(),n=new Map,a=s=>J(i(s),n,new Set,c),d=e.pallets.find(s=>s.name==="System")?.constants.find(s=>s.name==="SS58Prefix"),r;if(d)try{let s=a(d.type).dec(d.value);typeof s=="number"&&(r=s,c=S.AccountId(s))}catch{}let p=new Map,h=(s,u)=>{let y=p.get(s);y||p.set(s,y=S.Storage(s));let v=e.pallets.find(w=>w.name===s).storage.items.find(w=>w.name===u),g=(w,...G)=>{let U=y(...G);return{...U,len:w,fallback:v.modifier===1?U.dec(v.fallback):void 0}};if(v.type.tag==="plain")return g(0,u,a(v.type.value).dec);let{key:k,value:M,hashers:ae}=v.type.value,ce=a(M),O=ae.map(w=>S[w.tag]),ie=O.length===1?[[a(k),O[0]]]:i(k).value.map((w,G)=>[a(w.id),O[G]]);return g(O.length,u,ce.dec,...ie)},m=s=>s.type==="primitive"?S._void:s.type==="tuple"&&s.value.length===1?a(s.value[0].id):s.type==="tuple"?S.Tuple(...Object.values(s.value).map(u=>a(u.id))):S.Struct((0,$.mapObject)(s.value,u=>a(u.id))),b=(s,u)=>{let y=e.pallets.find(v=>v.name===s).constants.find(v=>v.name===u);return a(y.type)},o=s=>(u,y)=>{let v=e.pallets.find(M=>M.name===u),g=i(v[s]);if(g.type!=="enum")throw null;let k=g.value[y];return{location:[v.index,k.idx],codec:m(g.value[y])}},l=(s,u)=>{let y=e.apis.find(v=>v.name===s)?.methods.find(v=>v.name===u);if(!y)throw null;return{args:S.Tuple(...y.inputs.map(v=>a(v.type))),value:a(y.output)}};return{buildDefinition:a,buildStorage:h,buildEvent:o("events"),buildError:o("errors"),buildRuntimeCall:l,buildCall:o("calls"),buildConstant:b,ss58Prefix:r}};var H=require("@polkadot-api/substrate-bindings");var Q=new TextEncoder,be=Q.encode.bind(Q),E=e=>{let t=new Uint8Array(e.length*8),i=new DataView(t.buffer);for(let c=0;c<e.length;c++)i.setBigUint64(c*8,e[c]);return(0,H.h64)(t)},Y=e=>E(e.map(t=>(0,H.h64)(be(t)))),x={primitive:0n,vector:1n,tuple:2n,struct:3n,option:4n,result:5n,enum:6n},D={undefined:0n,number:1n,string:2n,bigint:3n,boolean:4n,bitSequence:5n,byteSequence:6n,accountId:7n},X={_void:D.undefined,bool:D.boolean,char:D.string,str:D.string,u8:D.number,u16:D.number,u32:D.number,u64:D.bigint,u128:D.bigint,u256:D.bigint,i8:D.number,i16:D.number,i32:D.number,i64:D.bigint,i128:D.bigint,i256:D.bigint},j=(e,t,i)=>{let c=Object.entries(t).sort(([d],[r])=>d.localeCompare(r)),n=Y(c.map(([d])=>d)),a=E(c.map(([,d])=>i(d)));return E([e,n,a])},A=(e,t=new Map)=>{if(t.has(e.id))return t;switch(e.type){case"array":case"option":case"sequence":t.set(e.id,[e,new Set([e.value.id])]),A(e.value,t);break;case"enum":{let i=Object.values(e.value).flatMap(c=>c.type==="primitive"?[]:c.type==="struct"?Object.values(c.value):c.value);t.set(e.id,[e,new Set(i.map(c=>c.id))]),i.forEach(c=>A(c,t));break}case"result":t.set(e.id,[e,new Set([e.value.ok.id,e.value.ko.id])]),A(e.value.ok,t),A(e.value.ko,t);break;case"struct":{let i=Object.values(e.value);t.set(e.id,[e,new Set(i.map(c=>c.id))]),i.forEach(c=>A(c,t));break}case"tuple":t.set(e.id,[e,new Set(e.value.map(i=>i.id))]),e.value.forEach(i=>A(i,t));break;default:t.set(e.id,[e,new Set])}return t},fe=(e,t)=>{if(e.type==="primitive")return E([x.primitive,X[e.value]]);if(e.type==="compact")return E([x.primitive,D[e.isBig?"bigint":"number"]]);if(e.type==="bitSequence")return E([x.primitive,D.bitSequence]);if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return E([x.primitive,D.byteSequence]);if(e.type==="AccountId32")return E([x.primitive,D.accountId]);if(e.type==="array"){let n=t(e.value);return E([x.vector,n,BigInt(e.len)])}if(e.type==="sequence"){let n=t(e.value);return E([x.vector,n])}let i=n=>E([x.tuple,...n.map(t)]),c=n=>j(x.struct,n,t);return e.type==="tuple"?i(e.value):e.type==="struct"?c(e.value):e.type==="option"?E([x.option,t(e.value)]):e.type==="result"?E([x.result,t(e.value.ok),t(e.value.ko)]):j(x.enum,e.value,n=>{switch(n.type){case"primitive":return X._void;case"tuple":return i(n.value);case"struct":return c(n.value)}})},ge=e=>{let t=new Map,i=0,c=[],n=[];function a(d){let r={index:i,lowLink:i,onStack:!0};t.set(d,r),i++,c.push(d);let p=e.get(d)[1];for(let h of p){let m=t.get(h);m?m.onStack&&(r.lowLink=Math.min(r.lowLink,m.index)):(a(h),r.lowLink=Math.min(r.lowLink,t.get(h).lowLink))}if(r.lowLink===r.index){let h=new Set,m=-1;do m=c.pop(),t.get(m).onStack=!1,h.add(m);while(m!==d);h.size>1&&n.push(h)}}for(let d of e.keys())t.has(d)||a(d);return n},De=e=>{let t=new Set(e.map((n,a)=>a)),i=new Map(e.map((n,a)=>[a,new Set]));e.forEach((n,a)=>{e.slice(a+1).forEach((d,r)=>{let p=r+a+1;new Set([...n,...d]).size!==n.size+d.size&&(i.get(a).add(p),i.get(p).add(a))})});let c=[];for(;t.size;){let n=new Set,a=[t.values().next().value];for(;a.length;){let d=a.pop();if(!t.has(d))continue;t.delete(d),e[d].forEach(p=>n.add(Number(p))),i.get(d).forEach(p=>a.push(p))}c.push(n)}return c},Ee=(e,t)=>{let i=a=>{let d=a.values().next().value,r=t.get(d)[0];return Array.from(A(r).keys())},c=new Array;function n(a){c.includes(a)||(e.filter(r=>r!==a&&i(a).some(p=>r.has(p))).forEach(r=>n(r)),c.includes(a))||c.push(a)}return e.forEach(a=>n(a)),c},xe=(e,t)=>{if(t.has(e.id))return t.get(e.id);let i=A(e),c=ge(i),n=De(c),a=Ee(n,i),d=(r,p,h=!1)=>{if(!h&&t.has(r.id))return t.get(r.id);let m=fe(r,b=>d(b,p));return p(r.id,m),m};return a.forEach(r=>{r.forEach(p=>t.set(p,0n));for(let p=0;p<r.size;p++){let h=new Map;r.forEach(m=>d(i.get(m)[0],(b,o)=>{(r.has(b)?h:t).set(b,o)},!0)),Array.from(h.entries()).forEach(([m,b])=>t.set(m,b))}}),d(e,(r,p)=>t.set(r,p))},ke=e=>{let t=e.lookup,i=L(t),c=new Map,n=o=>xe(i(o),c),a=(o,l)=>{try{let s=e.pallets.find(k=>k.name===o).storage.items.find(k=>k.name===l);if(s.type.tag==="plain")return n(s.type.value);let{key:u,value:y}=s.type.value,v=n(y),g=n(u);return E([v,g])}catch{return null}},d=(o,l)=>{try{let s=e.apis.find(g=>g.name===o)?.methods.find(g=>g.name===l);if(!s)throw null;let u=Y(s.inputs.map(g=>g.name)),y=E(s.inputs.map(g=>n(g.type))),v=n(s.output);return E([u,y,v])}catch{return null}},r=o=>{if(o.type==="primitive")return E([0n]);if(o.type==="tuple"){let l=Object.values(o.value).map(s=>n(s.id));return E([x.tuple,...l])}return j(x.struct,o.value,l=>n(l.id))},p=o=>j(x.tuple,o.value,l=>n(l.id)),h=o=>(l,s)=>{try{let u=e.pallets.find(v=>v.name===l),y=i(u[o]);if(y.type!=="enum")throw null;return r(y.value[s])}catch{return null}},m=(o,l)=>{try{let s=e.pallets.find(u=>u.name===o).constants.find(u=>u.name===l);return n(s.type)}catch{return null}},b=o=>(...l)=>o(...l)?.toString(32)??null;return{buildDefinition:b(n),buildRuntimeCall:b(d),buildStorage:b(a),buildCall:b(h("calls")),buildEvent:b(h("events")),buildError:b(h("errors")),buildConstant:b(m),buildComposite:b(r),buildNamedTuple:b(p)}};var _=require("@polkadot-api/utils"),P=require("@polkadot-api/substrate-bindings");var T=require("@polkadot-api/utils"),f=K(require("@polkadot-api/substrate-bindings")),Ve=T.toHex,Z=(e,t)=>f.createDecoder(i=>{let c=i,n=c.i,a=e(c),d=Ve(new Uint8Array(c.buffer.slice(n,c.i)));return{...t,value:a,input:d}}),B=(e,t,i)=>{let c=Z(t,{codec:e,...i});return Object.assign(c,{shape:{codec:e}})},R=(e,t,i)=>{let c=Z(t,{codec:e.codec,...i});return Object.assign(c,{shape:e})},N=(e=42)=>{let t=f.enhanceDecoder(f.AccountId(e).dec,i=>({address:i,ss58Prefix:e}));return B("AccountId",t,{})},Ce=e=>B("BytesArray",f.Hex.dec(e),{len:e}),we=["_void","bool","char","str","u8","u16","u32","i8","i16","i32","u64","u128","u256","i64","i128","i256","compactNumber","compactBn","bitSequence"],Ae=Object.fromEntries(we.map(e=>[e,B(e,f[e].dec)])),C={...Ae,Bytes:B("Bytes",f.Hex.dec()),BytesArray:Ce,AccountId:N()},Le=e=>R({codec:"Sequence",shape:e.shape},f.Vector.dec(e)),Re=(e,t)=>R({codec:"Array",shape:e.shape,len:t},f.Vector.dec(e,t)),Pe=(...e)=>R({codec:"Tuple",shape:e.map(t=>t.shape)},f.Tuple.dec(...e)),Te=e=>R({codec:"Struct",shape:(0,T.mapStringRecord)(e,t=>t.shape)},f.Struct.dec(e)),Oe=(e,t)=>R({codec:"Enum",shape:(0,T.mapStringRecord)(e,i=>i.shape)},f.Variant.dec(e,t)),We=e=>R({codec:"Option",shape:e.shape},f.Option.dec(e)),qe=(e,t)=>R({codec:"Result",shape:{ok:e.shape,ko:t.shape}},f.Result.dec(e,t)),ee=e=>{let t=c=>{let n=e(),a=n;return t=n,a(c)},i=c=>t(c);return i.shape={codec:"_void"},i},V={Sequence:Le,Array:Re,Tuple:Pe,Struct:Te,Enum:Oe,Option:We,Result:qe};var Ie=V.Tuple(),te=e=>(...t)=>{let i=e(...t);return{shape:i.shape,decoder:i}},F=(e,t,i)=>{let c=(0,P.enhanceDecoder)(e,n=>({...n,[t]:i}));return c.shape=e.shape,c},je=e=>(t,i,c,n,...a)=>{let{path:d}=n[t.id],r=e(t,i,c,n,...a);return d.length?F(r,"path",d):r},Be=(e,t,i,c,n)=>{if(e.type==="primitive")return C[e.value];if(e.type==="AccountId32")return n;if(e.type==="compact")return e.isBig?C.compactBn:C.compactNumber;if(e.type==="bitSequence")return C.bitSequence;if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return C.Bytes;let a=u=>oe(u,t,i,c,n),d=(u,y)=>{let v=a(u);return y?V.Array(v,y):V.Sequence(v)},r=(u,y)=>F(V.Tuple(...u.map(a)),"innerDocs",y),p=(u,y)=>F(V.Struct((0,_.mapStringRecord)(u,a)),"innerDocs",y);if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?C.BytesArray(e.len):d(e.value,e.len);if(e.type==="sequence")return d(e.value);if(e.type==="tuple")return r(e.value,e.innerDocs);if(e.type==="struct")return p(e.value,e.innerDocs);if(e.type==="option")return V.Option(a(e.value));if(e.type==="result")return V.Result(a(e.value.ok),a(e.value.ko));let h=Object.values(e.value).map(u=>u.type==="primitive"?C._void:u.type==="tuple"&&u.value.length===1?a(u.value[0]):u.type==="tuple"?r(u.value,u.innerDocs):p(u.value,u.innerDocs)),m=Object.fromEntries(Object.keys(e.value).map((u,y)=>[u,h[y]])),b=Object.values(e.value).map(u=>u.idx),l=b.every((u,y)=>u===y)?V.Enum(m):V.Enum(m,b),s=(0,P.enhanceDecoder)(l,u=>{let y=e.innerDocs[u.value.type];return{...u,docs:y}});return s.shape=l.shape,s},_e=je(Be),oe=I(_e,ee,(e,t)=>(t.shape=e.shape,e)),re=e=>`0x${e.toString(16).padEnd(2,"0")}`,ne=e=>{let t=e.lookup,i=new Map,c=o=>oe(n(o),i,new Set,t,a),n=L(t),a=C.AccountId,d=e.pallets.find(o=>o.name==="System")?.constants.find(o=>o.name==="SS58Prefix");if(d)try{let o=c(d.type)(d.value).value;typeof o=="number"&&(a=N(o))}catch{}let r=te(c),p=(0,P.createDecoder)(o=>{let l=P.u8.dec(o),s=e.pallets.find(k=>k.index===l);if(!s)throw new Error("Invalid Pallet");let u={value:{name:s.name,idx:l},input:re(o[0])},y=c(s.calls),v=y(o);if(v.codec!=="Enum")throw null;let g={value:{name:v.value.type,idx:o[1]},input:re(o[1]),docs:v.docs};return{pallet:u,call:g,args:{value:v.value.value,shape:y.shape}}}),h=te((o,l=!1)=>o.type==="primitive"?l?Ie:C._void:o.type==="tuple"?V.Tuple(...Object.values(o.value).map(s=>c(s.id))):V.Struct((0,_.mapObject)(o.value,s=>c(s.id)))),m=o=>(l,s)=>{let u=e.pallets.find(g=>g.name===l),y=n(u[o]);if(y.type!=="enum")throw null;let v=y.value[s];return{location:[u.index,v.idx],view:h(v,o==="calls")}},b=(o,l)=>{let s=e.pallets.find(u=>u.name===o).constants.find(u=>u.name===l);return r(s.type)};return{buildDefinition:r,callDecoder:p,buildEvent:m("events"),buildError:m("errors"),buildCall:m("calls"),buildConstant:b}};
"use strict";var W=Object.create;var A=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var J=(e,r)=>{for(var s in r)A(e,s,{get:r[s],enumerable:!0})},D=(e,r,s,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of H(r))!N.call(e,n)&&n!==s&&A(e,n,{get:()=>r[n],enumerable:!(a=K(r,n))||a.enumerable});return e};var Q=(e,r,s)=>(s=e!=null?W(U(e)):{},D(r||!e||!e.__esModule?A(s,"default",{value:e,enumerable:!0}):s,e)),X=e=>D(A({},"__esModule",{value:!0}),e);var se={};J(se,{getChecksumBuilder:()=>ue,getDynamicBuilder:()=>$,getLookupFn:()=>C});module.exports=X(se);var C=e=>{let r=new Map,s=new Set,a=p=>t=>{let c=r.get(t);if(c)return c;if(s.has(t)){let l={id:t};return r.set(t,l),l}s.add(t);let m=p(t);return c=r.get(t),c?Object.assign(c,m):(c={id:t,...m},r.set(t,c)),s.delete(t),c},n=!0,o=a(p=>{let{def:t,path:c,params:m}=e[p];if(t.tag==="composite"){if(t.value.length===0)return{type:"void"};if(t.value.length===1)return n&&c.join(",")==="sp_core,crypto,AccountId32"?(n=!1,{type:"AccountId32"}):o(t.value[0].type);let l=!0,v={},i={};return t.value.forEach((d,u)=>{l=l&&!!d.name;let g=d.name||u;v[g]=o(d.type),i[g]=d.docs}),l?{type:"struct",value:v,innerDocs:i}:{type:"tuple",value:Object.values(v),innerDocs:Object.values(i)}}if(t.tag==="variant"){if(c.length===1&&c[0]==="Option"&&m.length===1&&m[0].name==="T"){let i=o(m[0].type);return i.type==="void"?{type:"primitive",value:"bool"}:{type:"option",value:i}}if(c.length===1&&c[0]==="Result"&&m.length===2&&m[0].name==="T"&&m[1].name==="E")return{type:"result",value:{ok:o(m[0].type),ko:o(m[1].type)}};if(t.value.length===0)return{type:"void"};let l={},v={};return t.value.forEach(i=>{let d=i.name;if(v[d]=i.docs,i.fields.length===0){l[d]={type:"void",idx:i.index};return}if(i.fields.length===1&&!i.fields[0].name){l[d]={type:"lookupEntry",value:o(i.fields[0].type),idx:i.index};return}let u=!0,g={},b={};i.fields.forEach((f,h)=>{u=u&&!!f.name;let V=f.name||h;g[V]=o(f.type),b[V]=f.docs}),l[d]=u?{type:"struct",value:g,innerDocs:b,idx:i.index}:{type:"tuple",value:Object.values(g),innerDocs:Object.values(b),idx:i.index}}),{type:"enum",value:l,innerDocs:v}}if(t.tag==="sequence")return{type:"sequence",value:o(t.value)};if(t.tag==="array"){let{len:l}=t.value,v=o(t.value.type);return l===0?{type:"void"}:l===1?v:{type:"array",value:v,len:t.value.len}}if(t.tag==="tuple"){if(t.value.length===0)return{type:"void"};if(t.value.length===1)return o(t.value[0]);let l=t.value.map(d=>o(d)),v=t.value.map(d=>e[d].docs);return l.every(d=>d.id===l[0].id)&&v.every(d=>d.length===0)?{type:"array",value:l[0],len:l.length}:{type:"tuple",value:l,innerDocs:v}}if(t.tag==="primitive")return{type:"primitive",value:t.value.tag};if(t.tag==="compact"){let l=o(t.value);return l.type==="void"?{type:"compact",isBig:null}:{type:"compact",isBig:Number(l.value.slice(1))>32}}return{type:t.tag}});return o};var y=Q(require("@polkadot-api/substrate-bindings"));var I=(e,r,s)=>(a,n,o,...p)=>{let{id:t}=a;if(n.has(t))return n.get(t);if(o.has(t)){let m=r(()=>n.get(t),a,...p);return n.set(t,m),m}o.add(t);let c=e(a,n,o,...p);return o.delete(t),n.has(t)&&(c=s(c,n.get(t),a,...p)),n.set(t,c),c};var M=require("@polkadot-api/utils"),Y=y.Bin(),Z=(e,r,s,a)=>{if(e.type==="primitive")return y[e.value];if(e.type==="void")return y._void;if(e.type==="AccountId32")return a;if(e.type==="compact")return y.compact;if(e.type==="bitSequence")return y.bitSequence;let n=i=>B(i,r,s,a),o=(i,d)=>{let u=n(i);return d?y.Vector(u,d):y.Vector(u)},p=i=>y.Tuple(...i.map(n)),t=i=>{let d=Object.fromEntries(Object.entries(i).map(([u,g])=>[u,n(g)]));return y.Struct(d)};if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return Y;if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?y.Bin(e.len):o(e.value,e.len);if(e.type==="sequence")return o(e.value);if(e.type==="tuple")return p(e.value);if(e.type==="struct")return t(e.value);if(e.type==="option")return y.Option(n(e.value));if(e.type==="result")return y.Result(n(e.value.ok),n(e.value.ko));let c=Object.values(e.value).map(i=>i.type==="void"?y._void:i.type==="lookupEntry"?n(i.value):i.type==="tuple"?p(i.value):t(i.value)),m=Object.fromEntries(Object.keys(e.value).map((i,d)=>[i,c[d]])),l=Object.values(e.value).map(i=>i.idx);return l.every((i,d)=>i===d)?y.Variant(m):y.Variant(m,l)},B=I(Z,y.Self,e=>e),$=e=>{let r=e.lookup,s=C(r),a=y.AccountId(),n=new Map,o=u=>B(s(u),n,new Set,a),p=e.pallets.find(u=>u.name==="System")?.constants.find(u=>u.name==="SS58Prefix"),t;if(p)try{let u=o(p.type).dec(p.value);typeof u=="number"&&(t=u,a=y.AccountId(u))}catch{}let c=new Map,m=(u,g)=>{let b=c.get(u);b||c.set(u,b=y.Storage(u));let f=e.pallets.find(L=>L.name===u).storage.items.find(L=>L.name===g),h=(L,...O)=>{let j=b(...O);return{...j,len:L,fallback:f.modifier===1?j.dec(f.fallback):void 0}};if(f.type.tag==="plain")return h(0,g,o(f.type.value).dec);let{key:V,value:x,hashers:G}=f.type.value,F=o(x),R=G.map(L=>y[L.tag]),z=R.length===1?[[o(V),R[0]]]:s(V).value.map((L,O)=>[o(L.id),R[O]]);return h(R.length,g,F.dec,...z)},l=u=>u.type==="void"?y._void:u.type==="lookupEntry"?o(u.value.id):u.type==="tuple"?y.Tuple(...Object.values(u.value).map(g=>o(g.id))):y.Struct((0,M.mapObject)(u.value,g=>o(g.id))),v=(u,g)=>{let b=e.pallets.find(f=>f.name===u).constants.find(f=>f.name===g);return o(b.type)},i=u=>(g,b)=>{let f=e.pallets.find(x=>x.name===g),h=s(f[u]);if(h.type!=="enum")throw null;let V=h.value[b];return{location:[f.index,V.idx],codec:l(h.value[b])}},d=(u,g)=>{let b=e.apis.find(f=>f.name===u)?.methods.find(f=>f.name===g);if(!b)throw null;return{args:y.Tuple(...b.inputs.map(f=>o(f.type))),value:o(b.output)}};return{buildDefinition:o,buildStorage:m,buildEvent:i("events"),buildError:i("errors"),buildRuntimeCall:d,buildCall:i("calls"),buildConstant:v,ss58Prefix:t}};var q=require("@polkadot-api/substrate-bindings");var P=new TextEncoder,ee=P.encode.bind(P),k=e=>{let r=new Uint8Array(e.length*8),s=new DataView(r.buffer);for(let a=0;a<e.length;a++)s.setBigUint64(a*8,e[a]);return(0,q.h64)(r)},_=e=>k(e.map(r=>(0,q.h64)(ee(r)))),E={primitive:0n,vector:1n,tuple:2n,struct:3n,option:4n,result:5n,enum:6n,void:7n},S={undefined:0n,number:1n,string:2n,bigint:3n,boolean:4n,bitSequence:5n,byteSequence:6n,accountId:7n},te={bool:S.boolean,char:S.string,str:S.string,u8:S.number,u16:S.number,u32:S.number,u64:S.bigint,u128:S.bigint,u256:S.bigint,i8:S.number,i16:S.number,i32:S.number,i64:S.bigint,i128:S.bigint,i256:S.bigint},T=(e,r,s)=>{let a=Object.entries(r).sort(([p],[t])=>p.localeCompare(t)),n=_(a.map(([p])=>p)),o=k(a.map(([,p])=>s(p)));return k([e,n,o])},w=(e,r=new Map)=>{if(r.has(e.id))return r;switch(e.type){case"array":case"option":case"sequence":r.set(e.id,[e,new Set([e.value.id])]),w(e.value,r);break;case"enum":{let s=Object.values(e.value).flatMap(a=>a.type==="void"?[]:a.type==="lookupEntry"?a.value:a.type==="struct"?Object.values(a.value):a.value);r.set(e.id,[e,new Set(s.map(a=>a.id))]),s.forEach(a=>w(a,r));break}case"result":r.set(e.id,[e,new Set([e.value.ok.id,e.value.ko.id])]),w(e.value.ok,r),w(e.value.ko,r);break;case"struct":{let s=Object.values(e.value);r.set(e.id,[e,new Set(s.map(a=>a.id))]),s.forEach(a=>w(a,r));break}case"tuple":r.set(e.id,[e,new Set(e.value.map(s=>s.id))]),e.value.forEach(s=>w(s,r));break;default:r.set(e.id,[e,new Set])}return r},re=(e,r)=>{if(e.type==="primitive")return k([E.primitive,te[e.value]]);if(e.type==="void")return k([E.void]);if(e.type==="compact")return k([E.primitive,S[e.isBig||e.isBig===null?"bigint":"number"]]);if(e.type==="bitSequence")return k([E.primitive,S.bitSequence]);if(e.type==="AccountId32")return k([E.primitive,S.accountId]);if(e.type==="array"){let n=e.value;if(n.type==="primitive"&&n.value==="u8")return k([E.primitive,S.byteSequence,BigInt(e.len)]);let o=r(n);return k([E.vector,o,BigInt(e.len)])}if(e.type==="sequence"){let n=e.value;if(n.type==="primitive"&&n.value==="u8")return k([E.primitive,S.byteSequence]);let o=r(n);return k([E.vector,o])}let s=n=>k([E.tuple,...n.map(r)]),a=n=>T(E.struct,n,r);return e.type==="tuple"?s(e.value):e.type==="struct"?a(e.value):e.type==="option"?k([E.option,r(e.value)]):e.type==="result"?k([E.result,r(e.value.ok),r(e.value.ko)]):T(E.enum,e.value,n=>{if(n.type==="lookupEntry")return r(n.value);switch(n.type){case"void":return k([E.void]);case"tuple":return s(n.value);case"struct":return a(n.value)}})},ne=e=>{let r=new Map,s=0,a=[],n=[];function o(p){let t={index:s,lowLink:s,onStack:!0};r.set(p,t),s++,a.push(p);let c=e.get(p)[1];for(let m of c){let l=r.get(m);l?l.onStack&&(t.lowLink=Math.min(t.lowLink,l.index)):(o(m),t.lowLink=Math.min(t.lowLink,r.get(m).lowLink))}if(t.lowLink===t.index){let m=new Set,l=-1;do l=a.pop(),r.get(l).onStack=!1,m.add(l);while(l!==p);m.size>1&&n.push(m)}}for(let p of e.keys())r.has(p)||o(p);return n},oe=e=>{let r=new Set(e.map((n,o)=>o)),s=new Map(e.map((n,o)=>[o,new Set]));e.forEach((n,o)=>{e.slice(o+1).forEach((p,t)=>{let c=t+o+1;new Set([...n,...p]).size!==n.size+p.size&&(s.get(o).add(c),s.get(c).add(o))})});let a=[];for(;r.size;){let n=new Set,o=[r.values().next().value];for(;o.length;){let p=o.pop();if(!r.has(p))continue;r.delete(p),e[p].forEach(c=>n.add(Number(c))),s.get(p).forEach(c=>o.push(c))}a.push(n)}return a},ie=(e,r)=>{let s=o=>{let p=o.values().next().value,t=r.get(p)[0];return Array.from(w(t).keys())},a=new Array;function n(o){a.includes(o)||(e.filter(t=>t!==o&&s(o).some(c=>t.has(c))).forEach(t=>n(t)),a.includes(o))||a.push(o)}return e.forEach(o=>n(o)),a},ae=(e,r)=>{if(r.has(e.id))return r.get(e.id);let s=w(e),a=ne(s),n=oe(a),o=ie(n,s),p=(t,c,m=!1)=>{if(!m&&r.has(t.id))return r.get(t.id);let l=re(t,v=>p(v,c));return c(t.id,l),l};return o.forEach(t=>{t.forEach(c=>r.set(c,0n));for(let c=0;c<t.size;c++){let m=new Map;t.forEach(l=>p(s.get(l)[0],(v,i)=>{(t.has(v)?m:r).set(v,i)},!0)),Array.from(m.entries()).forEach(([l,v])=>r.set(l,v))}}),p(e,(t,c)=>r.set(t,c))},ue=e=>{let r=e.lookup,s=C(r),a=new Map,n=i=>ae(s(i),a),o=(i,d)=>{try{let u=e.pallets.find(V=>V.name===i).storage.items.find(V=>V.name===d);if(u.type.tag==="plain")return n(u.type.value);let{key:g,value:b}=u.type.value,f=n(b),h=n(g);return k([f,h])}catch{return null}},p=(i,d)=>{try{let u=e.apis.find(h=>h.name===i)?.methods.find(h=>h.name===d);if(!u)throw null;let g=_(u.inputs.map(h=>h.name)),b=k(u.inputs.map(h=>n(h.type))),f=n(u.output);return k([g,b,f])}catch{return null}},t=i=>{if(i.type==="void")return k([0n]);if(i.type==="tuple"){let d=Object.values(i.value).map(u=>n(u.id));return k([E.tuple,...d])}return T(E.struct,i.value,d=>n(d.id))},c=i=>T(E.tuple,i.value,d=>n(d.id)),m=i=>(d,u)=>{try{let g=e.pallets.find(h=>h.name===d),b=s(g[i]);if(n(b.id),b.type!=="enum")throw null;let f=b.value[u];return f.type==="lookupEntry"?n(f.value.id):t(f)}catch{return null}},l=(i,d)=>{try{let u=e.pallets.find(g=>g.name===i).constants.find(g=>g.name===d);return n(u.type)}catch{return null}},v=i=>(...d)=>i(...d)?.toString(32)??null;return{buildDefinition:v(n),buildRuntimeCall:v(p),buildStorage:v(o),buildCall:v(m("calls")),buildEvent:v(m("events")),buildError:v(m("errors")),buildConstant:v(l),buildComposite:v(t),buildNamedTuple:v(c),getAllGeneratedChecksums:()=>Array.from(a.values()).map(i=>i.toString(32))}};
//# sourceMappingURL=index.js.map
{
"name": "@polkadot-api/metadata-builders",
"version": "0.0.1-eb86fc91637c525cde1c49d99eb3e8eb04ca0f96.1.0",
"version": "0.0.1-ec31ff2f4abd322f732d9950196b5da5c9e75c11.1.0",
"author": "Josep M Sobrepere (https://github.com/josepot)",

@@ -43,5 +43,8 @@ "repository": {

"dependencies": {
"@polkadot-api/substrate-bindings": "0.0.1-eb86fc91637c525cde1c49d99eb3e8eb04ca0f96.1.0",
"@polkadot-api/utils": "0.0.1-eb86fc91637c525cde1c49d99eb3e8eb04ca0f96.1.0"
"@polkadot-api/utils": "0.0.1-ec31ff2f4abd322f732d9950196b5da5c9e75c11.1.0",
"@polkadot-api/substrate-bindings": "0.0.1-ec31ff2f4abd322f732d9950196b5da5c9e75c11.1.0"
},
"devDependencies": {
"@polkadot-api/metadata-fixtures": "0.0.1-ec31ff2f4abd322f732d9950196b5da5c9e75c11.1.0"
},
"scripts": {

@@ -48,0 +51,0 @@ "build": "tsc --noEmit && tsup-node src/index.ts --clean --sourcemap --platform neutral --target=es2020 --format esm,cjs --dts && tsup-node src/index.ts --clean --sourcemap --platform neutral --target=es2020 --format cjs --dts --minify --out-dir dist/min",

# @polkadot-api/metadata-builders
This package has multiple functions that read a metadata object, denormalizes it, and builds other structures needed for different processes
## getLookupFn
```ts
function getLookupFn(
lookupData: Metadata["lookup"],
): (id: number) => LookupEntry
```
Given the lookup property of a metadata, returns a function that will give the `LookupEntry` for an id.
The `LookupEntry` is a denormalized data structure for one entry in the metadata. It also "shortcuts" type references when those are pointers (composites or tuples of length 1). Essentially, it's a union of each of the different types that can be found in the lookup, mostly equivalent to something like:
```ts
type TerminalVar =
| PrimitiveVar // u8, str, char, i128, etc.
| CompactVar
| BitSequenceVar
| AccountId32
type ComposedVar =
| TupleVar
| StructVar
| SequenceVar
| ArrayVar
| OptionVar
| ResultVar
| EnumVar
type LookupEntry = TerminalVar | ComposedVar
```
Where, for instance, a StructVar is of the shape
```ts
type StructVar = {
type: "struct"
value: Record<string, LookupEntry>
}
```
It's useful to get types referenced by storage calls, etc.
## getDynamicBuilder
```ts
function getDynamicBuilder(lookupData: Metadata): {
buildDefinition: (id: number) => Codec
buildConstant: (pallet: string, name: string) => Codec
buildEvent: (pallet: string, name: string) => VariantEntry
buildError: (pallet: string, name: string) => VariantEntry
buildCall: (pallet: string, name: string) => VariantEntry
buildStorage: (pallet: string, entry: string) => StorageEntry
buildRuntimeCall: (api: string, method: string) => RuntimeEntry
}
```
Generates all the codecs needed to SCALE encode or decode the data for any interaction with the chain.
`buildDefinition` returns the codec for the type identified by the parameter `id`
`buildConstant` returns the codec for the requested constant (equivalent as calling `buildDefinition` with the type id of that constant)
`buildEvent`, `buildError` and `buildCall` return an object with the codec, and the indices of the pallet and entry within the metadata:
```ts
interface VariantEntry {
location: [number, number] // [palletIdx, entryIdx],
codec: Codec
}
```
`buildStorage` creates all the encoders/decoders needed to encode a storage call and decode its result:
```ts
interface StorageEntry {
// Encodes the arguments of the storage call.
enc: (...args: any[]) => string
// Decodes the result from the storage call.
dec: (value: string) => any
// Decodes the arguments of the storage call
keyDecoder: (value: string) => any[]
// Expected number of arguments
len: number
// Decoded fallback value as defined in the metadata entry
fallback: unknown
}
```
Similarly, `buildRuntimeCall` returns the codecs for both encoding the arguments of the runtime call, and the codec for decoding the result
```ts
interface RuntimeEntry {
args: Codec<any[]>
value: Codec<any>
}
```
## getChecksumBuilder
```ts
function getChecksumBuilder(metadata: Metadata): {
buildDefinition: (id: number) => string | null
buildRuntimeCall: (api: string, method: string) => string | null
buildStorage: (pallet: string, entry: string) => string | null
buildCall: (pallet: string, name: string) => string | null
buildEvent: (pallet: string, name: string) => string | null
buildError: (pallet: string, name: string) => string | null
buildConstant: (pallet: string, constantName: string) => string | null
}
```
Generates the checksums for the different components defined in the metadata.
`buildDefinition` builds the checksum of one of the types in the lookup. The rest of the methods build the checksum for each of the interfaces of the chain.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc