@polkadot-api/metadata-builders
Advanced tools
Comparing version 0.0.1-8085034060d643c71d85df47784513b07a0a247c.1.0 to 0.0.1-8126ff956901484e2daff885f88145c307372713.1.0
@@ -9,6 +9,6 @@ import * as scale from '@polkadot-api/substrate-bindings'; | ||
}; | ||
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; | ||
@@ -169,35 +169,2 @@ type CompactVar = { | ||
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", string>; | ||
interface Variable { | ||
id: string; | ||
types: string; | ||
value: string; | ||
directDependencies: Set<string>; | ||
} | ||
interface CodeDeclarations { | ||
imports: Set<string>; | ||
typeImports: Set<string>; | ||
enums: Map<string, string>; | ||
variables: Map<string, Variable>; | ||
} | ||
declare const getStaticBuilder: (metadata: V15) => { | ||
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, 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: V15) => { | ||
@@ -231,3 +198,3 @@ buildDefinition: (id: number) => Codec<any>; | ||
buildCall: (pallet: string, name: string) => { | ||
args: Codec<any>; | ||
codec: Codec<any>; | ||
location: [ | ||
@@ -417,2 +384,2 @@ number, | ||
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 }; | ||
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 | ||
}); | ||
@@ -216,2 +214,5 @@ module.exports = __toCommonJS(src_exports); | ||
// src/dynamic-builder.ts | ||
var scale = __toESM(require("@polkadot-api/substrate-bindings")); | ||
// src/with-cache.ts | ||
@@ -236,368 +237,3 @@ 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}" | ||
}; | ||
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) => { | ||
if (input.type === "primitive") { | ||
declarations.imports.add(input.value); | ||
return input.value; | ||
} | ||
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") { | ||
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("Bin"); | ||
declarations.typeImports.add("HexString"); | ||
declarations.typeImports.add("Binary"); | ||
const variable = { | ||
id: "_bytesSeq", | ||
value: "Bin()", | ||
types: "Binary", | ||
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 (input.value.type === "primitive" && input.value.value === "u8") { | ||
declarations.imports.add("Bin"); | ||
declarations.variables.set(varId, { | ||
id: varId, | ||
value: `Bin(${input.len})`, | ||
types: "Binary", | ||
directDependencies: /* @__PURE__ */ new Set() | ||
}); | ||
declarations.typeImports.add("HexString"); | ||
declarations.typeImports.add("Binary"); | ||
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); | ||
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]) => { | ||
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 = 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.enums.set( | ||
varId, | ||
Object.keys(input.value).map( | ||
(key, idx) => `{type: '${key}', value: ${getTypes(dependencies[idx])}}` | ||
).join(" | ") | ||
); | ||
declarations.variables.set(varId, { | ||
id: varId, | ||
value: `Variant(${innerEnum})`, | ||
types: `Enum<E${varId}>`, | ||
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: 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(), | ||
enums: /* @__PURE__ */ new Map() | ||
}; | ||
const lookupData = metadata.lookup; | ||
const getLookupEntryDef = getLookupFn(lookupData); | ||
const getVarName = (idx, ...post) => { | ||
const { path } = lookupData[idx]; | ||
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); | ||
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 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 lookupEntry = getLookupEntryDef( | ||
metadata.pallets.find((x) => x.name === pallet)[type] | ||
); | ||
if (lookupEntry.type !== "enum") | ||
throw null; | ||
const returnVar = toCamelCase(buildDefinition(lookupEntry.id), name); | ||
if (!declarations.variables.has(returnVar) && lookupEntry.value[name].type === "primitive") { | ||
declarations.variables.set(returnVar, { | ||
id: returnVar, | ||
value: "_void", | ||
types: "undefined", | ||
directDependencies: /* @__PURE__ */ new Set() | ||
}); | ||
} | ||
return returnVar; | ||
}; | ||
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/client"; | ||
`; | ||
const varImports = `import {${[...declarations.imports].join( | ||
", " | ||
)}} from "@polkadot-api/substrate-bindings"; | ||
`; | ||
const code = [...declarations.variables.values()].map((variable) => { | ||
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 getEnums = () => [...declarations.enums.keys()]; | ||
const getTypeFromVarName = (varName) => primitiveTypes[varName] ?? declarations.variables.get(varName)?.types ?? varName; | ||
return { | ||
buildDefinition, | ||
buildStorage, | ||
buildEvent: buildVariant("events"), | ||
buildError: buildVariant("errors"), | ||
buildCall: buildVariant("calls"), | ||
buildRuntimeCall, | ||
buildConstant, | ||
getTypeFromVarName, | ||
getCode, | ||
getEnums | ||
}; | ||
}; | ||
// src/dynamic-builder.ts | ||
var scale = __toESM(require("@polkadot-api/substrate-bindings")); | ||
var import_utils = require("@polkadot-api/utils"); | ||
@@ -716,2 +352,4 @@ var _bytes = scale.Bin(); | ||
return scale._void; | ||
if (entry.type === "tuple" && entry.value.length === 1) | ||
return buildDefinition(entry.value[0].id); | ||
return entry.type === "tuple" ? scale.Tuple( | ||
@@ -738,13 +376,2 @@ ...Object.values(entry.value).map((l) => buildDefinition(l.id)) | ||
}; | ||
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) => { | ||
@@ -765,3 +392,3 @@ const entry = metadata.apis.find((x) => x.name === api)?.methods.find((x) => x.name === method); | ||
buildRuntimeCall, | ||
buildCall, | ||
buildCall: buildVariant("calls"), | ||
buildConstant, | ||
@@ -768,0 +395,0 @@ ss58Prefix |
@@ -9,6 +9,6 @@ import * as scale from '@polkadot-api/substrate-bindings'; | ||
}; | ||
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; | ||
@@ -169,35 +169,2 @@ type CompactVar = { | ||
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", string>; | ||
interface Variable { | ||
id: string; | ||
types: string; | ||
value: string; | ||
directDependencies: Set<string>; | ||
} | ||
interface CodeDeclarations { | ||
imports: Set<string>; | ||
typeImports: Set<string>; | ||
enums: Map<string, string>; | ||
variables: Map<string, Variable>; | ||
} | ||
declare const getStaticBuilder: (metadata: V15) => { | ||
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, 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: V15) => { | ||
@@ -231,3 +198,3 @@ buildDefinition: (id: number) => Codec<any>; | ||
buildCall: (pallet: string, name: string) => { | ||
args: Codec<any>; | ||
codec: Codec<any>; | ||
location: [ | ||
@@ -417,2 +384,2 @@ number, | ||
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 }; | ||
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,9 +0,2 @@ | ||
"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 u in t)W(e,u,{get:t[u],enumerable:!0})},X=(e,t,u,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ve(t))!be.call(e,i)&&i!==u&&W(e,i,{get:()=>t[i],enumerable:!(r=ye(t,i))||r.enumerable});return e};var Z=(e,t,u)=>(u=e!=null?me(he(e)):{},X(t||!e||!e.__esModule?W(u,"default",{value:e,enumerable:!0}):u,e)),Se=e=>X(W({},"__esModule",{value:!0}),e);var Ne={};ge(Ne,{getChecksumBuilder:()=>Re,getDynamicBuilder:()=>xe,getLookupFn:()=>R,getStaticBuilder:()=>De,getViewBuilder:()=>de,primitiveTypes:()=>N});module.exports=Se(Ne);var M={type:"primitive",value:"_void"},R=e=>{let t=new Map,u=new Set,r=l=>o=>{let y=t.get(o);if(y)return y;if(u.has(o)){let h={id:o};return t.set(o,h),h}u.add(o);let v=l(o);return y=t.get(o),y?Object.assign(y,v):(y={id:o,...v},t.set(o,y)),u.delete(o),y},i=!0,a=r(l=>{let{def:o,path:y,params:v}=e[l];if(o.tag==="composite"){if(o.value.length===0)return M;if(o.value.length===1)return i&&y.join(",")==="sp_core,crypto,AccountId32"?(i=!1,{type:"AccountId32"}):a(o.value[0].type);let h=!0,f={},s={};return o.value.forEach((b,c)=>{h=h&&!!b.name;let n=b.name||c;f[n]=a(b.type),s[n]=b.docs}),h?{type:"struct",value:f,innerDocs:s}:{type:"tuple",value:Object.values(f),innerDocs:Object.values(s)}}if(o.tag==="variant"){if(y.length===1&&y[0]==="Option"&&v.length===1&&v[0].name==="T"){let s=a(v[0].type);return s.type==="primitive"&&s.value==="_void"?{type:"primitive",value:"bool"}:{type:"option",value:s}}if(y.length===1&&y[0]==="Result"&&v.length===2&&v[0].name==="T"&&v[1].name==="E")return{type:"result",value:{ok:a(v[0].type),ko:a(v[1].type)}};if(o.value.length===0)return M;let h={},f={};return o.value.forEach(s=>{let b=s.name;if(f[b]=s.docs,s.fields.length===0){h[b]={...M,idx:s.index};return}let c=!0,n={},d={};s.fields.forEach((p,m)=>{c=c&&!!p.name;let g=p.name||m;n[g]=a(p.type),d[g]=p.docs}),h[b]=c?{type:"struct",value:n,innerDocs:d,idx:s.index}:{type:"tuple",value:Object.values(n),innerDocs:Object.values(d),idx:s.index}}),{type:"enum",value:h,innerDocs:f}}if(o.tag==="sequence")return{type:"sequence",value:a(o.value)};if(o.tag==="array")return{type:"array",value:a(o.value.type),len:o.value.len};if(o.tag==="tuple"){if(o.value.length===0)return M;if(o.value.length===1)return a(o.value[0]);let h=o.value.map(s=>a(s)),f=o.value.map(s=>e[s].docs);return{type:"tuple",value:h,innerDocs:f}}if(o.tag==="primitive")return{type:"primitive",value:o.value.tag};if(o.tag==="compact"){let h=a(o.value);return{type:"compact",isBig:Number(h.value.slice(1))>32}}return{type:o.tag}});return a};var _=(e,t,u)=>(r,i,a,...l)=>{let{id:o}=r;if(i.has(o))return i.get(o);if(a.has(o)){let v=t(()=>i.get(o),r,...l);return i.set(o,v),v}a.add(o);let y=e(r,i,a,...l);return a.delete(o),i.has(o)&&(y=u(y,i.get(o),r,...l)),i.set(o,y),y};var N={_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}"},K=(...e)=>e.map(t=>t[0].toUpperCase()+t.slice(1)).join(""),P=e=>N[e]??e,fe=(e,t,u,r,i)=>{if(e.type==="primitive")return r.imports.add(e.value),e.value;if(e.type==="AccountId32"){r.imports.add("AccountId");let c="_accountId";return r.variables.set(c,{id:c,value:"AccountId()",types:"SS58String",directDependencies:new Set}),r.typeImports.add("SS58String"),c}if(e.type==="compact"){let c=e.isBig?"compactBn":"compactNumber";return r.imports.add(c),c}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 c={id:"_bytesSeq",value:"Bin()",types:"Binary",directDependencies:new Set};return r.variables.has(c.id)||r.variables.set(c.id,c),c.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 a=c=>ee(c,t,u,r,i),l=(c,n,d)=>{r.imports.add("Vector");let p=a(n),g={id:c,value:`Vector(${(d?[p,d]:[p]).join(", ")})`,types:`Array<${P(p)}>`,directDependencies:new Set([p])};return r.variables.set(c,g),c},o=(c,n)=>{r.imports.add("Tuple");let d=n.map(a),p={id:c,value:`Tuple(${d.join(", ")})`,types:`[${d.map(P).join(", ")}]`,directDependencies:new Set(d)};return r.variables.set(c,p),c},y=(c,n)=>{r.imports.add("Struct");let d=Object.values(n).map(a),p={id:c,value:`Struct({${Object.keys(n).map((m,g)=>`${m}: ${d[g]}`).join(", ")}})`,types:`{${Object.keys(n).map((m,g)=>`${m}: ${P(d[g])}`).join(", ")}}`,directDependencies:new Set(d)};return r.variables.set(c,p),c},v=i(e.id);if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?(r.imports.add("Bin"),r.variables.set(v,{id:v,value:`Bin(${e.len})`,types:"Binary",directDependencies:new Set}),r.typeImports.add("HexString"),r.typeImports.add("Binary"),v):l(v,e.value,e.len);if(e.type==="sequence")return l(v,e.value);if(e.type==="tuple")return o(v,e.value);if(e.type==="struct")return y(v,e.value);if(e.type==="option"){r.imports.add("Option");let c=a(e.value),n=`_Option_${c}`,d={id:n,value:`Option(${c})`,types:`${P(c)} | undefined`,directDependencies:new Set([c])};return r.variables.set(n,d),n}if(e.type==="result"){r.imports.add("Result"),r.typeImports.add("ResultPayload");let c=a(e.value.ok),n=a(e.value.ko),d=`_Result_${c}_${n}`,p={id:d,value:`Result(${c}, ${n})`,types:`ResultPayload<${P(c)}, ${P(n)}>`,directDependencies:new Set([c,n])};return r.variables.set(d,p),d}r.imports.add("Variant"),r.typeImports.add("Enum");let h=Object.entries(e.value).map(([c,n])=>{if(n.type==="primitive")return r.imports.add(n.value),n.value;let d=K(v,c);if(n.type==="tuple"){if(n.value.length===1){let p=a(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 y(d,n.value);return d}),f=Object.values(e.value).map(c=>c.idx),s=f.every((c,n)=>c===n),b=`{${Object.keys(e.value).map((c,n)=>`${c}: ${h[n]}`)}}${s?"":`, [${f.join(", ")}]`}`;return r.enums.set(v,Object.keys(e.value).map((c,n)=>`{type: '${c}', value: ${P(h[n])}}`).join(" | ")),r.variables.set(v,{id:v,value:`Variant(${b})`,types:`Enum<E${v}>`,directDependencies:new Set(h)}),v},ee=_(fe,(e,t,u,r)=>{u.imports.add("Self");let i=r(t.id),a={id:r(t.id,"circular"),types:i,value:`Self(() => ${i})`,directDependencies:new Set([i])};return u.variables.set(a.id,a),a.id},e=>e),De=e=>{let t={imports:new Set,typeImports:new Set(["Codec"]),variables:new Map,enums:new Map},u=e.lookup,r=R(u),i=(p,...m)=>{let{path:g}=u[p],S;return g.length===0?S=["cdc"+p]:g[0]==="sp_runtime"?S=[g.slice(-1)[0]]:g.length>2&&g.slice(-2)[0].toUpperCase()===g.slice(-2)[1].toUpperCase()?S=g.slice(0,-1):S=[...g],S.push(...m),K(...S)},a=new Map,l=p=>ee(r(p),a,new Set,t,i),o=(p,m)=>{if(t.variables.has(m))return m;let g=p.map(w=>w.type).map(l),S=p.map(w=>w.name);t.imports.add("Tuple");let C={id:m,types:`[${S.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(m,C),m},y="_emptyTuple",v=()=>(t.variables.has(y)||(t.imports.add("Tuple"),t.variables.set(y,{id:y,types:"[]",value:"Tuple()",directDependencies:new Set})),y),h=(p,m)=>{let g=e.pallets.find(O=>O.name===p).storage.items.find(O=>O.name===m);if(g.type.tag==="plain")return{key:v(),val:l(g.type.value)};let{key:S,value:C}=g.type.value,w=l(C);return{key:g.type.value.hashers.length===1?o([{name:"key",type:S}],i(S,"Tupled")):l(S),val:w}},f=(p,m)=>{let g=e.apis.find(S=>S.name===p)?.methods.find(S=>S.name===m);if(!g)throw null;return{args:o(g.inputs,`${p}${m}Args`),value:l(g.output)}},s=p=>(m,g)=>{let S=r(e.pallets.find(w=>w.name===m)[p]);if(S.type!=="enum")throw null;let C=K(l(S.id),g);return!t.variables.has(C)&&S.value[g].type==="primitive"&&t.variables.set(C,{id:C,value:"_void",types:"undefined",directDependencies:new Set}),C},b=(p,m)=>{let g=e.pallets.find(S=>S.name===p).constants.find(S=>S.name===m);return l(g.type)},c=()=>{let p=`import type {${[...t.typeImports].join(", ")}} from "@polkadot-api/client"; | ||
`,m=`import {${[...t.imports].join(", ")}} from "@polkadot-api/substrate-bindings"; | ||
`,g=[...t.variables.values()].map(S=>`${t.enums.has(S.id)?`type E${S.id} = ${t.enums.get(S.id)}; | ||
export `:""}type ${S.id} = ${S.types}; | ||
const ${S.id}: Codec<${S.id}> = ${S.value};`).join(` | ||
`);return`${p}${m}${g}`},n=()=>[...t.enums.keys()],d=p=>N[p]??t.variables.get(p)?.types??p;return{buildDefinition:l,buildStorage:h,buildEvent:s("events"),buildError:s("errors"),buildCall:s("calls"),buildRuntimeCall:f,buildConstant:b,getTypeFromVarName:d,getCode:c,getEnums:n}};var D=Z(require("@polkadot-api/substrate-bindings"));var te=require("@polkadot-api/utils"),Ee=D.Bin(),ke=(e,t,u,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=s=>re(s,t,u,r),a=(s,b)=>{let c=i(s);return b?D.Vector(c,b):D.Vector(c)},l=s=>D.Tuple(...s.map(i)),o=s=>{let b=Object.fromEntries(Object.entries(s).map(([c,n])=>[c,i(n)]));return D.Struct(b)};if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?D.Bin(e.len):a(e.value,e.len);if(e.type==="sequence")return a(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 y=Object.values(e.value).map(s=>s.type==="primitive"?D._void:s.type==="tuple"&&s.value.length===1?i(s.value[0]):s.type==="tuple"?l(s.value):o(s.value)),v=Object.fromEntries(Object.keys(e.value).map((s,b)=>[s,y[b]])),h=Object.values(e.value).map(s=>s.idx);return h.every((s,b)=>s===b)?D.Variant(v):D.Variant(v,h)},re=_(ke,D.Self,e=>e),xe=e=>{let t=e.lookup,u=R(t),r=D.AccountId(),i=new Map,a=n=>re(u(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=a(l.type).dec(l.value);typeof n=="number"&&(o=n,r=D.AccountId(n))}catch{}let y=new Map,v=(n,d)=>{let p=y.get(n);p||y.set(n,p=D.Storage(n));let m=e.pallets.find(A=>A.name===n).storage.items.find(A=>A.name===d),g=(A,...G)=>{let Q=p(...G);return{...Q,len:A,fallback:m.modifier===1?Q.dec(m.fallback):void 0}};if(m.type.tag==="plain")return g(0,d,a(m.type.value).dec);let{key:S,value:C,hashers:w}=m.type.value,B=a(C),O=w.map(A=>D[A.tag]),le=O.length===1?[[a(S),O[0]]]:u(S).value.map((A,G)=>[a(A.id),O[G]]);return g(O.length,d,B.dec,...le)},h=n=>n.type==="primitive"?D._void:n.type==="tuple"?D.Tuple(...Object.values(n.value).map(d=>a(d.id))):D.Struct((0,te.mapObject)(n.value,d=>a(d.id))),f=(n,d)=>{let p=e.pallets.find(m=>m.name===n).constants.find(m=>m.name===d);return a(p.type)},s=n=>(d,p)=>{let m=e.pallets.find(C=>C.name===d),g=u(m[n]);if(g.type!=="enum")throw null;let S=g.value[p];return{location:[m.index,S.idx],codec:h(g.value[p])}},b=(n,d)=>{let p=e.pallets.find(S=>S.name===n),m=u(p.calls);if(m.type!=="enum")throw null;let g=m.value[d];return{location:[p.index,g.idx],args:h(m.value[d])}},c=(n,d)=>{let p=e.apis.find(m=>m.name===n)?.methods.find(m=>m.name===d);if(!p)throw null;return{args:D.Tuple(...p.inputs.map(m=>a(m.type))),value:a(p.output)}};return{buildDefinition:a,buildStorage:v,buildEvent:s("events"),buildError:s("errors"),buildRuntimeCall:c,buildCall:b,buildConstant:f,ss58Prefix:o}};var z=require("@polkadot-api/substrate-bindings");var ne=new TextEncoder,Ve=ne.encode.bind(ne),x=e=>{let t=new Uint8Array(e.length*8),u=new DataView(t.buffer);for(let r=0;r<e.length;r++)u.setBigUint64(r*8,e[r]);return(0,z.h64)(t)},ie=e=>x(e.map(t=>(0,z.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},U=(e,t,u)=>{let r=Object.entries(t).sort(([l],[o])=>l.localeCompare(o)),i=ie(r.map(([l])=>l)),a=x(r.map(([,l])=>u(l)));return x([e,i,a])},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 u=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(u.map(r=>r.id))]),u.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 u=Object.values(e.value);t.set(e.id,[e,new Set(u.map(r=>r.id))]),u.forEach(r=>I(r,t));break}case"tuple":t.set(e.id,[e,new Set(e.value.map(u=>u.id))]),e.value.forEach(u=>I(u,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 u=i=>x([V.tuple,...i.map(t)]),r=i=>U(V.struct,i,t);return e.type==="tuple"?u(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)]):U(V.enum,e.value,i=>{switch(i.type){case"primitive":return oe._void;case"tuple":return u(i.value);case"struct":return r(i.value)}})},we=e=>{let t=new Map,u=0,r=[],i=[];function a(l){let o={index:u,lowLink:u,onStack:!0};t.set(l,o),u++,r.push(l);let y=e.get(l)[1];for(let v of y){let h=t.get(v);h?h.onStack&&(o.lowLink=Math.min(o.lowLink,h.index)):(a(v),o.lowLink=Math.min(o.lowLink,t.get(v).lowLink))}if(o.lowLink===o.index){let v=new Set,h=-1;do h=r.pop(),t.get(h).onStack=!1,v.add(h);while(h!==l);v.size>1&&i.push(v)}}for(let l of e.keys())t.has(l)||a(l);return i},Te=e=>{let t=new Set(e.map((i,a)=>a)),u=new Map(e.map((i,a)=>[a,new Set]));e.forEach((i,a)=>{e.slice(a+1).forEach((l,o)=>{let y=o+a+1;new Set([...i,...l]).size!==i.size+l.size&&(u.get(a).add(y),u.get(y).add(a))})});let r=[];for(;t.size;){let i=new Set,a=[t.values().next().value];for(;a.length;){let l=a.pop();if(!t.has(l))continue;t.delete(l),e[l].forEach(y=>i.add(Number(y))),u.get(l).forEach(y=>a.push(y))}r.push(i)}return r},Le=(e,t)=>{let u=a=>{let l=a.values().next().value,o=t.get(l)[0];return Array.from(I(o).keys())},r=new Array;function i(a){r.includes(a)||(e.filter(o=>o!==a&&u(a).some(y=>o.has(y))).forEach(o=>i(o)),r.includes(a))||r.push(a)}return e.forEach(a=>i(a)),r},Ae=(e,t)=>{if(t.has(e.id))return t.get(e.id);let u=I(e),r=we(u),i=Te(r),a=Le(i,u),l=(o,y,v=!1)=>{if(!v&&t.has(o.id))return t.get(o.id);let h=Ce(o,f=>l(f,y));return y(o.id,h),h};return a.forEach(o=>{o.forEach(y=>t.set(y,0n));for(let y=0;y<o.size;y++){let v=new Map;o.forEach(h=>l(u.get(h)[0],(f,s)=>{(o.has(f)?v:t).set(f,s)},!0)),Array.from(v.entries()).forEach(([h,f])=>t.set(h,f))}}),l(e,(o,y)=>t.set(o,y))},Re=e=>{let t=e.lookup,u=R(t),r=new Map,i=s=>Ae(u(s),r),a=(s,b)=>{try{let c=e.pallets.find(g=>g.name===s).storage.items.find(g=>g.name===b);if(c.type.tag==="plain")return i(c.type.value);let{key:n,value:d}=c.type.value,p=i(d),m=i(n);return x([p,m])}catch{return null}},l=(s,b)=>{try{let c=e.apis.find(m=>m.name===s)?.methods.find(m=>m.name===b);if(!c)throw null;let n=ie(c.inputs.map(m=>m.name)),d=x(c.inputs.map(m=>i(m.type))),p=i(c.output);return x([n,d,p])}catch{return null}},o=s=>{if(s.type==="primitive")return x([0n]);if(s.type==="tuple"){let b=Object.values(s.value).map(c=>i(c.id));return x([V.tuple,...b])}return U(V.struct,s.value,b=>i(b.id))},y=s=>U(V.tuple,s.value,b=>i(b.id)),v=s=>(b,c)=>{try{let n=e.pallets.find(p=>p.name===b),d=u(n[s]);if(d.type!=="enum")throw null;return o(d.value[c])}catch{return null}},h=(s,b)=>{try{let c=e.pallets.find(n=>n.name===s).constants.find(n=>n.name===b);return i(c.type)}catch{return null}},f=s=>(...b)=>s(...b)?.toString(32)??null;return{buildDefinition:f(i),buildRuntimeCall:f(l),buildStorage:f(a),buildCall:f(v("calls")),buildEvent:f(v("events")),buildError:f(v("errors")),buildConstant:f(h),buildComposite:f(o),buildNamedTuple:f(y)}};var F=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(u=>{let r=u,i=r.i,a=e(r),l=Pe(new Uint8Array(r.buffer.slice(i,r.i)));return{...t,value:a,input:l}}),H=(e,t,u)=>{let r=se(t,{codec:e,...u});return Object.assign(r,{shape:{codec:e}})},j=(e,t,u)=>{let r=se(t,{codec:e.codec,...u});return Object.assign(r,{shape:e})},Y=(e=42)=>{let t=E.enhanceDecoder(E.AccountId(e).dec,u=>({address:u,ss58Prefix:e}));return H("AccountId",t,{})},Oe=e=>H("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,H(e,E[e].dec)])),L={...je,Bytes:H("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,u=>u.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(),a=i;return t=i,a(r)},u=r=>t(r);return u.shape={codec:"_void"},u},T={Sequence:$e,Array:_e,Tuple:qe,Struct:Be,Enum:We,Option:Me,Result:Ue};var He=T.Tuple(),ce=e=>(...t)=>{let u=e(...t);return{shape:u.shape,decoder:u}},J=(e,t,u)=>{let r=(0,$.enhanceDecoder)(e,i=>({...i,[t]:u}));return r.shape=e.shape,r},Fe=e=>(t,u,r,i,...a)=>{let{path:l}=i[t.id],o=e(t,u,r,i,...a);return l.length?J(o,"path",l):o},Ge=(e,t,u,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 a=n=>pe(n,t,u,r,i),l=(n,d)=>{let p=a(n);return d?T.Array(p,d):T.Sequence(p)},o=(n,d)=>J(T.Tuple(...n.map(a)),"innerDocs",d),y=(n,d)=>J(T.Struct((0,F.mapStringRecord)(n,a)),"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 y(e.value,e.innerDocs);if(e.type==="option")return T.Option(a(e.value));if(e.type==="result")return T.Result(a(e.value.ok),a(e.value.ko));let v=Object.values(e.value).map(n=>n.type==="primitive"?L._void:n.type==="tuple"&&n.value.length===1?a(n.value[0]):n.type==="tuple"?o(n.value,n.innerDocs):y(n.value,n.innerDocs)),h=Object.fromEntries(Object.keys(e.value).map((n,d)=>[n,v[d]])),f=Object.values(e.value).map(n=>n.idx),b=f.every((n,d)=>n===d)?T.Enum(h):T.Enum(h,f),c=(0,$.enhanceDecoder)(b,n=>{let d=e.innerDocs[n.value.type];return{...n,docs:d}});return c.shape=b.shape,c},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,u=new Map,r=s=>pe(i(s),u,new Set,t,a),i=R(t),a=L.AccountId,l=e.pallets.find(s=>s.name==="System")?.constants.find(s=>s.name==="SS58Prefix");if(l)try{let s=r(l.type)(l.value).value;typeof s=="number"&&(a=Y(s))}catch{}let o=ce(r),y=(0,$.createDecoder)(s=>{let b=$.u8.dec(s),c=e.pallets.find(g=>g.index===b);if(!c)throw new Error("Invalid Pallet");let n={value:{name:c.name,idx:b},input:ue(s[0])},d=r(c.calls),p=d(s);if(p.codec!=="Enum")throw null;let m={value:{name:p.value.type,idx:s[1]},input:ue(s[1]),docs:p.docs};return{pallet:n,call:m,args:{value:p.value.value,shape:d.shape}}}),v=ce((s,b=!1)=>s.type==="primitive"?b?He:L._void:s.type==="tuple"?T.Tuple(...Object.values(s.value).map(c=>r(c.id))):T.Struct((0,F.mapObject)(s.value,c=>r(c.id)))),h=s=>(b,c)=>{let n=e.pallets.find(m=>m.name===b),d=i(n[s]);if(d.type!=="enum")throw null;let p=d.value[c];return{location:[n.index,p.idx],view:v(p,s==="calls")}},f=(s,b)=>{let c=e.pallets.find(n=>n.name===s).constants.find(n=>n.name===b);return o(c.type)};return{buildDefinition:o,callDecoder:y,buildEvent:h("events"),buildError:h("errors"),buildCall:h("calls"),buildConstant:f}}; | ||
"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-8085034060d643c71d85df47784513b07a0a247c.1.0", | ||
"version": "0.0.1-8126ff956901484e2daff885f88145c307372713.1.0", | ||
"author": "Josep M Sobrepere (https://github.com/josepot)", | ||
@@ -43,4 +43,4 @@ "repository": { | ||
"dependencies": { | ||
"@polkadot-api/substrate-bindings": "0.0.1-8085034060d643c71d85df47784513b07a0a247c.1.0", | ||
"@polkadot-api/utils": "0.0.1-8085034060d643c71d85df47784513b07a0a247c.1.0" | ||
"@polkadot-api/substrate-bindings": "0.0.1-8126ff956901484e2daff885f88145c307372713.1.0", | ||
"@polkadot-api/utils": "0.0.1-8126ff956901484e2daff885f88145c307372713.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
342191
2917
+ Added@polkadot-api/substrate-bindings@0.0.1-8126ff956901484e2daff885f88145c307372713.1.0(transitive)
+ Added@polkadot-api/utils@0.0.1-8126ff956901484e2daff885f88145c307372713.1.0(transitive)
- Removed@polkadot-api/substrate-bindings@0.0.1-8085034060d643c71d85df47784513b07a0a247c.1.0(transitive)
- Removed@polkadot-api/utils@0.0.1-8085034060d643c71d85df47784513b07a0a247c.1.0(transitive)
Updated@polkadot-api/substrate-bindings@0.0.1-8126ff956901484e2daff885f88145c307372713.1.0
Updated@polkadot-api/utils@0.0.1-8126ff956901484e2daff885f88145c307372713.1.0