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
201
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-5385372d2b5500605bc9e86b6dbd27cfd9c6469c.1.0 to 0.0.1-5438e9d2e4bbfe30fd6a48c7db793443e6c9c1ff.1.0

104

dist/index.d.ts
import * as scale from '@polkadot-api/substrate-bindings';
import { StringRecord, V14, Codec, Decoder, HexString } from '@polkadot-api/substrate-bindings';
export { Decoder, HexString, StringRecord, V14 } 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';

@@ -21,3 +21,6 @@ type VoidVar = {

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

@@ -40,2 +43,13 @@ type: "tuple";

};
type OptionVar = {
type: "option";
value: LookupEntry;
};
type ResultVar = {
type: "result";
value: {
ok: LookupEntry;
ko: LookupEntry;
};
};
type SequenceVar = {

@@ -50,3 +64,3 @@ type: "sequence";

};
type ComposedVar = TupleVar | StructVar | SequenceVar | ArrayVar | EnumVar;
type ComposedVar = TupleVar | StructVar | SequenceVar | ArrayVar | OptionVar | ResultVar | EnumVar;
type Var = TerminalVar | ComposedVar;

@@ -61,3 +75,3 @@ type LookupEntry = {

name: string;
type: number | void | undefined;
type: number | undefined;
}[];

@@ -67,5 +81,5 @@ def: {

value: {
name: string | void | undefined;
name: string | undefined;
type: number;
typeName: string | void | undefined;
typeName: string | undefined;
docs: string[];

@@ -78,5 +92,5 @@ }[];

fields: {
name: string | void | undefined;
name: string | undefined;
type: number;
typeName: string | void | undefined;
typeName: string | undefined;
docs: string[];

@@ -156,5 +170,2 @@ }[];

};
} | {
tag: "historicMetaCompat";
value: string;
};

@@ -165,3 +176,3 @@ docs: string[];

type MetadataPrimitives = "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256";
declare const primitiveTypes: Record<MetadataPrimitives | "_void" | "compactNumber" | "compactBn" | "bitSequence" | "historicMetaCompat", string>;
declare const primitiveTypes: Record<MetadataPrimitives | "_void" | "compactNumber" | "compactBn" | "bitSequence", string>;
interface Variable {

@@ -176,5 +187,6 @@ id: string;

typeImports: Set<string>;
enums: Map<string, string>;
variables: Map<string, Variable>;
}
declare const getStaticBuilder: (metadata: V14) => {
declare const getStaticBuilder: (metadata: V15) => {
buildDefinition: (id: number) => string;

@@ -187,9 +199,14 @@ buildStorage: (pallet: string, entry: string) => {

buildError: (pallet: string, name: string) => string;
buildCall: (pallet: string, callName: string) => string;
buildCall: (pallet: string, name: string) => string;
buildRuntimeCall: (api: string, method: string) => {
args: string;
value: string;
};
buildConstant: (pallet: string, constantName: string) => string;
getTypeFromVarName: (varName: string) => string;
getCode: () => string;
getEnums: () => string[];
};
declare const getDynamicBuilder: (metadata: V14) => {
declare const getDynamicBuilder: (metadata: V15) => {
buildDefinition: (id: number) => Codec<any>;

@@ -217,3 +234,8 @@ buildStorage: (pallet: string, entry: string) => {

};
buildCall: (pallet: string, callName: string) => {
buildRuntimeCall: (api: string, method: string) => {
args: Codec<any[]>;
value: Codec<any>;
};
buildCall: (pallet: string, name: string) => {
args: Codec<any>;
location: [

@@ -223,3 +245,2 @@ number,

];
args: Codec<any>;
};

@@ -230,12 +251,22 @@ buildConstant: (pallet: string, constantName: string) => Codec<any>;

declare const getChecksumBuilder: (metadata: V14) => {
declare const getChecksumBuilder: (metadata: V15) => {
buildDefinition: (id: number) => string | null;
buildRuntimeCall: (api: string, method: string) => string | null;
buildStorage: (pallet: string, entry: string) => string | null;
buildCall: (pallet: string, callName: 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;
buildComposite: (input: VoidVar | TupleVar | StructVar) => string | null;
};
type GetViewBuilder = (metadata: V14) => {
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) => {

@@ -246,2 +277,6 @@ shape: Shape;

callDecoder: Decoder<DecodedCall>;
buildEvent: VariantBasedBuild;
buildError: VariantBasedBuild;
buildCall: VariantBasedBuild;
buildConstant: (pallet: string, name: string) => UnshapedDecoder;
};

@@ -325,2 +360,10 @@ interface DecodedCall {

}>;
type OptionDecoded = WithInputAndPath<{
codec: "Option";
value: Decoded;
}>;
type ResultDecoded = WithInputAndPath<{
codec: "Result";
value: ResultPayload<Decoded, Decoded>;
}>;
type TupleDecoded = WithInputAndPath<{

@@ -339,3 +382,3 @@ codec: "Tuple";

value: {
tag: string;
type: string;
value: Decoded;

@@ -345,3 +388,3 @@ };

}>;
type ComplexDecoded = SequenceDecoded | ArrayDecoded | TupleDecoded | StructDecoded | EnumDecoded;
type ComplexDecoded = SequenceDecoded | ArrayDecoded | TupleDecoded | StructDecoded | OptionDecoded | ResultDecoded | EnumDecoded;
type Decoded = PrimitiveDecoded | ComplexDecoded;

@@ -365,2 +408,13 @@ interface SequenceShape {

}
interface OptionShape {
codec: "Option";
shape: Shape;
}
interface ResultShape {
codec: "Result";
shape: {
ok: Shape;
ko: Shape;
};
}
interface EnumShape {

@@ -370,3 +424,3 @@ codec: "Enum";

}
type ComplexShape = SequenceShape | ArrayShape | TupleShape | StructShape | EnumShape;
type ComplexShape = SequenceShape | ArrayShape | TupleShape | StructShape | OptionShape | ResultShape | EnumShape;
type Shape = {

@@ -378,2 +432,2 @@ codec: PrimitiveDecoded["codec"];

export { type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CodeDeclarations, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives$1 as MetadataPrimitives, type NumberDecoded, type PrimitiveDecoded, type PrimitiveVar, 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 Var, type Variable, type VoidDecoded, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn, getStaticBuilder, getViewBuilder, primitiveTypes };
export { type AccountId32, type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CodeDeclarations, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives$1 as 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 Variable, type VoidDecoded, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn, getStaticBuilder, getViewBuilder, primitiveTypes };

@@ -75,9 +75,15 @@ "use strict";

};
let isAccountId32SearchOn = true;
const getLookupEntryDef = withCache2((id) => {
const { def } = lookupData[id];
const { def, path, params } = lookupData[id];
if (def.tag === "composite") {
if (def.value.length === 0)
return voidVar;
if (def.value.length === 1)
if (def.value.length === 1) {
if (isAccountId32SearchOn && path.join(",") === "sp_core,crypto,AccountId32") {
isAccountId32SearchOn = false;
return { type: "AccountId32" };
}
return getLookupEntryDef(def.value[0].type);
}
let allKey = true;

@@ -103,2 +109,22 @@ const values = {};

if (def.tag === "variant") {
if (path.length === 1 && path[0] === "Option" && params.length === 1 && params[0].name === "T") {
const value = getLookupEntryDef(params[0].type);
return value.type === "primitive" && value.value === "_void" ? (
// Option(_void) would return a Codec<undefined> which makes no sense
// Therefore, we better treat it as a bool
{ type: "primitive", value: "bool" }
) : {
type: "option",
value
};
}
if (path.length === 1 && path[0] === "Result" && params.length === 2 && params[0].name === "T" && params[1].name === "E") {
return {
type: "result",
value: {
ok: getLookupEntryDef(params[0].type),
ko: getLookupEntryDef(params[1].type)
}
};
}
if (def.value.length === 0)

@@ -143,13 +169,13 @@ return voidVar;

if (def.tag === "sequence") {
const value2 = getLookupEntryDef(def.value);
const value = getLookupEntryDef(def.value);
return {
type: "sequence",
value: value2
value
};
}
if (def.tag === "array") {
const value2 = getLookupEntryDef(def.value.type);
const value = getLookupEntryDef(def.value.type);
return {
type: "array",
value: value2,
value,
len: def.value.len

@@ -163,7 +189,7 @@ };

return getLookupEntryDef(def.value[0]);
const value2 = def.value.map((x) => getLookupEntryDef(x));
const value = def.value.map((x) => getLookupEntryDef(x));
const innerDocs = def.value.map((x) => lookupData[x].docs);
return {
type: "tuple",
value: value2,
value,
innerDocs

@@ -186,9 +212,4 @@ };

}
if (def.tag === "bitSequence") {
return { type: "bitSequence" };
}
const value = def.value;
return {
type: "primitive",
value
type: def.tag
};

@@ -238,8 +259,6 @@ });

compactBn: "bigint",
bitSequence: "{bitsLen: number, bytes: Uint8Array}",
historicMetaCompat: "any"
bitSequence: "{bitsLen: number, bytes: Uint8Array}"
};
var toCamelCase = (...parts) => parts[0] + parts.slice(1).map((part) => part[0].toUpperCase() + part.slice(1)).join("");
var isBytes = (input) => input.type === "primitive" && input.value === "u8";
var getTypes = (varName) => primitiveTypes[varName] ?? `I${varName}`;
var toCamelCase = (...parts) => parts.map((part) => part[0].toUpperCase() + part.slice(1)).join("");
var getTypes = (varName) => primitiveTypes[varName] ?? varName;
var _buildSyntax = (input, cache, stack, declarations, getVarName) => {

@@ -250,2 +269,14 @@ if (input.type === "primitive") {

}
if (input.type === "AccountId32") {
declarations.imports.add("AccountId");
const id = "_accountId";
declarations.variables.set(id, {
id,
value: `AccountId()`,
types: "SS58String",
directDependencies: /* @__PURE__ */ new Set()
});
declarations.typeImports.add("SS58String");
return id;
}
if (input.type === "compact") {

@@ -319,15 +350,3 @@ const importVal = input.isBig ? "compactBn" : "compactNumber";

if (input.type === "array") {
if (isBytes(input.value)) {
if (input.len === 32 && (input.id === 0 || input.id === 1)) {
declarations.imports.add("AccountId");
const id = "_accountId";
declarations.variables.set(id, {
id,
value: `AccountId()`,
types: "SS58String",
directDependencies: /* @__PURE__ */ new Set()
});
declarations.typeImports.add("SS58String");
return id;
}
if (input.value.type === "primitive" && input.value.value === "u8") {
declarations.imports.add("Bin");

@@ -352,3 +371,32 @@ declarations.variables.set(varId, {

return buildStruct(varId, input.value);
declarations.imports.add("Enum");
if (input.type === "option") {
declarations.imports.add("Option");
const inner = buildNextSyntax(input.value);
const id = `_Option_${inner}`;
const variable = {
id,
value: `Option(${inner})`,
types: `${getTypes(inner)} | undefined`,
directDependencies: /* @__PURE__ */ new Set([inner])
};
declarations.variables.set(id, variable);
return id;
}
if (input.type === "result") {
declarations.imports.add("Result");
declarations.typeImports.add("ResultPayload");
const ok = buildNextSyntax(input.value.ok);
const ko = buildNextSyntax(input.value.ko);
const id = `_Result_${ok}_${ko}`;
const variable = {
id,
value: `Result(${ok}, ${ko})`,
types: `ResultPayload<${getTypes(ok)}, ${getTypes(ko)}>`,
directDependencies: /* @__PURE__ */ new Set([ok, ko])
};
declarations.variables.set(id, variable);
return id;
}
declarations.imports.add("Variant");
declarations.typeImports.add("Enum");
const dependencies = Object.entries(input.value).map(([key, value]) => {

@@ -384,8 +432,12 @@ if (value.type === "primitive") {

)}}${areIndexesSorted ? "" : `, [${indexes.join(", ")}]`}`;
declarations.enums.set(
varId,
Object.keys(input.value).map(
(key, idx) => `{type: '${key}', value: ${getTypes(dependencies[idx])}}`
).join(" | ")
);
declarations.variables.set(varId, {
id: varId,
value: `Enum(${innerEnum})`,
types: Object.keys(input.value).map(
(key, idx) => `{tag: '${key}', value: ${getTypes(dependencies[idx])}}`
).join(" | "),
value: `Variant(${innerEnum})`,
types: `Enum<E${varId}>`,
directDependencies: new Set(dependencies)

@@ -402,3 +454,3 @@ });

id: getVarName(entry.id, "circular"),
types: `I${nonCircular}`,
types: nonCircular,
value: `Self(() => ${nonCircular})`,

@@ -416,3 +468,4 @@ directDependencies: /* @__PURE__ */ new Set([nonCircular])

typeImports: /* @__PURE__ */ new Set(["Codec"]),
variables: /* @__PURE__ */ new Map()
variables: /* @__PURE__ */ new Map(),
enums: /* @__PURE__ */ new Map()
};

@@ -423,3 +476,14 @@ const lookupData = metadata.lookup;

const { path } = lookupData[idx];
const parts = path.length === 0 ? ["cdc" + idx] : ["c", ...path];
let parts;
if (path.length === 0)
parts = ["cdc" + idx];
else if (path[0] === "sp_runtime")
parts = [path.slice(-1)[0]];
else if (
// Junctions Junctions, etc
path.length > 2 && path.slice(-2)[0].toUpperCase() === path.slice(-2)[1].toUpperCase()
)
parts = path.slice(0, -1);
else
parts = [...path];
parts.push(...post);

@@ -481,10 +545,19 @@ return toCamelCase(...parts);

};
const buildRuntimeCall = (api, method) => {
const entry = metadata.apis.find((x) => x.name === api)?.methods.find((x) => x.name === method);
if (!entry)
throw null;
return {
args: buildNamedTuple(entry.inputs, `${api}${method}Args`),
value: buildDefinition(entry.output)
};
};
const buildVariant = (type) => (pallet, name) => {
const eventsLookup = getLookupEntryDef(
const lookupEntry = getLookupEntryDef(
metadata.pallets.find((x) => x.name === pallet)[type]
);
if (eventsLookup.type !== "enum")
if (lookupEntry.type !== "enum")
throw null;
const returnVar = toCamelCase(buildDefinition(eventsLookup.id), name);
if (!declarations.variables.has(returnVar) && eventsLookup.value[name].type === "primitive") {
const returnVar = toCamelCase(buildDefinition(lookupEntry.id), name);
if (!declarations.variables.has(returnVar) && lookupEntry.value[name].type === "primitive") {
declarations.variables.set(returnVar, {

@@ -499,22 +572,2 @@ id: returnVar,

};
const buildCall = (pallet, callName) => {
const callsLookup = getLookupEntryDef(
metadata.pallets.find((x) => x.name === pallet).calls
);
if (callsLookup.type !== "enum")
throw null;
const callEntry = callsLookup.value[callName];
if (callEntry.type === "primitive")
return getEmptyTuple();
if (callEntry.type === "tuple")
return toCamelCase(buildDefinition(callsLookup.id), callName);
const params = Object.entries(callEntry.value).map(([name, val]) => ({
name,
type: val.id
}));
return buildNamedTuple(
params,
getVarName(callsLookup.id, callName, "Tupled")
);
};
const buildConstant = (pallet, constantName) => {

@@ -527,3 +580,3 @@ const storageEntry = metadata.pallets.find((x) => x.name === pallet).constants.find((s) => s.name === constantName);

", "
)}} from "@polkadot-api/substrate-bindings";
)}} from "@polkadot-api/client";
`;

@@ -536,8 +589,13 @@ const varImports = `import {${[...declarations.imports].join(

const code = [...declarations.variables.values()].map((variable) => {
return `type I${variable.id} = ${variable.types};
const ${variable.id}: Codec<I${variable.id}> = ${variable.value};`;
const ePrefix = declarations.enums.has(variable.id) ? `type E${variable.id} = ${declarations.enums.get(
variable.id
)};
export ` : "";
return `${ePrefix}type ${variable.id} = ${variable.types};
const ${variable.id}: Codec<${variable.id}> = ${variable.value};`;
}).join("\n\n");
return `${typeImports}${varImports}${code}`;
};
const getTypeFromVarName = (varName) => primitiveTypes[varName] ?? declarations.variables.get(varName)?.types ?? `I${varName}`;
const getEnums = () => [...declarations.enums.keys()];
const getTypeFromVarName = (varName) => primitiveTypes[varName] ?? declarations.variables.get(varName)?.types ?? varName;
return {

@@ -548,6 +606,8 @@ buildDefinition,

buildError: buildVariant("errors"),
buildCall,
buildCall: buildVariant("calls"),
buildRuntimeCall,
buildConstant,
getTypeFromVarName,
getCode
getCode,
getEnums
};

@@ -558,7 +618,9 @@ };

var scale = __toESM(require("@polkadot-api/substrate-bindings"));
var import_utils = require("@polkadot-api/utils");
var _bytes = scale.Bin();
var isBytes2 = (input) => input.type === "primitive" && input.value === "u8";
var _buildCodec = (input, cache, stack, _accountId) => {
if (input.type === "primitive")
return scale[input.value];
if (input.type === "AccountId32")
return _accountId;
if (input.type === "compact")

@@ -584,5 +646,4 @@ return scale.compact;

if (input.type === "array") {
if (isBytes2(input.value)) {
return input.len === 32 && (input.id === 0 || input.id === 1) ? _accountId : scale.Bin(input.len);
}
if (input.value.type === "primitive" && input.value.value === "u8")
return scale.Bin(input.len);
return buildVector(input.value, input.len);

@@ -596,2 +657,9 @@ }

return buildStruct(input.value);
if (input.type === "option")
return scale.Option(buildNextCodec(input.value));
if (input.type === "result")
return scale.Result(
buildNextCodec(input.value.ok),
buildNextCodec(input.value.ko)
);
const dependencies = Object.values(input.value).map((v) => {

@@ -611,6 +679,5 @@ if (v.type === "primitive")

const areIndexesSorted = indexes.every((idx, i) => idx === i);
return areIndexesSorted ? scale.Enum(inner) : scale.Enum(inner, indexes);
return areIndexesSorted ? scale.Variant(inner) : scale.Variant(inner, indexes);
};
var buildCodec = withCache(_buildCodec, scale.Self, (res) => res);
var emptyTuple = scale.Tuple();
var getDynamicBuilder = (metadata) => {

@@ -665,16 +732,10 @@ const lookupData = metadata.lookup;

};
const buildCall = (pallet, callName) => {
const palletEntry = metadata.pallets.find((x) => x.name === pallet);
const callsLookup = getLookupEntryDef(palletEntry.calls);
if (callsLookup.type !== "enum")
throw null;
const callEntry = callsLookup.value[callName];
return {
location: [palletEntry.index, callEntry.idx],
args: callEntry.type === "primitive" ? emptyTuple : scale.Tuple(
...Object.values(callEntry.value).map(
(l) => buildDefinition(l.id)
)
)
};
const buildEnumEntry = (entry) => {
if (entry.type === "primitive")
return scale._void;
return entry.type === "tuple" ? scale.Tuple(
...Object.values(entry.value).map((l) => buildDefinition(l.id))
) : scale.Struct(
(0, import_utils.mapObject)(entry.value, (x) => buildDefinition(x.id))
);
};

@@ -690,8 +751,28 @@ const buildConstant = (pallet, constantName) => {

throw null;
const event = lookup.value[name];
const entry = lookup.value[name];
return {
location: [palletEntry.index, event.idx],
codec: event.type === "primitive" ? scale._void : buildDefinition(lookup.id)
location: [palletEntry.index, entry.idx],
codec: buildEnumEntry(lookup.value[name])
};
};
const buildCall = (pallet, name) => {
const palletEntry = metadata.pallets.find((x) => x.name === pallet);
const lookup = getLookupEntryDef(palletEntry.calls);
if (lookup.type !== "enum")
throw null;
const entry = lookup.value[name];
return {
location: [palletEntry.index, entry.idx],
args: buildEnumEntry(lookup.value[name])
};
};
const buildRuntimeCall = (api, method) => {
const entry = metadata.apis.find((x) => x.name === api)?.methods.find((x) => x.name === method);
if (!entry)
throw null;
return {
args: scale.Tuple(...entry.inputs.map((x) => buildDefinition(x.type))),
value: buildDefinition(entry.output)
};
};
return {

@@ -702,2 +783,3 @@ buildDefinition,

buildError: buildVariant("errors"),
buildRuntimeCall,
buildCall,

@@ -713,66 +795,134 @@ buildConstant,

var encodeText = textEncoder.encode.bind(textEncoder);
var getChecksum = (values, shape) => {
const hasShape = typeof shape === "string";
const res = new Uint8Array((values.length + (hasShape ? 1 : 0)) * 8);
var getChecksum = (values) => {
const res = new Uint8Array(values.length * 8);
const dv = new DataView(res.buffer);
let offset = 0;
if (hasShape) {
dv.setBigUint64(offset, (0, import_substrate_bindings.h64)(encodeText(shape)));
offset += 8;
}
for (let i = 0; i < values.length; i++, offset += 8)
dv.setBigUint64(offset, values[i]);
for (let i = 0; i < values.length; i++)
dv.setBigUint64(i * 8, values[i]);
return (0, import_substrate_bindings.h64)(res);
};
var primitiveChecksums = {
_void: 0n,
bool: 1n,
char: 2n,
str: 3n,
u8: 4n,
u16: 5n,
u32: 6n,
u64: 7n,
u128: 8n,
u256: 9n,
i8: 5n,
i16: 5n,
i32: 6n,
i64: 7n,
i128: 8n,
i256: 9n,
compacts: 10n,
compactb: 11n,
bitSequence: 12n,
historicMetaCompat: 13n
var getStringChecksum = (values) => getChecksum(values.map((v) => (0, import_substrate_bindings.h64)(encodeText(v))));
var shapeIds = {
primitive: 0n,
vector: 1n,
tuple: 2n,
struct: 3n,
option: 4n,
result: 5n,
enum: 6n
};
var bytesChecksum = 14n;
var _buildChecksum = (input, cache, stack) => {
if (cache.has(input.id))
return cache.get(input.id);
var runtimePrimitiveIds = {
undefined: 0n,
number: 1n,
string: 2n,
bigint: 3n,
boolean: 4n,
bitSequence: 5n,
// {bitsLen: number, bytes: Uint8Array}
byteSequence: 6n,
// Binary
accountId: 7n
// SS58String
};
var metadataPrimitiveIds = {
_void: runtimePrimitiveIds.undefined,
bool: runtimePrimitiveIds.boolean,
char: runtimePrimitiveIds.string,
str: runtimePrimitiveIds.string,
u8: runtimePrimitiveIds.number,
u16: runtimePrimitiveIds.number,
u32: runtimePrimitiveIds.number,
u64: runtimePrimitiveIds.bigint,
u128: runtimePrimitiveIds.bigint,
u256: runtimePrimitiveIds.bigint,
i8: runtimePrimitiveIds.number,
i16: runtimePrimitiveIds.number,
i32: runtimePrimitiveIds.number,
i64: runtimePrimitiveIds.bigint,
i128: runtimePrimitiveIds.bigint,
i256: runtimePrimitiveIds.bigint
};
var structLikeBuilder = (shapeId, input, innerChecksum) => {
const sortedEntries = Object.entries(input).sort(
([a], [b]) => a.localeCompare(b)
);
const keysChecksum = getStringChecksum(sortedEntries.map(([key]) => key));
const valuesChecksum = getChecksum(
sortedEntries.map(([, entry]) => innerChecksum(entry))
);
return getChecksum([shapeId, keysChecksum, valuesChecksum]);
};
var buildGraph = (entry, result = /* @__PURE__ */ new Map()) => {
if (result.has(entry.id))
return result;
switch (entry.type) {
case "array":
case "option":
case "sequence":
result.set(entry.id, [entry, /* @__PURE__ */ new Set([entry.value.id])]);
buildGraph(entry.value, result);
break;
case "enum": {
const children = Object.values(entry.value).flatMap((value) => {
if (value.type === "primitive")
return [];
if (value.type === "struct")
return Object.values(value.value);
return value.value;
});
result.set(entry.id, [entry, new Set(children.map((child) => child.id))]);
children.forEach((child) => buildGraph(child, result));
break;
}
case "result":
result.set(entry.id, [
entry,
/* @__PURE__ */ new Set([entry.value.ok.id, entry.value.ko.id])
]);
buildGraph(entry.value.ok, result);
buildGraph(entry.value.ko, result);
break;
case "struct": {
const children = Object.values(entry.value);
result.set(entry.id, [entry, new Set(children.map((child) => child.id))]);
children.forEach((child) => buildGraph(child, result));
break;
}
case "tuple":
result.set(entry.id, [
entry,
new Set(entry.value.map((child) => child.id))
]);
entry.value.forEach((child) => buildGraph(child, result));
break;
default:
result.set(entry.id, [entry, /* @__PURE__ */ new Set()]);
}
return result;
};
var _buildChecksum = (input, buildNextChecksum) => {
if (input.type === "primitive")
return primitiveChecksums[input.value];
return getChecksum([shapeIds.primitive, metadataPrimitiveIds[input.value]]);
if (input.type === "compact")
return primitiveChecksums[input.isBig ? "compactb" : "compacts"];
return getChecksum([
shapeIds.primitive,
runtimePrimitiveIds[input.isBig ? "bigint" : "number"]
]);
if (input.type === "bitSequence")
return primitiveChecksums.bitSequence;
return getChecksum([shapeIds.primitive, runtimePrimitiveIds.bitSequence]);
if (input.type === "sequence" && input.value.type === "primitive" && input.value.value === "u8") {
return bytesChecksum;
return getChecksum([shapeIds.primitive, runtimePrimitiveIds.byteSequence]);
}
const buildNextChecksum = (nextInput) => buildChecksum(nextInput, cache, stack);
const buildVector = (inner, len) => {
const innerChecksum = buildNextChecksum(inner);
return len ? getChecksum([innerChecksum, BigInt(len)], "Vector(,)") : getChecksum([innerChecksum], "Vector()");
};
const buildTuple = (value) => getChecksum(value.map(buildNextChecksum));
const buildStruct = (value) => {
return getChecksum(
Object.values(value).map(buildNextChecksum),
JSON.stringify(Object.keys(value))
);
};
if (input.type === "array")
return buildVector(input.value, input.len);
if (input.type === "sequence")
return buildVector(input.value);
if (input.type === "AccountId32") {
return getChecksum([shapeIds.primitive, runtimePrimitiveIds.accountId]);
}
if (input.type === "array") {
const innerChecksum = buildNextChecksum(input.value);
return getChecksum([shapeIds.vector, innerChecksum, BigInt(input.len)]);
}
if (input.type === "sequence") {
const innerChecksum = buildNextChecksum(input.value);
return getChecksum([shapeIds.vector, innerChecksum]);
}
const buildTuple = (entries) => getChecksum([shapeIds.tuple, ...entries.map(buildNextChecksum)]);
const buildStruct = (entries) => structLikeBuilder(shapeIds.struct, entries, buildNextChecksum);
if (input.type === "tuple")

@@ -782,16 +932,154 @@ return buildTuple(input.value);

return buildStruct(input.value);
const dependencies = Object.values(input.value).map((v) => {
if (v.type === "primitive")
return 0n;
return v.type === "tuple" ? buildTuple(v.value) : buildStruct(v.value);
if (input.type === "option")
return getChecksum([shapeIds.option, buildNextChecksum(input.value)]);
if (input.type === "result")
return getChecksum([
shapeIds.result,
buildNextChecksum(input.value.ok),
buildNextChecksum(input.value.ko)
]);
return structLikeBuilder(shapeIds.enum, input.value, (entry) => {
switch (entry.type) {
case "primitive":
return metadataPrimitiveIds._void;
case "tuple":
return buildTuple(entry.value);
case "struct":
return buildStruct(entry.value);
}
});
const keys = Object.keys(input.value);
keys.push("Enum");
return getChecksum(dependencies, JSON.stringify({ Enum: keys }));
};
var buildChecksum = withCache(
_buildChecksum,
() => 0n,
(result) => result
);
var getCycles = (graph) => {
const tarjanState = /* @__PURE__ */ new Map();
let index = 0;
const stack = [];
const result = [];
function strongConnect(v) {
const state = {
index,
lowLink: index,
onStack: true
};
tarjanState.set(v, state);
index++;
stack.push(v);
const edges = graph.get(v)[1];
for (let w of edges) {
const edgeState = tarjanState.get(w);
if (!edgeState) {
strongConnect(w);
state.lowLink = Math.min(state.lowLink, tarjanState.get(w).lowLink);
} else if (edgeState.onStack) {
state.lowLink = Math.min(state.lowLink, edgeState.index);
}
}
if (state.lowLink === state.index) {
const component = /* @__PURE__ */ new Set();
let poppedNode = -1;
do {
poppedNode = stack.pop();
tarjanState.get(poppedNode).onStack = false;
component.add(poppedNode);
} while (poppedNode !== v);
if (component.size > 1)
result.push(component);
}
}
for (const node of graph.keys()) {
if (!tarjanState.has(node)) {
strongConnect(node);
}
}
return result;
};
var getCyclicGroups = (cycles) => {
const ungroupedCycles = new Set(cycles.map((_, i) => i));
const edges = new Map(cycles.map((_, i) => [i, /* @__PURE__ */ new Set()]));
cycles.forEach((cycle, i) => {
cycles.slice(i + 1).forEach((otherCycle, _j) => {
const j = _j + i + 1;
const combined = /* @__PURE__ */ new Set([...cycle, ...otherCycle]);
if (combined.size !== cycle.size + otherCycle.size) {
edges.get(i).add(j);
edges.get(j).add(i);
}
});
});
const groups = [];
while (ungroupedCycles.size) {
const group = /* @__PURE__ */ new Set();
const toVisit = [ungroupedCycles.values().next().value];
while (toVisit.length) {
const idx = toVisit.pop();
if (!ungroupedCycles.has(idx))
continue;
ungroupedCycles.delete(idx);
const cycle = cycles[idx];
cycle.forEach((v) => group.add(Number(v)));
edges.get(idx).forEach((n) => toVisit.push(n));
}
groups.push(group);
}
return groups;
};
var sortCyclicGroups = (groups, graph) => {
const getReachableNodes = (group) => {
const first = group.values().next().value;
const entry = graph.get(first)[0];
return Array.from(buildGraph(entry).keys());
};
const result = new Array();
function dependentsFirst(group) {
if (result.includes(group))
return;
const dependents = groups.filter(
(candidate) => candidate !== group && getReachableNodes(group).some((node) => candidate.has(node))
);
dependents.forEach((group2) => dependentsFirst(group2));
if (result.includes(group))
return;
result.push(group);
}
groups.forEach((group) => dependentsFirst(group));
return result;
};
var buildChecksum = (entry, cache) => {
if (cache.has(entry.id))
return cache.get(entry.id);
const graph = buildGraph(entry);
const cycles = getCycles(graph);
const cyclicGroups = getCyclicGroups(cycles);
const sortedCyclicGroups = sortCyclicGroups(cyclicGroups, graph);
const recursiveBuildChecksum = (entry2, writeCache, skipCache = false) => {
if (!skipCache && cache.has(entry2.id)) {
return cache.get(entry2.id);
}
const result = _buildChecksum(
entry2,
(nextEntry) => recursiveBuildChecksum(nextEntry, writeCache)
);
writeCache(entry2.id, result);
return result;
};
sortedCyclicGroups.forEach((group) => {
group.forEach((id) => cache.set(id, 0n));
for (let i = 0; i < group.size; i++) {
const results = /* @__PURE__ */ new Map();
group.forEach(
(id) => recursiveBuildChecksum(
graph.get(id)[0],
(id2, value) => {
const writeCache = group.has(id2) ? results : cache;
writeCache.set(id2, value);
},
true
)
);
Array.from(results.entries()).forEach(
([id, checksum]) => cache.set(id, checksum)
);
}
});
return recursiveBuildChecksum(entry, (id, value) => cache.set(id, value));
};
var getChecksumBuilder = (metadata) => {

@@ -801,3 +1089,3 @@ const lookupData = metadata.lookup;

const cache = /* @__PURE__ */ new Map();
const buildDefinition = (id) => buildChecksum(getLookupEntryDef(id), cache, /* @__PURE__ */ new Set());
const buildDefinition = (id) => buildChecksum(getLookupEntryDef(id), cache);
const buildStorage = (pallet, entry) => {

@@ -807,6 +1095,6 @@ try {

if (storageEntry.type.tag === "plain")
return getChecksum([buildDefinition(storageEntry.type.value)]);
return buildDefinition(storageEntry.type.value);
const { key, value } = storageEntry.type.value;
const val = buildDefinition(value);
const returnKey = storageEntry.type.value.hashers.length === 1 ? getChecksum([buildDefinition(key)]) : buildDefinition(key);
const returnKey = buildDefinition(key);
return getChecksum([val, returnKey]);

@@ -817,15 +1105,15 @@ } catch (_) {

};
const buildEnumEntry = (entry) => {
if (entry.type === "primitive")
return 0n;
const values = Object.values(entry.value).map((l) => buildDefinition(l.id));
return entry.type === "tuple" ? getChecksum(values) : getChecksum(values, JSON.stringify(Object.keys(entry.value)));
};
const buildCall = (pallet, callName) => {
const buildRuntimeCall = (api, method) => {
try {
const palletEntry = metadata.pallets.find((x) => x.name === pallet);
const callsLookup = getLookupEntryDef(palletEntry.calls);
if (callsLookup.type !== "enum")
const entry = metadata.apis.find((x) => x.name === api)?.methods.find((x) => x.name === method);
if (!entry)
throw null;
return buildEnumEntry(callsLookup.value[callName]);
const argNamesChecksum = getStringChecksum(
entry.inputs.map((x) => x.name)
);
const argValuesChecksum = getChecksum(
entry.inputs.map((x) => buildDefinition(x.type))
);
const outputChecksum = buildDefinition(entry.output);
return getChecksum([argNamesChecksum, argValuesChecksum, outputChecksum]);
} catch (_) {

@@ -835,2 +1123,17 @@ return null;

};
const buildComposite = (input) => {
if (input.type === "primitive")
return getChecksum([0n]);
if (input.type === "tuple") {
const values = Object.values(input.value).map(
(entry) => buildDefinition(entry.id)
);
return getChecksum([shapeIds.tuple, ...values]);
}
return structLikeBuilder(
shapeIds.struct,
input.value,
(entry) => buildDefinition(entry.id)
);
};
const buildVariant = (variantType) => (pallet, name) => {

@@ -844,3 +1147,3 @@ try {

throw null;
return buildEnumEntry(callsLookup.value[name]);
return buildComposite(callsLookup.value[name]);
} catch (_) {

@@ -861,7 +1164,9 @@ return null;

buildDefinition: toStringEnhancer(buildDefinition),
buildRuntimeCall: toStringEnhancer(buildRuntimeCall),
buildStorage: toStringEnhancer(buildStorage),
buildCall: toStringEnhancer(buildCall),
buildCall: toStringEnhancer(buildVariant("calls")),
buildEvent: toStringEnhancer(buildVariant("events")),
buildError: toStringEnhancer(buildVariant("errors")),
buildConstant: toStringEnhancer(buildConstant)
buildConstant: toStringEnhancer(buildConstant),
buildComposite: toStringEnhancer(buildComposite)
};

@@ -871,9 +1176,9 @@ };

// src/view-builder/view-builder.ts
var import_utils2 = require("@polkadot-api/utils");
var import_utils3 = require("@polkadot-api/utils");
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
// src/view-builder/shaped-decoders.ts
var import_utils = require("@polkadot-api/utils");
var import_utils2 = require("@polkadot-api/utils");
var scale2 = __toESM(require("@polkadot-api/substrate-bindings"));
var toHex = import_utils.toHex;
var toHex = import_utils2.toHex;
var createInputValueDecoder = (dec, rest) => scale2.createDecoder((_bytes2) => {

@@ -952,9 +1257,17 @@ const bytes = _bytes2;

var StructDec = (input) => complexShapedDecoder(
{ codec: "Struct", shape: (0, import_utils.mapStringRecord)(input, (x) => x.shape) },
{ 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_utils.mapStringRecord)(input, (x) => x.shape) },
scale2.Enum.dec(input, args)
{ 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) => {

@@ -976,6 +1289,16 @@ let cache = (x) => {

Struct: StructDec,
Enum: EnumDec
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) => {

@@ -997,2 +1320,4 @@ const decoder = (0, import_substrate_bindings2.enhanceDecoder)(input, (x) => ({

return primitives[input.value];
if (input.type === "AccountId32")
return _accountId;
if (input.type === "compact")

@@ -1012,3 +1337,3 @@ return input.isBig ? primitives.compactBn : primitives.compactNumber;

const buildStruct = (value, innerDocs) => withProp(
complex.Struct((0, import_utils2.mapStringRecord)(value, buildNext)),
complex.Struct((0, import_utils3.mapStringRecord)(value, buildNext)),
"innerDocs",

@@ -1019,3 +1344,3 @@ innerDocs

if (input.value.type === "primitive" && input.value.value === "u8") {
return input.len === 32 && (input.id === 0 || input.id === 1) ? _accountId : primitives.BytesArray(input.len);
return primitives.BytesArray(input.len);
}

@@ -1030,2 +1355,6 @@ return buildVector(input.value, input.len);

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) => {

@@ -1046,3 +1375,3 @@ if (v.type === "primitive")

const withDocs = (0, import_substrate_bindings2.enhanceDecoder)(withoutDocs, (val) => {
const docs = input.innerDocs[val.value.tag];
const docs = input.innerDocs[val.value.type];
return {

@@ -1083,9 +1412,3 @@ ...val,

}
const buildDefinition = (id) => {
const shapedDecoder = getDecoder(id);
return {
shape: shapedDecoder.shape,
decoder: shapedDecoder
};
};
const buildDefinition = toUnshapedDecoder(getDecoder);
const callDecoder = (0, import_substrate_bindings2.createDecoder)((bytes) => {

@@ -1109,3 +1432,3 @@ const palletIdx = import_substrate_bindings2.u8.dec(bytes);

value: {
name: decoded.value.tag,
name: decoded.value.type,
idx: bytes[1]

@@ -1122,4 +1445,40 @@ },

});
return { buildDefinition, callDecoder };
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, V14, Codec, Decoder, HexString } from '@polkadot-api/substrate-bindings';
export { Decoder, HexString, StringRecord, V14 } 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';

@@ -21,3 +21,6 @@ type VoidVar = {

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

@@ -40,2 +43,13 @@ type: "tuple";

};
type OptionVar = {
type: "option";
value: LookupEntry;
};
type ResultVar = {
type: "result";
value: {
ok: LookupEntry;
ko: LookupEntry;
};
};
type SequenceVar = {

@@ -50,3 +64,3 @@ type: "sequence";

};
type ComposedVar = TupleVar | StructVar | SequenceVar | ArrayVar | EnumVar;
type ComposedVar = TupleVar | StructVar | SequenceVar | ArrayVar | OptionVar | ResultVar | EnumVar;
type Var = TerminalVar | ComposedVar;

@@ -61,3 +75,3 @@ type LookupEntry = {

name: string;
type: number | void | undefined;
type: number | undefined;
}[];

@@ -67,5 +81,5 @@ def: {

value: {
name: string | void | undefined;
name: string | undefined;
type: number;
typeName: string | void | undefined;
typeName: string | undefined;
docs: string[];

@@ -78,5 +92,5 @@ }[];

fields: {
name: string | void | undefined;
name: string | undefined;
type: number;
typeName: string | void | undefined;
typeName: string | undefined;
docs: string[];

@@ -156,5 +170,2 @@ }[];

};
} | {
tag: "historicMetaCompat";
value: string;
};

@@ -165,3 +176,3 @@ docs: string[];

type MetadataPrimitives = "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256";
declare const primitiveTypes: Record<MetadataPrimitives | "_void" | "compactNumber" | "compactBn" | "bitSequence" | "historicMetaCompat", string>;
declare const primitiveTypes: Record<MetadataPrimitives | "_void" | "compactNumber" | "compactBn" | "bitSequence", string>;
interface Variable {

@@ -176,5 +187,6 @@ id: string;

typeImports: Set<string>;
enums: Map<string, string>;
variables: Map<string, Variable>;
}
declare const getStaticBuilder: (metadata: V14) => {
declare const getStaticBuilder: (metadata: V15) => {
buildDefinition: (id: number) => string;

@@ -187,9 +199,14 @@ buildStorage: (pallet: string, entry: string) => {

buildError: (pallet: string, name: string) => string;
buildCall: (pallet: string, callName: string) => string;
buildCall: (pallet: string, name: string) => string;
buildRuntimeCall: (api: string, method: string) => {
args: string;
value: string;
};
buildConstant: (pallet: string, constantName: string) => string;
getTypeFromVarName: (varName: string) => string;
getCode: () => string;
getEnums: () => string[];
};
declare const getDynamicBuilder: (metadata: V14) => {
declare const getDynamicBuilder: (metadata: V15) => {
buildDefinition: (id: number) => Codec<any>;

@@ -217,3 +234,8 @@ buildStorage: (pallet: string, entry: string) => {

};
buildCall: (pallet: string, callName: string) => {
buildRuntimeCall: (api: string, method: string) => {
args: Codec<any[]>;
value: Codec<any>;
};
buildCall: (pallet: string, name: string) => {
args: Codec<any>;
location: [

@@ -223,3 +245,2 @@ number,

];
args: Codec<any>;
};

@@ -230,12 +251,22 @@ buildConstant: (pallet: string, constantName: string) => Codec<any>;

declare const getChecksumBuilder: (metadata: V14) => {
declare const getChecksumBuilder: (metadata: V15) => {
buildDefinition: (id: number) => string | null;
buildRuntimeCall: (api: string, method: string) => string | null;
buildStorage: (pallet: string, entry: string) => string | null;
buildCall: (pallet: string, callName: 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;
buildComposite: (input: VoidVar | TupleVar | StructVar) => string | null;
};
type GetViewBuilder = (metadata: V14) => {
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) => {

@@ -246,2 +277,6 @@ shape: Shape;

callDecoder: Decoder<DecodedCall>;
buildEvent: VariantBasedBuild;
buildError: VariantBasedBuild;
buildCall: VariantBasedBuild;
buildConstant: (pallet: string, name: string) => UnshapedDecoder;
};

@@ -325,2 +360,10 @@ interface DecodedCall {

}>;
type OptionDecoded = WithInputAndPath<{
codec: "Option";
value: Decoded;
}>;
type ResultDecoded = WithInputAndPath<{
codec: "Result";
value: ResultPayload<Decoded, Decoded>;
}>;
type TupleDecoded = WithInputAndPath<{

@@ -339,3 +382,3 @@ codec: "Tuple";

value: {
tag: string;
type: string;
value: Decoded;

@@ -345,3 +388,3 @@ };

}>;
type ComplexDecoded = SequenceDecoded | ArrayDecoded | TupleDecoded | StructDecoded | EnumDecoded;
type ComplexDecoded = SequenceDecoded | ArrayDecoded | TupleDecoded | StructDecoded | OptionDecoded | ResultDecoded | EnumDecoded;
type Decoded = PrimitiveDecoded | ComplexDecoded;

@@ -365,2 +408,13 @@ interface SequenceShape {

}
interface OptionShape {
codec: "Option";
shape: Shape;
}
interface ResultShape {
codec: "Result";
shape: {
ok: Shape;
ko: Shape;
};
}
interface EnumShape {

@@ -370,3 +424,3 @@ codec: "Enum";

}
type ComplexShape = SequenceShape | ArrayShape | TupleShape | StructShape | EnumShape;
type ComplexShape = SequenceShape | ArrayShape | TupleShape | StructShape | OptionShape | ResultShape | EnumShape;
type Shape = {

@@ -378,2 +432,2 @@ codec: PrimitiveDecoded["codec"];

export { type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CodeDeclarations, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives$1 as MetadataPrimitives, type NumberDecoded, type PrimitiveDecoded, type PrimitiveVar, 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 Var, type Variable, type VoidDecoded, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn, getStaticBuilder, getViewBuilder, primitiveTypes };
export { type AccountId32, type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CodeDeclarations, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives$1 as 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 Variable, type VoidDecoded, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn, getStaticBuilder, getViewBuilder, primitiveTypes };

@@ -1,8 +0,9 @@

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

@@ -43,4 +43,4 @@ "repository": {

"dependencies": {
"@polkadot-api/substrate-bindings": "0.0.1-5385372d2b5500605bc9e86b6dbd27cfd9c6469c.1.0",
"@polkadot-api/utils": "0.0.1-5385372d2b5500605bc9e86b6dbd27cfd9c6469c.1.0"
"@polkadot-api/substrate-bindings": "0.0.1-5438e9d2e4bbfe30fd6a48c7db793443e6c9c1ff.1.0",
"@polkadot-api/utils": "0.0.1-5438e9d2e4bbfe30fd6a48c7db793443e6c9c1ff.1.0"
},

@@ -47,0 +47,0 @@ "scripts": {

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