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-3b74a30d89c855b13ddebe0cd6702eff171b7172.1.0 to 0.0.1-3fdf48394f8fd292d39de8ace33d593b54e38cf4.1.0

124

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';

@@ -9,6 +9,6 @@ type VoidVar = {

};
type MetadataPrimitives$1 = "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256";
type MetadataPrimitives = "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256";
type PrimitiveVar = {
type: "primitive";
value: MetadataPrimitives$1;
value: MetadataPrimitives;
} | VoidVar;

@@ -22,3 +22,6 @@ type CompactVar = {

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

@@ -41,2 +44,13 @@ type: "tuple";

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

@@ -51,3 +65,3 @@ type: "sequence";

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

@@ -62,3 +76,3 @@ type LookupEntry = {

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

@@ -68,5 +82,5 @@ def: {

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

@@ -79,5 +93,5 @@ }[];

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

@@ -157,5 +171,2 @@ }[];

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

@@ -165,30 +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>;
interface Variable {
id: string;
types: string;
value: string;
directDependencies: Set<string>;
}
interface CodeDeclarations {
imports: Set<string>;
typeImports: Set<string>;
variables: Map<string, Variable>;
}
declare const getStaticBuilder: (metadata: V14) => {
buildDefinition: (id: number) => string;
buildStorage: (pallet: string, entry: string) => {
key: string;
val: string;
};
buildEvent: (pallet: string, name: string) => string;
buildError: (pallet: string, name: string) => string;
buildCall: (pallet: string, callName: string) => string;
buildConstant: (pallet: string, constantName: string) => string;
getTypeFromVarName: (varName: string) => string;
getCode: () => string;
};
declare const getDynamicBuilder: (metadata: V14) => {
declare const getDynamicBuilder: (metadata: V15) => {
buildDefinition: (id: number) => Codec<any>;

@@ -216,3 +200,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) => {
codec: Codec<any>;
location: [

@@ -222,3 +211,2 @@ number,

];
args: Codec<any>;
};

@@ -229,12 +217,23 @@ 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;
buildNamedTuple: (input: 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) => {

@@ -245,2 +244,6 @@ shape: Shape;

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

@@ -324,2 +327,10 @@ interface DecodedCall {

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

@@ -338,3 +349,3 @@ codec: "Tuple";

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

@@ -344,3 +355,3 @@ };

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

@@ -364,2 +375,13 @@ interface SequenceShape {

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

@@ -369,3 +391,3 @@ codec: "Enum";

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

@@ -377,2 +399,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 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 };

@@ -36,5 +36,3 @@ "use strict";

getLookupFn: () => getLookupFn,
getStaticBuilder: () => getStaticBuilder,
getViewBuilder: () => getViewBuilder,
primitiveTypes: () => primitiveTypes
getViewBuilder: () => getViewBuilder
});

@@ -76,9 +74,15 @@ module.exports = __toCommonJS(src_exports);

};
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;

@@ -104,2 +108,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)

@@ -144,13 +168,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

@@ -164,7 +188,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

@@ -187,9 +211,4 @@ };

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

@@ -200,2 +219,5 @@ });

// src/dynamic-builder.ts
var scale = __toESM(require("@polkadot-api/substrate-bindings"));
// src/with-cache.ts

@@ -220,348 +242,10 @@ var withCache = (fn, onEnterCircular, onExitCircular) => (input, cache, stack, ...rest) => {

// src/static-builder.ts
var primitiveTypes = {
_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"
};
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 _buildSyntax = (input, cache, stack, declarations, getVarName) => {
if (input.type === "primitive") {
declarations.imports.add(input.value);
return input.value;
}
if (input.type === "compact") {
const importVal = input.isBig ? "compactBn" : "compactNumber";
declarations.imports.add(importVal);
return importVal;
}
if (input.type === "bitSequence") {
declarations.imports.add(input.type);
return input.type;
}
if (input.type === "sequence" && input.value.type === "primitive" && input.value.value === "u8") {
declarations.imports.add("Hex");
declarations.typeImports.add("HexString");
const variable = {
id: "_bytesSeq",
value: "Hex()",
types: "HexString",
directDependencies: /* @__PURE__ */ new Set()
};
if (!declarations.variables.has(variable.id)) {
declarations.variables.set(variable.id, variable);
}
return variable.id;
}
if (declarations.variables.has(getVarName(input.id, "circular")))
return getVarName(input.id, "circular");
if (declarations.variables.has(getVarName(input.id)))
return getVarName(input.id);
const buildNextSyntax = (nextInput) => buildSyntax(nextInput, cache, stack, declarations, getVarName);
const buildVector = (id, inner, len) => {
declarations.imports.add("Vector");
const dependsVar = buildNextSyntax(inner);
const args = len ? [dependsVar, len] : [dependsVar];
const variable = {
id,
value: `Vector(${args.join(", ")})`,
types: `Array<${getTypes(dependsVar)}>`,
directDependencies: /* @__PURE__ */ new Set([dependsVar])
};
declarations.variables.set(id, variable);
return id;
};
const buildTuple = (id, value) => {
declarations.imports.add("Tuple");
const deps = value.map(buildNextSyntax);
const variable = {
id,
value: `Tuple(${deps.join(", ")})`,
types: `[${deps.map(getTypes).join(", ")}]`,
directDependencies: new Set(deps)
};
declarations.variables.set(id, variable);
return id;
};
const buildStruct = (id, value) => {
declarations.imports.add("Struct");
const deps = Object.values(value).map(buildNextSyntax);
const variable = {
id,
value: `Struct({${Object.keys(value).map((key, idx) => `${key}: ${deps[idx]}`).join(", ")}})`,
types: `{${Object.keys(value).map((key, idx) => `${key}: ${getTypes(deps[idx])}`).join(", ")}}`,
directDependencies: new Set(deps)
};
declarations.variables.set(id, variable);
return id;
};
const varId = getVarName(input.id);
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;
}
declarations.imports.add("Hex");
declarations.variables.set(varId, {
id: varId,
value: `Hex(${input.len})`,
types: "HexString",
directDependencies: /* @__PURE__ */ new Set()
});
declarations.typeImports.add("HexString");
return varId;
}
return buildVector(varId, input.value, input.len);
}
if (input.type === "sequence")
return buildVector(varId, input.value);
if (input.type === "tuple")
return buildTuple(varId, input.value);
if (input.type === "struct")
return buildStruct(varId, input.value);
declarations.imports.add("Enum");
const dependencies = Object.entries(input.value).map(([key, value]) => {
if (value.type === "primitive") {
declarations.imports.add(value.value);
return value.value;
}
const varName = toCamelCase(varId, key);
if (value.type === "tuple") {
if (value.value.length === 1) {
let result;
const innerVal = value.value[0];
if (key.startsWith("Raw") && innerVal.type === "array" && isBytes(innerVal.value)) {
const id = `_fixedStr${innerVal.len}`;
result = id;
if (!declarations.variables.has(id)) {
declarations.imports.add("fixedStr");
declarations.variables.set(id, {
id,
value: `fixedStr(${innerVal.len})`,
types: "string",
directDependencies: /* @__PURE__ */ new Set()
});
}
} else {
result = buildNextSyntax(value.value[0]);
}
if (!declarations.variables.has(varName)) {
declarations.variables.set(varName, {
id: varName,
value: result,
types: getTypes(result),
directDependencies: /* @__PURE__ */ new Set([result])
});
}
return varName;
}
return buildTuple(varName, value.value);
} else {
buildStruct(varName, value.value);
}
return varName;
});
const indexes = Object.values(input.value).map((x) => x.idx);
const areIndexesSorted = indexes.every((idx, i) => idx === i);
const innerEnum = `{${Object.keys(input.value).map(
(key, idx) => `${key}: ${dependencies[idx]}`
)}}${areIndexesSorted ? "" : `, [${indexes.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(" | "),
directDependencies: new Set(dependencies)
});
return varId;
};
var buildSyntax = withCache(
_buildSyntax,
(_getter, entry, declarations, getVarName) => {
declarations.imports.add("Self");
const nonCircular = getVarName(entry.id);
const variable = {
id: getVarName(entry.id, "circular"),
types: `I${nonCircular}`,
value: `Self(() => ${nonCircular})`,
directDependencies: /* @__PURE__ */ new Set([nonCircular])
};
declarations.variables.set(variable.id, variable);
return variable.id;
},
(x) => x
);
var getStaticBuilder = (metadata) => {
const declarations = {
imports: /* @__PURE__ */ new Set(),
typeImports: /* @__PURE__ */ new Set(["Codec"]),
variables: /* @__PURE__ */ new Map()
};
const lookupData = metadata.lookup;
const getLookupEntryDef = getLookupFn(lookupData);
const getVarName = (idx, ...post) => {
const { path } = lookupData[idx];
const parts = path.length === 0 ? ["cdc" + idx] : ["c", ...path];
parts.push(...post);
return toCamelCase(...parts);
};
const cache = /* @__PURE__ */ new Map();
const buildDefinition = (id) => buildSyntax(
getLookupEntryDef(id),
cache,
/* @__PURE__ */ new Set(),
declarations,
getVarName
);
const buildNamedTuple = (params, varName) => {
if (declarations.variables.has(varName))
return varName;
const args = params.map((p) => p.type).map(buildDefinition);
const names = params.map((p) => p.name);
declarations.imports.add("Tuple");
const variable = {
id: varName,
types: `[${names.map(
(name, pIdx) => `${name[0].toUpperCase() + name.slice(1)}: ${getTypes(args[pIdx])}`
).join(", ")}]`,
value: `Tuple(${args.join(", ")})`,
directDependencies: new Set(args)
};
declarations.variables.set(varName, variable);
return varName;
};
const EMPTY_TUPLE_VAR_NAME = "_emptyTuple";
const getEmptyTuple = () => {
if (!declarations.variables.has(EMPTY_TUPLE_VAR_NAME)) {
declarations.imports.add("Tuple");
declarations.variables.set(EMPTY_TUPLE_VAR_NAME, {
id: EMPTY_TUPLE_VAR_NAME,
types: `[]`,
value: `Tuple()`,
directDependencies: /* @__PURE__ */ new Set()
});
}
return EMPTY_TUPLE_VAR_NAME;
};
const buildStorage = (pallet, entry) => {
const storageEntry = metadata.pallets.find((x) => x.name === pallet).storage.items.find((s) => s.name === entry);
if (storageEntry.type.tag === "plain")
return {
key: getEmptyTuple(),
val: buildDefinition(storageEntry.type.value)
};
const { key, value } = storageEntry.type.value;
const val = buildDefinition(value);
const returnKey = storageEntry.type.value.hashers.length === 1 ? buildNamedTuple(
[{ name: "key", type: key }],
getVarName(key, "Tupled")
) : buildDefinition(key);
return { key: returnKey, val };
};
const buildVariant = (type) => (pallet, name) => {
const eventsLookup = getLookupEntryDef(
metadata.pallets.find((x) => x.name === pallet)[type]
);
if (eventsLookup.type !== "enum")
throw null;
const returnVar = toCamelCase(buildDefinition(eventsLookup.id), name);
if (!declarations.variables.has(returnVar) && eventsLookup.value[name].type === "primitive") {
declarations.variables.set(returnVar, {
id: returnVar,
value: "_void",
types: "undefined",
directDependencies: /* @__PURE__ */ new Set()
});
}
return 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) => {
const storageEntry = metadata.pallets.find((x) => x.name === pallet).constants.find((s) => s.name === constantName);
return buildDefinition(storageEntry.type);
};
const getCode = () => {
const typeImports = `import type {${[...declarations.typeImports].join(
", "
)}} from "@polkadot-api/substrate-bindings";
`;
const varImports = `import {${[...declarations.imports].join(
", "
)}} from "@polkadot-api/substrate-bindings";
`;
const code = [...declarations.variables.values()].map((variable) => {
return `type I${variable.id} = ${variable.types};
const ${variable.id}: Codec<I${variable.id}> = ${variable.value};`;
}).join("\n\n");
return `${typeImports}${varImports}${code}`;
};
const getTypeFromVarName = (varName) => primitiveTypes[varName] ?? declarations.variables.get(varName)?.types ?? `I${varName}`;
return {
buildDefinition,
buildStorage,
buildEvent: buildVariant("events"),
buildError: buildVariant("errors"),
buildCall,
buildConstant,
getTypeFromVarName,
getCode
};
};
// src/dynamic-builder.ts
var scale = __toESM(require("@polkadot-api/substrate-bindings"));
var _bytes = scale.Hex();
var isBytes2 = (input) => input.type === "primitive" && input.value === "u8";
var import_utils = require("@polkadot-api/utils");
var _bytes = scale.Bin();
var _buildCodec = (input, cache, stack, _accountId) => {
if (input.type === "primitive")
return scale[input.value];
if (input.type === "AccountId32")
return _accountId;
if (input.type === "compact")

@@ -587,5 +271,4 @@ return scale.compact;

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

@@ -599,9 +282,14 @@ }

return buildStruct(input.value);
const dependencies = Object.entries(input.value).map(([k, v]) => {
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) => {
if (v.type === "primitive")
return scale._void;
if (v.type === "tuple" && v.value.length === 1) {
const innerVal = v.value[0];
return k.startsWith("Raw") && innerVal.type === "array" && isBytes2(innerVal.value) ? scale.fixedStr(innerVal.len) : buildNextCodec(innerVal);
}
if (v.type === "tuple" && v.value.length === 1)
return buildNextCodec(v.value[0]);
return v.type === "tuple" ? buildTuple(v.value) : buildStruct(v.value);

@@ -616,6 +304,5 @@ });

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

@@ -670,16 +357,12 @@ 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;
if (entry.type === "tuple" && entry.value.length === 1)
return buildDefinition(entry.value[0].id);
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))
);
};

@@ -695,8 +378,17 @@ 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 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 {

@@ -707,3 +399,4 @@ buildDefinition,

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

@@ -718,66 +411,134 @@ ss58Prefix

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")

@@ -787,16 +548,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) => {

@@ -806,3 +705,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) => {

@@ -812,6 +711,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]);

@@ -822,15 +721,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 (_) {

@@ -840,2 +739,24 @@ 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 buildNamedTuple = (input) => {
return structLikeBuilder(
shapeIds.tuple,
input.value,
(entry) => buildDefinition(entry.id)
);
};
const buildVariant = (variantType) => (pallet, name) => {

@@ -849,3 +770,3 @@ try {

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

@@ -866,7 +787,10 @@ 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),
buildNamedTuple: toStringEnhancer(buildNamedTuple)
};

@@ -876,9 +800,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) => {

@@ -957,9 +881,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) => {

@@ -981,6 +913,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) => {

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

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

@@ -1017,3 +961,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",

@@ -1024,3 +968,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);
}

@@ -1035,2 +979,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) => {

@@ -1051,3 +999,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 {

@@ -1088,9 +1036,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) => {

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

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

@@ -1127,4 +1069,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';

@@ -9,6 +9,6 @@ type VoidVar = {

};
type MetadataPrimitives$1 = "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256";
type MetadataPrimitives = "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256";
type PrimitiveVar = {
type: "primitive";
value: MetadataPrimitives$1;
value: MetadataPrimitives;
} | VoidVar;

@@ -22,3 +22,6 @@ type CompactVar = {

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

@@ -41,2 +44,13 @@ type: "tuple";

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

@@ -51,3 +65,3 @@ type: "sequence";

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

@@ -62,3 +76,3 @@ type LookupEntry = {

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

@@ -68,5 +82,5 @@ def: {

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

@@ -79,5 +93,5 @@ }[];

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

@@ -157,5 +171,2 @@ }[];

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

@@ -165,30 +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>;
interface Variable {
id: string;
types: string;
value: string;
directDependencies: Set<string>;
}
interface CodeDeclarations {
imports: Set<string>;
typeImports: Set<string>;
variables: Map<string, Variable>;
}
declare const getStaticBuilder: (metadata: V14) => {
buildDefinition: (id: number) => string;
buildStorage: (pallet: string, entry: string) => {
key: string;
val: string;
};
buildEvent: (pallet: string, name: string) => string;
buildError: (pallet: string, name: string) => string;
buildCall: (pallet: string, callName: string) => string;
buildConstant: (pallet: string, constantName: string) => string;
getTypeFromVarName: (varName: string) => string;
getCode: () => string;
};
declare const getDynamicBuilder: (metadata: V14) => {
declare const getDynamicBuilder: (metadata: V15) => {
buildDefinition: (id: number) => Codec<any>;

@@ -216,3 +200,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) => {
codec: Codec<any>;
location: [

@@ -222,3 +211,2 @@ number,

];
args: Codec<any>;
};

@@ -229,12 +217,23 @@ 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;
buildNamedTuple: (input: 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) => {

@@ -245,2 +244,6 @@ shape: Shape;

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

@@ -324,2 +327,10 @@ interface DecodedCall {

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

@@ -338,3 +349,3 @@ codec: "Tuple";

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

@@ -344,3 +355,3 @@ };

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

@@ -364,2 +375,13 @@ interface SequenceShape {

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

@@ -369,3 +391,3 @@ codec: "Enum";

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

@@ -377,2 +399,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 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 };

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

"use strict";var se=Object.create;var W=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var pe=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var le=(e,t)=>{for(var p in t)W(e,p,{get:t[p],enumerable:!0})},G=(e,t,p,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ue(t))!de.call(e,s)&&s!==p&&W(e,s,{get:()=>t[s],enumerable:!(r=ce(t,s))||r.enumerable});return e};var J=(e,t,p)=>(p=e!=null?se(pe(e)):{},G(t||!e||!e.__esModule?W(p,"default",{value:e,enumerable:!0}):p,e)),me=e=>G(W({},"__esModule",{value:!0}),e);var We={};le(We,{getChecksumBuilder:()=>Ee,getDynamicBuilder:()=>Se,getLookupFn:()=>T,getStaticBuilder:()=>ve,getViewBuilder:()=>ae,primitiveTypes:()=>M});module.exports=me(We);var $={type:"primitive",value:"_void"},T=e=>{let t=new Map,p=new Set,s=(d=>o=>{let h=t.get(o);if(h)return h;if(p.has(o)){let c={id:o};return t.set(o,c),c}p.add(o);let y=d(o);return h=t.get(o),h?Object.assign(h,y):(h={id:o,...y},t.set(o,h)),p.delete(o),h})(d=>{let{def:o}=e[d];if(o.tag==="composite"){if(o.value.length===0)return $;if(o.value.length===1)return s(o.value[0].type);let y=!0,c={},v={};return o.value.forEach((b,g)=>{y=y&&!!b.name;let u=b.name||g;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(o.tag==="variant"){if(o.value.length===0)return $;let y={},c={};return o.value.forEach(v=>{let b=v.name;if(c[b]=v.docs,v.fields.length===0){y[b]={...$,idx:v.index};return}let g=!0,u={},n={};v.fields.forEach((i,a)=>{g=g&&!!i.name;let l=i.name||a;u[l]=s(i.type),n[l]=i.docs}),y[b]=g?{type:"struct",value:u,innerDocs:n,idx:v.index}:{type:"tuple",value:Object.values(u),innerDocs:Object.values(n),idx:v.index}}),{type:"enum",value:y,innerDocs:c}}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 $;if(o.value.length===1)return s(o.value[0]);let y=o.value.map(v=>s(v)),c=o.value.map(v=>e[v].docs);return{type:"tuple",value:y,innerDocs:c}}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 o.tag==="bitSequence"?{type:"bitSequence"}:{type:"primitive",value:o.value}});return s};var L=(e,t,p)=>(r,s,d,...o)=>{let{id:h}=r;if(s.has(h))return s.get(h);if(d.has(h)){let c=t(()=>s.get(h),r,...o);return s.set(h,c),c}d.add(h);let y=e(r,s,d,...o);return d.delete(h),s.has(h)&&(y=p(y,s.get(h),r,...o)),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"},I=(...e)=>e[0]+e.slice(1).map(t=>t[0].toUpperCase()+t.slice(1)).join(""),Y=e=>e.type==="primitive"&&e.value==="u8",O=e=>M[e]??`I${e}`,ye=(e,t,p,r,s)=>{if(e.type==="primitive")return r.imports.add(e.value),e.value;if(e.type==="compact"){let n=e.isBig?"compactBn":"compactNumber";return r.imports.add(n),n}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("Hex"),r.typeImports.add("HexString");let n={id:"_bytesSeq",value:"Hex()",types:"HexString",directDependencies:new Set};return r.variables.has(n.id)||r.variables.set(n.id,n),n.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=n=>z(n,t,p,r,s),o=(n,i,a)=>{r.imports.add("Vector");let l=d(i),S={id:n,value:`Vector(${(a?[l,a]:[l]).join(", ")})`,types:`Array<${O(l)}>`,directDependencies:new Set([l])};return r.variables.set(n,S),n},h=(n,i)=>{r.imports.add("Tuple");let a=i.map(d),l={id:n,value:`Tuple(${a.join(", ")})`,types:`[${a.map(O).join(", ")}]`,directDependencies:new Set(a)};return r.variables.set(n,l),n},y=(n,i)=>{r.imports.add("Struct");let a=Object.values(i).map(d),l={id:n,value:`Struct({${Object.keys(i).map((m,S)=>`${m}: ${a[S]}`).join(", ")}})`,types:`{${Object.keys(i).map((m,S)=>`${m}: ${O(a[S])}`).join(", ")}}`,directDependencies:new Set(a)};return r.variables.set(n,l),n},c=s(e.id);if(e.type==="array"){if(Y(e.value)){if(e.len===32&&(e.id===0||e.id===1)){r.imports.add("AccountId");let n="_accountId";return r.variables.set(n,{id:n,value:"AccountId()",types:"SS58String",directDependencies:new Set}),r.typeImports.add("SS58String"),n}return r.imports.add("Hex"),r.variables.set(c,{id:c,value:`Hex(${e.len})`,types:"HexString",directDependencies:new Set}),r.typeImports.add("HexString"),c}return o(c,e.value,e.len)}if(e.type==="sequence")return o(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(([n,i])=>{if(i.type==="primitive")return r.imports.add(i.value),i.value;let a=I(c,n);if(i.type==="tuple"){if(i.value.length===1){let l,m=i.value[0];if(n.startsWith("Raw")&&m.type==="array"&&Y(m.value)){let S=`_fixedStr${m.len}`;l=S,r.variables.has(S)||(r.imports.add("fixedStr"),r.variables.set(S,{id:S,value:`fixedStr(${m.len})`,types:"string",directDependencies:new Set}))}else l=d(i.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,i.value)}else y(a,i.value);return a}),b=Object.values(e.value).map(n=>n.idx),g=b.every((n,i)=>n===i),u=`{${Object.keys(e.value).map((n,i)=>`${n}: ${v[i]}`)}}${g?"":`, [${b.join(", ")}]`}`;return r.variables.set(c,{id:c,value:`Enum(${u})`,types:Object.keys(e.value).map((n,i)=>`{tag: '${n}', value: ${O(v[i])}}`).join(" | "),directDependencies:new Set(v)}),c},z=L(ye,(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),ve=e=>{let t={imports:new Set,typeImports:new Set(["Codec"]),variables:new Map},p=e.lookup,r=T(p),s=(a,...l)=>{let{path:m}=p[a],S=m.length===0?["cdc"+a]:["c",...m];return S.push(...l),I(...S)},d=new Map,o=a=>z(r(a),d,new Set,t,s),h=(a,l)=>{if(t.variables.has(l))return l;let m=a.map(x=>x.type).map(o),S=a.map(x=>x.name);t.imports.add("Tuple");let E={id:l,types:`[${S.map((x,V)=>`${x[0].toUpperCase()+x.slice(1)}: ${O(m[V])}`).join(", ")}]`,value:`Tuple(${m.join(", ")})`,directDependencies:new Set(m)};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 m=e.pallets.find(j=>j.name===a).storage.items.find(j=>j.name===l);if(m.type.tag==="plain")return{key:c(),val:o(m.type.value)};let{key:S,value:E}=m.type.value,x=o(E);return{key:m.type.value.hashers.length===1?h([{name:"key",type:S}],s(S,"Tupled")):o(S),val:x}},b=a=>(l,m)=>{let S=r(e.pallets.find(x=>x.name===l)[a]);if(S.type!=="enum")throw null;let E=I(o(S.id),m);return!t.variables.has(E)&&S.value[m].type==="primitive"&&t.variables.set(E,{id:E,value:"_void",types:"undefined",directDependencies:new Set}),E},g=(a,l)=>{let m=r(e.pallets.find(x=>x.name===a).calls);if(m.type!=="enum")throw null;let S=m.value[l];if(S.type==="primitive")return c();if(S.type==="tuple")return I(o(m.id),l);let E=Object.entries(S.value).map(([x,V])=>({name:x,type:V.id}));return h(E,s(m.id,l,"Tupled"))},u=(a,l)=>{let m=e.pallets.find(S=>S.name===a).constants.find(S=>S.name===l);return o(m.type)},n=()=>{let a=`import type {${[...t.typeImports].join(", ")}} from "@polkadot-api/substrate-bindings";
`,l=`import {${[...t.imports].join(", ")}} from "@polkadot-api/substrate-bindings";
`,m=[...t.variables.values()].map(S=>`type I${S.id} = ${S.types};
const ${S.id}: Codec<I${S.id}> = ${S.value};`).join(`
`);return`${a}${l}${m}`},i=a=>M[a]??t.variables.get(a)?.types??`I${a}`;return{buildDefinition:o,buildStorage:v,buildEvent:b("events"),buildError:b("errors"),buildCall:g,buildConstant:u,getTypeFromVarName:i,getCode:n}};var f=J(require("@polkadot-api/substrate-bindings"));var he=f.Hex(),Q=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 he;let s=g=>X(g,t,p,r),d=(g,u)=>{let n=s(g);return u?f.Vector(n,u):f.Vector(n)},o=g=>f.Tuple(...g.map(s)),h=g=>{let u=Object.fromEntries(Object.entries(g).map(([n,i])=>[n,s(i)]));return f.Struct(u)};if(e.type==="array")return Q(e.value)?e.len===32&&(e.id===0||e.id===1)?r:f.Hex(e.len):d(e.value,e.len);if(e.type==="sequence")return d(e.value);if(e.type==="tuple")return o(e.value);if(e.type==="struct")return h(e.value);let y=Object.entries(e.value).map(([g,u])=>{if(u.type==="primitive")return f._void;if(u.type==="tuple"&&u.value.length===1){let n=u.value[0];return g.startsWith("Raw")&&n.type==="array"&&Q(n.value)?f.fixedStr(n.len):s(n)}return u.type==="tuple"?o(u.value):h(u.value)}),c=Object.fromEntries(Object.keys(e.value).map((g,u)=>[g,y[u]])),v=Object.values(e.value).map(g=>g.idx);return v.every((g,u)=>g===u)?f.Enum(c):f.Enum(c,v)},X=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=>X(p(u),s,new Set,r),o=e.pallets.find(u=>u.name==="System")?.constants.find(u=>u.name==="SS58Prefix"),h;if(o)try{let u=d(o.type).dec(o.value);typeof u=="number"&&(h=u,r=f.AccountId(u))}catch{}let y=new Map,c=(u,n)=>{let i=y.get(u);i||y.set(u,i=f.Storage(u));let a=e.pallets.find(C=>C.name===u).storage.items.find(C=>C.name===n),l=(C,...B)=>{let K=i(...B);return{...K,len:C,fallback:a.modifier===1?K.dec(a.fallback):void 0}};if(a.type.tag==="plain")return l(0,n,d(a.type.value).dec);let{key:m,value:S,hashers:E}=a.type.value,x=d(S),V=E.map(C=>f[C.tag]),j=V.length===1?[[d(m),V[0]]]:p(m).value.map((C,B)=>[d(C.id),V[B]]);return l(V.length,n,x.dec,...j)},v=(u,n)=>{let i=e.pallets.find(m=>m.name===u),a=p(i.calls);if(a.type!=="enum")throw null;let l=a.value[n];return{location:[i.index,l.idx],args:l.type==="primitive"?ge:f.Tuple(...Object.values(l.value).map(m=>d(m.id)))}},b=(u,n)=>{let i=e.pallets.find(a=>a.name===u).constants.find(a=>a.name===n);return d(i.type)},g=u=>(n,i)=>{let a=e.pallets.find(S=>S.name===n),l=p(a[u]);if(l.type!=="enum")throw null;let m=l.value[i];return{location:[a.index,m.idx],codec:m.type==="primitive"?f._void:d(l.id)}};return{buildDefinition:d,buildStorage:c,buildEvent:g("events"),buildError:g("errors"),buildCall:v,buildConstant:b,ss58Prefix:h}};var F=require("@polkadot-api/substrate-bindings");var Z=new TextEncoder,fe=Z.encode.bind(Z),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 o=0;o<e.length;o++,d+=8)s.setBigUint64(d,e[o]);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=>ee(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)),o=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 o(e.value);let h=Object.values(e.value).map(c=>c.type==="primitive"?0n:c.type==="tuple"?d(c.value):o(c.value)),y=Object.keys(e.value);return y.push("Enum"),k(h,JSON.stringify({Enum:y}))},ee=L(xe,()=>0n,e=>e),Ee=e=>{let t=e.lookup,p=T(t),r=new Map,s=b=>ee(p(b),r,new Set),d=(b,g)=>{try{let u=e.pallets.find(m=>m.name===b).storage.items.find(m=>m.name===g);if(u.type.tag==="plain")return k([s(u.type.value)]);let{key:n,value:i}=u.type.value,a=s(i),l=u.type.value.hashers.length===1?k([s(n)]):s(n);return k([a,l])}catch{return null}},o=b=>{if(b.type==="primitive")return 0n;let g=Object.values(b.value).map(u=>s(u.id));return b.type==="tuple"?k(g):k(g,JSON.stringify(Object.keys(b.value)))},h=(b,g)=>{try{let u=e.pallets.find(i=>i.name===b),n=p(u.calls);if(n.type!=="enum")throw null;return o(n.value[g])}catch{return null}},y=b=>(g,u)=>{try{let n=e.pallets.find(a=>a.name===g),i=p(n[b]);if(i.type!=="enum")throw null;return o(i.value[u])}catch{return null}},c=(b,g)=>{try{let u=e.pallets.find(n=>n.name===b).constants.find(n=>n.name===g);return s(u.type)}catch{return null}},v=b=>(...g)=>b(...g)?.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 oe=require("@polkadot-api/utils"),A=require("@polkadot-api/substrate-bindings");var R=require("@polkadot-api/utils"),D=J(require("@polkadot-api/substrate-bindings")),ke=R.toHex,te=(e,t)=>D.createDecoder(p=>{let r=p,s=r.i,d=e(r),o=ke(new Uint8Array(r.buffer.slice(s,r.i)));return{...t,value:d,input:o}}),_=(e,t,p)=>{let r=te(t,{codec:e,...p});return Object.assign(r,{shape:{codec:e}})},q=(e,t,p)=>{let r=te(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,{})},Ve=e=>_("BytesArray",D.Hex.dec(e),{len:e}),Ce=["_void","bool","char","str","u8","u16","u32","i8","i16","i32","u64","u128","u256","i64","i128","i256","compactNumber","compactBn","bitSequence"],Te=Object.fromEntries(Ce.map(e=>[e,_(e,D[e].dec)])),P={...Te,Bytes:_("Bytes",D.Hex.dec()),BytesArray:Ve,AccountId:U()},Pe=e=>q({codec:"Sequence",shape:e.shape},D.Vector.dec(e)),Le=(e,t)=>q({codec:"Array",shape:e.shape,len:t},D.Vector.dec(e,t)),we=(...e)=>q({codec:"Tuple",shape:e.map(t=>t.shape)},D.Tuple.dec(...e)),Ae=e=>q({codec:"Struct",shape:(0,R.mapStringRecord)(e,t=>t.shape)},D.Struct.dec(e)),Oe=(e,t)=>q({codec:"Enum",shape:(0,R.mapStringRecord)(e,p=>p.shape)},D.Enum.dec(e,t)),re=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:o}=s[t.id],h=e(t,p,r,s,...d);return o.length?N(h,"path",o):h},Re=(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=i=>ie(i,t,p,r,s),o=(i,a)=>{let l=d(i);return a?w.Array(l,a):w.Sequence(l)},h=(i,a)=>N(w.Tuple(...i.map(d)),"innerDocs",a),y=(i,a)=>N(w.Struct((0,oe.mapStringRecord)(i,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):o(e.value,e.len);if(e.type==="sequence")return o(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(i=>i.type==="primitive"?P._void:i.type==="tuple"&&i.value.length===1?d(i.value[0]):i.type==="tuple"?h(i.value,i.innerDocs):y(i.value,i.innerDocs)),v=Object.fromEntries(Object.keys(e.value).map((i,a)=>[i,c[a]])),b=Object.values(e.value).map(i=>i.idx),u=b.every((i,a)=>i===a)?w.Enum(v):w.Enum(v,b),n=(0,A.enhanceDecoder)(u,i=>{let a=e.innerDocs[i.value.tag];return{...i,docs:a}});return n.shape=u.shape,n},qe=je(Re),ie=L(qe,re,(e,t)=>(t.shape=e.shape,e)),ne=e=>`0x${e.toString(16).padEnd(2,"0")}`,ae=e=>{let t=e.lookup,p=new Map,r=c=>ie(s(c),p,new Set,t,d),s=T(t),d=P.AccountId,o=e.pallets.find(c=>c.name==="System")?.constants.find(c=>c.name==="SS58Prefix");if(o)try{let c=r(o.type)(o.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 g={value:{name:b.name,idx:v},input:ne(c[0])},u=r(b.calls),n=u(c);if(n.codec!=="Enum")throw null;let i={value:{name:n.value.tag,idx:c[1]},input:ne(c[1]),docs:n.docs};return{pallet:g,call:i,args:{value:n.value.value,shape:u.shape}}});return{buildDefinition:h,callDecoder:y}};
"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}};
//# sourceMappingURL=index.js.map
{
"name": "@polkadot-api/metadata-builders",
"version": "0.0.1-3b74a30d89c855b13ddebe0cd6702eff171b7172.1.0",
"version": "0.0.1-3fdf48394f8fd292d39de8ace33d593b54e38cf4.1.0",
"author": "Josep M Sobrepere (https://github.com/josepot)",

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

"dependencies": {
"@polkadot-api/utils": "0.0.1-3b74a30d89c855b13ddebe0cd6702eff171b7172.1.0",
"@polkadot-api/substrate-bindings": "0.0.1-3b74a30d89c855b13ddebe0cd6702eff171b7172.1.0"
"@polkadot-api/utils": "0.0.1-3fdf48394f8fd292d39de8ace33d593b54e38cf4.1.0",
"@polkadot-api/substrate-bindings": "0.0.1-3fdf48394f8fd292d39de8ace33d593b54e38cf4.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