@polkadot-api/metadata-builders
Advanced tools
Comparing version 0.0.1-2f8cd6b33dbc501f595a518082ecb436f6b87c74.1.0 to 0.0.1-2fd415f1844f1ab7840350b883b06607be4b277b.1.0
import * as scale from '@polkadot-api/substrate-bindings'; | ||
import { StringRecord, V15, Codec, Decoder, HexString } 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 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; | ||
@@ -73,3 +73,3 @@ type CompactVar = { | ||
name: string; | ||
type: number | void | undefined; | ||
type: number | undefined; | ||
}[]; | ||
@@ -79,5 +79,5 @@ def: { | ||
value: { | ||
name: string | void | undefined; | ||
name: string | undefined; | ||
type: number; | ||
typeName: string | void | undefined; | ||
typeName: string | undefined; | ||
docs: string[]; | ||
@@ -90,5 +90,5 @@ }[]; | ||
fields: { | ||
name: string | void | undefined; | ||
name: string | undefined; | ||
type: number; | ||
typeName: string | void | undefined; | ||
typeName: string | undefined; | ||
docs: string[]; | ||
@@ -168,5 +168,2 @@ }[]; | ||
}; | ||
} | { | ||
tag: "historicMetaCompat"; | ||
value: string; | ||
}; | ||
@@ -176,35 +173,2 @@ 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>; | ||
enums: Map<string, string>; | ||
variables: Map<string, Variable>; | ||
} | ||
declare const getStaticBuilder: (metadata: V15, namespace: string) => { | ||
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) => { | ||
@@ -238,3 +202,3 @@ buildDefinition: (id: number) => Codec<any>; | ||
buildCall: (pallet: string, name: string) => { | ||
args: Codec<any>; | ||
codec: Codec<any>; | ||
location: [ | ||
@@ -257,2 +221,4 @@ number, | ||
buildConstant: (pallet: string, constantName: string) => string | null; | ||
buildComposite: (input: VoidVar | TupleVar | StructVar) => string | null; | ||
buildNamedTuple: (input: StructVar) => string | null; | ||
}; | ||
@@ -362,6 +328,3 @@ | ||
codec: "Result"; | ||
value: { | ||
ok: Decoded; | ||
ko: Decoded; | ||
}; | ||
value: ResultPayload<Decoded, Decoded>; | ||
}>; | ||
@@ -427,2 +390,2 @@ type TupleDecoded = WithInputAndPath<{ | ||
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 | ||
}); | ||
@@ -110,5 +108,10 @@ module.exports = __toCommonJS(src_exports); | ||
if (path.length === 1 && path[0] === "Option" && params.length === 1 && params[0].name === "T") { | ||
return { | ||
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: getLookupEntryDef(params[0].type) | ||
value | ||
}; | ||
@@ -164,13 +167,13 @@ } | ||
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 | ||
@@ -184,7 +187,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 | ||
@@ -207,9 +210,4 @@ }; | ||
} | ||
if (def.tag === "bitSequence") { | ||
return { type: "bitSequence" }; | ||
} | ||
const value = def.value; | ||
return { | ||
type: "primitive", | ||
value | ||
type: def.tag | ||
}; | ||
@@ -220,2 +218,5 @@ }); | ||
// src/dynamic-builder.ts | ||
var scale = __toESM(require("@polkadot-api/substrate-bindings")); | ||
// src/with-cache.ts | ||
@@ -240,358 +241,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}", | ||
historicMetaCompat: "any" | ||
}; | ||
var toCamelCase = (...parts) => parts[0] + parts.slice(1).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, namespace) => { | ||
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]; | ||
const parts = path.length === 0 ? ["cdc" + idx] : path[0] === "sp_runtime" ? [namespace, path.slice(-1)[0]] : [namespace, ...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"); | ||
@@ -710,2 +356,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( | ||
@@ -732,13 +380,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) => { | ||
@@ -759,3 +396,3 @@ const entry = metadata.apis.find((x) => x.name === api)?.methods.find((x) => x.name === method); | ||
buildRuntimeCall, | ||
buildCall, | ||
buildCall: buildVariant("calls"), | ||
buildConstant, | ||
@@ -770,66 +407,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") | ||
@@ -840,25 +545,153 @@ return buildTuple(input.value); | ||
if (input.type === "option") | ||
return getChecksum([buildNextChecksum(input.value)], "Option()"); | ||
return getChecksum([shapeIds.option, buildNextChecksum(input.value)]); | ||
if (input.type === "result") | ||
return getChecksum( | ||
[input.value.ok, input.value.ko].map(buildNextChecksum), | ||
"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); | ||
} | ||
}); | ||
}; | ||
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)) | ||
); | ||
if (input.type === "AccountId32") { | ||
return getChecksum([primitiveChecksums.u8, 32n], "AccountId32"); | ||
dependents.forEach((group2) => dependentsFirst(group2)); | ||
if (result.includes(group)) | ||
return; | ||
result.push(group); | ||
} | ||
const dependencies = Object.values(input.value).map((v) => { | ||
if (v.type === "primitive") | ||
return 0n; | ||
return v.type === "tuple" ? buildTuple(v.value) : buildStruct(v.value); | ||
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) | ||
); | ||
} | ||
}); | ||
const keys = Object.keys(input.value); | ||
keys.push("Enum"); | ||
return getChecksum(dependencies, JSON.stringify({ Enum: keys })); | ||
return recursiveBuildChecksum(entry, (id, value) => cache.set(id, value)); | ||
}; | ||
var buildChecksum = withCache( | ||
_buildChecksum, | ||
() => 0n, | ||
(result) => result | ||
); | ||
var getChecksumBuilder = (metadata) => { | ||
@@ -868,3 +701,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) => { | ||
@@ -874,6 +707,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]); | ||
@@ -889,7 +722,10 @@ } catch (_) { | ||
throw null; | ||
const args = getChecksum( | ||
entry.inputs.map((x) => buildDefinition(x.type)), | ||
`(${entry.inputs.map((x) => x.name).join(",")})` | ||
const argNamesChecksum = getStringChecksum( | ||
entry.inputs.map((x) => x.name) | ||
); | ||
return getChecksum([args, buildDefinition(entry.output)]); | ||
const argValuesChecksum = getChecksum( | ||
entry.inputs.map((x) => buildDefinition(x.type)) | ||
); | ||
const outputChecksum = buildDefinition(entry.output); | ||
return getChecksum([argNamesChecksum, argValuesChecksum, outputChecksum]); | ||
} catch (_) { | ||
@@ -899,8 +735,24 @@ return null; | ||
}; | ||
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 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) => { | ||
@@ -914,3 +766,3 @@ try { | ||
throw null; | ||
return buildEnumEntry(callsLookup.value[name]); | ||
return buildComposite(callsLookup.value[name]); | ||
} catch (_) { | ||
@@ -936,3 +788,5 @@ return null; | ||
buildError: toStringEnhancer(buildVariant("errors")), | ||
buildConstant: toStringEnhancer(buildConstant) | ||
buildConstant: toStringEnhancer(buildConstant), | ||
buildComposite: toStringEnhancer(buildComposite), | ||
buildNamedTuple: toStringEnhancer(buildNamedTuple) | ||
}; | ||
@@ -939,0 +793,0 @@ }; |
import * as scale from '@polkadot-api/substrate-bindings'; | ||
import { StringRecord, V15, Codec, Decoder, HexString } 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 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; | ||
@@ -73,3 +73,3 @@ type CompactVar = { | ||
name: string; | ||
type: number | void | undefined; | ||
type: number | undefined; | ||
}[]; | ||
@@ -79,5 +79,5 @@ def: { | ||
value: { | ||
name: string | void | undefined; | ||
name: string | undefined; | ||
type: number; | ||
typeName: string | void | undefined; | ||
typeName: string | undefined; | ||
docs: string[]; | ||
@@ -90,5 +90,5 @@ }[]; | ||
fields: { | ||
name: string | void | undefined; | ||
name: string | undefined; | ||
type: number; | ||
typeName: string | void | undefined; | ||
typeName: string | undefined; | ||
docs: string[]; | ||
@@ -168,5 +168,2 @@ }[]; | ||
}; | ||
} | { | ||
tag: "historicMetaCompat"; | ||
value: string; | ||
}; | ||
@@ -176,35 +173,2 @@ 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>; | ||
enums: Map<string, string>; | ||
variables: Map<string, Variable>; | ||
} | ||
declare const getStaticBuilder: (metadata: V15, namespace: string) => { | ||
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) => { | ||
@@ -238,3 +202,3 @@ buildDefinition: (id: number) => Codec<any>; | ||
buildCall: (pallet: string, name: string) => { | ||
args: Codec<any>; | ||
codec: Codec<any>; | ||
location: [ | ||
@@ -257,2 +221,4 @@ number, | ||
buildConstant: (pallet: string, constantName: string) => string | null; | ||
buildComposite: (input: VoidVar | TupleVar | StructVar) => string | null; | ||
buildNamedTuple: (input: StructVar) => string | null; | ||
}; | ||
@@ -362,6 +328,3 @@ | ||
codec: "Result"; | ||
value: { | ||
ok: Decoded; | ||
ko: Decoded; | ||
}; | ||
value: ResultPayload<Decoded, Decoded>; | ||
}>; | ||
@@ -427,2 +390,2 @@ type TupleDecoded = WithInputAndPath<{ | ||
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 ue=Object.create;var _=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty;var ye=(e,o)=>{for(var i in o)_(e,i,{get:o[i],enumerable:!0})},z=(e,o,i,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let u of de(o))!me.call(e,u)&&u!==i&&_(e,u,{get:()=>o[u],enumerable:!(r=pe(o,u))||r.enumerable});return e};var Q=(e,o,i)=>(i=e!=null?ue(le(e)):{},z(o||!e||!e.__esModule?_(i,"default",{value:e,enumerable:!0}):i,e)),ve=e=>z(_({},"__esModule",{value:!0}),e);var We={};ye(We,{getChecksumBuilder:()=>ke,getDynamicBuilder:()=>fe,getLookupFn:()=>P,getStaticBuilder:()=>be,getViewBuilder:()=>ce,primitiveTypes:()=>N});module.exports=ve(We);var q={type:"primitive",value:"_void"},P=e=>{let o=new Map,i=new Set,r=b=>a=>{let h=o.get(a);if(h)return h;if(i.has(a)){let D={id:a};return o.set(a,D),D}i.add(a);let m=b(a);return h=o.get(a),h?Object.assign(h,m):(h={id:a,...m},o.set(a,h)),i.delete(a),h},u=!0,c=r(b=>{let{def:a,path:h,params:m}=e[b];if(a.tag==="composite"){if(a.value.length===0)return q;if(a.value.length===1)return u&&h.join(",")==="sp_core,crypto,AccountId32"?(u=!1,{type:"AccountId32"}):c(a.value[0].type);let v=!0,s={},d={};return a.value.forEach((n,t)=>{v=v&&!!n.name;let p=n.name||t;s[p]=c(n.type),d[p]=n.docs}),v?{type:"struct",value:s,innerDocs:d}:{type:"tuple",value:Object.values(s),innerDocs:Object.values(d)}}if(a.tag==="variant"){if(h.length===1&&h[0]==="Option"&&m.length===1&&m[0].name==="T")return{type:"option",value:c(m[0].type)};if(h.length===1&&h[0]==="Result"&&m.length===2&&m[0].name==="T"&&m[1].name==="E")return{type:"result",value:{ok:c(m[0].type),ko:c(m[1].type)}};if(a.value.length===0)return q;let v={},s={};return a.value.forEach(d=>{let n=d.name;if(s[n]=d.docs,d.fields.length===0){v[n]={...q,idx:d.index};return}let t=!0,p={},y={};d.fields.forEach((l,g)=>{t=t&&!!l.name;let f=l.name||g;p[f]=c(l.type),y[f]=l.docs}),v[n]=t?{type:"struct",value:p,innerDocs:y,idx:d.index}:{type:"tuple",value:Object.values(p),innerDocs:Object.values(y),idx:d.index}}),{type:"enum",value:v,innerDocs:s}}if(a.tag==="sequence")return{type:"sequence",value:c(a.value)};if(a.tag==="array")return{type:"array",value:c(a.value.type),len:a.value.len};if(a.tag==="tuple"){if(a.value.length===0)return q;if(a.value.length===1)return c(a.value[0]);let v=a.value.map(d=>c(d)),s=a.value.map(d=>e[d].docs);return{type:"tuple",value:v,innerDocs:s}}if(a.tag==="primitive")return{type:"primitive",value:a.value.tag};if(a.tag==="compact"){let v=c(a.value);return{type:"compact",isBig:Number(v.value.slice(1))>32}}return a.tag==="bitSequence"?{type:"bitSequence"}:{type:"primitive",value:a.value}});return c};var L=(e,o,i)=>(r,u,c,...b)=>{let{id:a}=r;if(u.has(a))return u.get(a);if(c.has(a)){let m=o(()=>u.get(a),r,...b);return u.set(a,m),m}c.add(a);let h=e(r,u,c,...b);return c.delete(a),u.has(a)&&(h=i(h,u.get(a),r,...b)),u.set(a,h),h};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}",historicMetaCompat:"any"},F=(...e)=>e[0]+e.slice(1).map(o=>o[0].toUpperCase()+o.slice(1)).join(""),A=e=>N[e]??e,he=(e,o,i,r,u)=>{if(e.type==="primitive")return r.imports.add(e.value),e.value;if(e.type==="AccountId32"){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}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("Bin"),r.typeImports.add("HexString"),r.typeImports.add("Binary");let n={id:"_bytesSeq",value:"Bin()",types:"Binary",directDependencies:new Set};return r.variables.has(n.id)||r.variables.set(n.id,n),n.id}if(r.variables.has(u(e.id,"circular")))return u(e.id,"circular");if(r.variables.has(u(e.id)))return u(e.id);let c=n=>X(n,o,i,r,u),b=(n,t,p)=>{r.imports.add("Vector");let y=c(t),g={id:n,value:`Vector(${(p?[y,p]:[y]).join(", ")})`,types:`Array<${A(y)}>`,directDependencies:new Set([y])};return r.variables.set(n,g),n},a=(n,t)=>{r.imports.add("Tuple");let p=t.map(c),y={id:n,value:`Tuple(${p.join(", ")})`,types:`[${p.map(A).join(", ")}]`,directDependencies:new Set(p)};return r.variables.set(n,y),n},h=(n,t)=>{r.imports.add("Struct");let p=Object.values(t).map(c),y={id:n,value:`Struct({${Object.keys(t).map((l,g)=>`${l}: ${p[g]}`).join(", ")}})`,types:`{${Object.keys(t).map((l,g)=>`${l}: ${A(p[g])}`).join(", ")}}`,directDependencies:new Set(p)};return r.variables.set(n,y),n},m=u(e.id);if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?(r.imports.add("Bin"),r.variables.set(m,{id:m,value:`Bin(${e.len})`,types:"Binary",directDependencies:new Set}),r.typeImports.add("HexString"),r.typeImports.add("Binary"),m):b(m,e.value,e.len);if(e.type==="sequence")return b(m,e.value);if(e.type==="tuple")return a(m,e.value);if(e.type==="struct")return h(m,e.value);if(e.type==="option"){r.imports.add("Option");let n=c(e.value),t=`_Option_${n}`,p={id:t,value:`Option(${n})`,types:`${A(n)} | undefined`,directDependencies:new Set([n])};return r.variables.set(t,p),t}if(e.type==="result"){r.imports.add("Result"),r.typeImports.add("ResultPayload");let n=c(e.value.ok),t=c(e.value.ko),p=`_Result_${n}_${t}`,y={id:p,value:`Result(${n}, ${t})`,types:`ResultPayload<${A(n)}, ${A(t)}>`,directDependencies:new Set([n,t])};return r.variables.set(p,y),p}r.imports.add("Variant"),r.typeImports.add("Enum");let D=Object.entries(e.value).map(([n,t])=>{if(t.type==="primitive")return r.imports.add(t.value),t.value;let p=F(m,n);if(t.type==="tuple"){if(t.value.length===1){let y=c(t.value[0]);return r.variables.has(p)||r.variables.set(p,{id:p,value:y,types:A(y),directDependencies:new Set([y])}),p}return a(p,t.value)}else h(p,t.value);return p}),v=Object.values(e.value).map(n=>n.idx),s=v.every((n,t)=>n===t),d=`{${Object.keys(e.value).map((n,t)=>`${n}: ${D[t]}`)}}${s?"":`, [${v.join(", ")}]`}`;return r.enums.set(m,Object.keys(e.value).map((n,t)=>`{type: '${n}', value: ${A(D[t])}}`).join(" | ")),r.variables.set(m,{id:m,value:`Variant(${d})`,types:`Enum<E${m}>`,directDependencies:new Set(D)}),m},X=L(he,(e,o,i,r)=>{i.imports.add("Self");let u=r(o.id),c={id:r(o.id,"circular"),types:u,value:`Self(() => ${u})`,directDependencies:new Set([u])};return i.variables.set(c.id,c),c.id},e=>e),be=(e,o)=>{let i={imports:new Set,typeImports:new Set(["Codec"]),variables:new Map,enums:new Map},r=e.lookup,u=P(r),c=(l,...g)=>{let{path:f}=r[l],E=f.length===0?["cdc"+l]:f[0]==="sp_runtime"?[o,f.slice(-1)[0]]:[o,...f];return E.push(...g),F(...E)},b=new Map,a=l=>X(u(l),b,new Set,i,c),h=(l,g)=>{if(i.variables.has(g))return g;let f=l.map(V=>V.type).map(a),E=l.map(V=>V.name);i.imports.add("Tuple");let T={id:g,types:`[${E.map((V,w)=>`${V[0].toUpperCase()+V.slice(1)}: ${A(f[w])}`).join(", ")}]`,value:`Tuple(${f.join(", ")})`,directDependencies:new Set(f)};return i.variables.set(g,T),g},m="_emptyTuple",D=()=>(i.variables.has(m)||(i.imports.add("Tuple"),i.variables.set(m,{id:m,types:"[]",value:"Tuple()",directDependencies:new Set})),m),v=(l,g)=>{let f=e.pallets.find(I=>I.name===l).storage.items.find(I=>I.name===g);if(f.type.tag==="plain")return{key:D(),val:a(f.type.value)};let{key:E,value:T}=f.type.value,V=a(T);return{key:f.type.value.hashers.length===1?h([{name:"key",type:E}],c(E,"Tupled")):a(E),val:V}},s=(l,g)=>{let f=e.apis.find(E=>E.name===l)?.methods.find(E=>E.name===g);if(!f)throw null;return{args:h(f.inputs,`${l}${g}Args`),value:a(f.output)}},d=l=>(g,f)=>{let E=u(e.pallets.find(V=>V.name===g)[l]);if(E.type!=="enum")throw null;let T=F(a(E.id),f);return!i.variables.has(T)&&E.value[f].type==="primitive"&&i.variables.set(T,{id:T,value:"_void",types:"undefined",directDependencies:new Set}),T},n=(l,g)=>{let f=e.pallets.find(E=>E.name===l).constants.find(E=>E.name===g);return a(f.type)},t=()=>{let l=`import type {${[...i.typeImports].join(", ")}} from "@polkadot-api/client"; | ||
`,g=`import {${[...i.imports].join(", ")}} from "@polkadot-api/substrate-bindings"; | ||
`,f=[...i.variables.values()].map(E=>`${i.enums.has(E.id)?`type E${E.id} = ${i.enums.get(E.id)}; | ||
export `:""}type ${E.id} = ${E.types}; | ||
const ${E.id}: Codec<${E.id}> = ${E.value};`).join(` | ||
`);return`${l}${g}${f}`},p=()=>[...i.enums.keys()],y=l=>N[l]??i.variables.get(l)?.types??l;return{buildDefinition:a,buildStorage:v,buildEvent:d("events"),buildError:d("errors"),buildCall:d("calls"),buildRuntimeCall:s,buildConstant:n,getTypeFromVarName:y,getCode:t,getEnums:p}};var S=Q(require("@polkadot-api/substrate-bindings"));var Z=require("@polkadot-api/utils"),ge=S.Bin(),Se=(e,o,i,r)=>{if(e.type==="primitive")return S[e.value];if(e.type==="AccountId32")return r;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 ge;let u=s=>ee(s,o,i,r),c=(s,d)=>{let n=u(s);return d?S.Vector(n,d):S.Vector(n)},b=s=>S.Tuple(...s.map(u)),a=s=>{let d=Object.fromEntries(Object.entries(s).map(([n,t])=>[n,u(t)]));return S.Struct(d)};if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?S.Bin(e.len):c(e.value,e.len);if(e.type==="sequence")return c(e.value);if(e.type==="tuple")return b(e.value);if(e.type==="struct")return a(e.value);if(e.type==="option")return S.Option(u(e.value));if(e.type==="result")return S.Result(u(e.value.ok),u(e.value.ko));let h=Object.values(e.value).map(s=>s.type==="primitive"?S._void:s.type==="tuple"&&s.value.length===1?u(s.value[0]):s.type==="tuple"?b(s.value):a(s.value)),m=Object.fromEntries(Object.keys(e.value).map((s,d)=>[s,h[d]])),D=Object.values(e.value).map(s=>s.idx);return D.every((s,d)=>s===d)?S.Variant(m):S.Variant(m,D)},ee=L(Se,S.Self,e=>e),fe=e=>{let o=e.lookup,i=P(o),r=S.AccountId(),u=new Map,c=t=>ee(i(t),u,new Set,r),b=e.pallets.find(t=>t.name==="System")?.constants.find(t=>t.name==="SS58Prefix"),a;if(b)try{let t=c(b.type).dec(b.value);typeof t=="number"&&(a=t,r=S.AccountId(t))}catch{}let h=new Map,m=(t,p)=>{let y=h.get(t);y||h.set(t,y=S.Storage(t));let l=e.pallets.find(R=>R.name===t).storage.items.find(R=>R.name===p),g=(R,...U)=>{let Y=y(...U);return{...Y,len:R,fallback:l.modifier===1?Y.dec(l.fallback):void 0}};if(l.type.tag==="plain")return g(0,p,c(l.type.value).dec);let{key:f,value:E,hashers:T}=l.type.value,V=c(E),w=T.map(R=>S[R.tag]),I=w.length===1?[[c(f),w[0]]]:i(f).value.map((R,U)=>[c(R.id),w[U]]);return g(w.length,p,V.dec,...I)},D=t=>t.type==="primitive"?S._void:t.type==="tuple"?S.Tuple(...Object.values(t.value).map(p=>c(p.id))):S.Struct((0,Z.mapObject)(t.value,p=>c(p.id))),v=(t,p)=>{let y=e.pallets.find(l=>l.name===t).constants.find(l=>l.name===p);return c(y.type)},s=t=>(p,y)=>{let l=e.pallets.find(E=>E.name===p),g=i(l[t]);if(g.type!=="enum")throw null;let f=g.value[y];return{location:[l.index,f.idx],codec:D(g.value[y])}},d=(t,p)=>{let y=e.pallets.find(f=>f.name===t),l=i(y.calls);if(l.type!=="enum")throw null;let g=l.value[p];return{location:[y.index,g.idx],args:D(l.value[p])}},n=(t,p)=>{let y=e.apis.find(l=>l.name===t)?.methods.find(l=>l.name===p);if(!y)throw null;return{args:S.Tuple(...y.inputs.map(l=>c(l.type))),value:c(y.output)}};return{buildDefinition:c,buildStorage:m,buildEvent:s("events"),buildError:s("errors"),buildRuntimeCall:n,buildCall:d,buildConstant:v,ss58Prefix:a}};var K=require("@polkadot-api/substrate-bindings");var te=new TextEncoder,De=te.encode.bind(te),k=(e,o)=>{let i=typeof o=="string",r=new Uint8Array((e.length+(i?1:0))*8),u=new DataView(r.buffer),c=0;i&&(u.setBigUint64(c,(0,K.h64)(De(o))),c+=8);for(let b=0;b<e.length;b++,c+=8)u.setBigUint64(c,e[b]);return(0,K.h64)(r)},W={_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},Ee=14n,xe=(e,o,i)=>{if(o.has(e.id))return o.get(e.id);if(e.type==="primitive")return W[e.value];if(e.type==="compact")return W[e.isBig?"compactb":"compacts"];if(e.type==="bitSequence")return W.bitSequence;if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return Ee;let r=m=>re(m,o,i),u=(m,D)=>{let v=r(m);return D?k([v,BigInt(D)],"Vector(,)"):k([v],"Vector()")},c=m=>k(m.map(r)),b=m=>k(Object.values(m).map(r),JSON.stringify(Object.keys(m)));if(e.type==="array")return u(e.value,e.len);if(e.type==="sequence")return u(e.value);if(e.type==="tuple")return c(e.value);if(e.type==="struct")return b(e.value);if(e.type==="option")return k([r(e.value)],"Option()");if(e.type==="result")return k([e.value.ok,e.value.ko].map(r),"Result()");if(e.type==="AccountId32")return k([W.u8,32n],"AccountId32");let a=Object.values(e.value).map(m=>m.type==="primitive"?0n:m.type==="tuple"?c(m.value):b(m.value)),h=Object.keys(e.value);return h.push("Enum"),k(a,JSON.stringify({Enum:h}))},re=L(xe,()=>0n,e=>e),ke=e=>{let o=e.lookup,i=P(o),r=new Map,u=v=>re(i(v),r,new Set),c=(v,s)=>{try{let d=e.pallets.find(l=>l.name===v).storage.items.find(l=>l.name===s);if(d.type.tag==="plain")return k([u(d.type.value)]);let{key:n,value:t}=d.type.value,p=u(t),y=d.type.value.hashers.length===1?k([u(n)]):u(n);return k([p,y])}catch{return null}},b=(v,s)=>{try{let d=e.apis.find(t=>t.name===v)?.methods.find(t=>t.name===s);if(!d)throw null;let n=k(d.inputs.map(t=>u(t.type)),`(${d.inputs.map(t=>t.name).join(",")})`);return k([n,u(d.output)])}catch{return null}},a=v=>{if(v.type==="primitive")return 0n;let s=Object.values(v.value).map(d=>u(d.id));return v.type==="tuple"?k(s):k(s,JSON.stringify(Object.keys(v.value)))},h=v=>(s,d)=>{try{let n=e.pallets.find(p=>p.name===s),t=i(n[v]);if(t.type!=="enum")throw null;return a(t.value[d])}catch{return null}},m=(v,s)=>{try{let d=e.pallets.find(n=>n.name===v).constants.find(n=>n.name===s);return u(d.type)}catch{return null}},D=v=>(...s)=>v(...s)?.toString(32)??null;return{buildDefinition:D(u),buildRuntimeCall:D(b),buildStorage:D(c),buildCall:D(h("calls")),buildEvent:D(h("events")),buildError:D(h("errors")),buildConstant:D(m)}};var H=require("@polkadot-api/utils"),j=require("@polkadot-api/substrate-bindings");var B=require("@polkadot-api/utils"),x=Q(require("@polkadot-api/substrate-bindings")),Ve=B.toHex,ne=(e,o)=>x.createDecoder(i=>{let r=i,u=r.i,c=e(r),b=Ve(new Uint8Array(r.buffer.slice(u,r.i)));return{...o,value:c,input:b}}),M=(e,o,i)=>{let r=ne(o,{codec:e,...i});return Object.assign(r,{shape:{codec:e}})},$=(e,o,i)=>{let r=ne(o,{codec:e.codec,...i});return Object.assign(r,{shape:e})},G=(e=42)=>{let o=x.enhanceDecoder(x.AccountId(e).dec,i=>({address:i,ss58Prefix:e}));return M("AccountId",o,{})},Ce=e=>M("BytesArray",x.Hex.dec(e),{len:e}),Te=["_void","bool","char","str","u8","u16","u32","i8","i16","i32","u64","u128","u256","i64","i128","i256","compactNumber","compactBn","bitSequence"],Oe=Object.fromEntries(Te.map(e=>[e,M(e,x[e].dec)])),O={...Oe,Bytes:M("Bytes",x.Hex.dec()),BytesArray:Ce,AccountId:G()},Re=e=>$({codec:"Sequence",shape:e.shape},x.Vector.dec(e)),Pe=(e,o)=>$({codec:"Array",shape:e.shape,len:o},x.Vector.dec(e,o)),Ae=(...e)=>$({codec:"Tuple",shape:e.map(o=>o.shape)},x.Tuple.dec(...e)),Le=e=>$({codec:"Struct",shape:(0,B.mapStringRecord)(e,o=>o.shape)},x.Struct.dec(e)),we=(e,o)=>$({codec:"Enum",shape:(0,B.mapStringRecord)(e,i=>i.shape)},x.Variant.dec(e,o)),$e=e=>$({codec:"Option",shape:e.shape},x.Option.dec(e)),je=(e,o)=>$({codec:"Result",shape:{ok:e.shape,ko:o.shape}},x.Result.dec(e,o)),oe=e=>{let o=r=>{let u=e(),c=u;return o=u,c(r)},i=r=>o(r);return i.shape={codec:"_void"},i},C={Sequence:Re,Array:Pe,Tuple:Ae,Struct:Le,Enum:we,Option:$e,Result:je};var Ie=C.Tuple(),ae=e=>(...o)=>{let i=e(...o);return{shape:i.shape,decoder:i}},J=(e,o,i)=>{let r=(0,j.enhanceDecoder)(e,u=>({...u,[o]:i}));return r.shape=e.shape,r},Be=e=>(o,i,r,u,...c)=>{let{path:b}=u[o.id],a=e(o,i,r,u,...c);return b.length?J(a,"path",b):a},_e=(e,o,i,r,u)=>{if(e.type==="primitive")return O[e.value];if(e.type==="AccountId32")return u;if(e.type==="compact")return e.isBig?O.compactBn:O.compactNumber;if(e.type==="bitSequence")return O.bitSequence;if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return O.Bytes;let c=t=>ie(t,o,i,r,u),b=(t,p)=>{let y=c(t);return p?C.Array(y,p):C.Sequence(y)},a=(t,p)=>J(C.Tuple(...t.map(c)),"innerDocs",p),h=(t,p)=>J(C.Struct((0,H.mapStringRecord)(t,c)),"innerDocs",p);if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?O.BytesArray(e.len):b(e.value,e.len);if(e.type==="sequence")return b(e.value);if(e.type==="tuple")return a(e.value,e.innerDocs);if(e.type==="struct")return h(e.value,e.innerDocs);if(e.type==="option")return C.Option(c(e.value));if(e.type==="result")return C.Result(c(e.value.ok),c(e.value.ko));let m=Object.values(e.value).map(t=>t.type==="primitive"?O._void:t.type==="tuple"&&t.value.length===1?c(t.value[0]):t.type==="tuple"?a(t.value,t.innerDocs):h(t.value,t.innerDocs)),D=Object.fromEntries(Object.keys(e.value).map((t,p)=>[t,m[p]])),v=Object.values(e.value).map(t=>t.idx),d=v.every((t,p)=>t===p)?C.Enum(D):C.Enum(D,v),n=(0,j.enhanceDecoder)(d,t=>{let p=e.innerDocs[t.value.type];return{...t,docs:p}});return n.shape=d.shape,n},qe=Be(_e),ie=L(qe,oe,(e,o)=>(o.shape=e.shape,e)),se=e=>`0x${e.toString(16).padEnd(2,"0")}`,ce=e=>{let o=e.lookup,i=new Map,r=s=>ie(u(s),i,new Set,o,c),u=P(o),c=O.AccountId,b=e.pallets.find(s=>s.name==="System")?.constants.find(s=>s.name==="SS58Prefix");if(b)try{let s=r(b.type)(b.value).value;typeof s=="number"&&(c=G(s))}catch{}let a=ae(r),h=(0,j.createDecoder)(s=>{let d=j.u8.dec(s),n=e.pallets.find(g=>g.index===d);if(!n)throw new Error("Invalid Pallet");let t={value:{name:n.name,idx:d},input:se(s[0])},p=r(n.calls),y=p(s);if(y.codec!=="Enum")throw null;let l={value:{name:y.value.type,idx:s[1]},input:se(s[1]),docs:y.docs};return{pallet:t,call:l,args:{value:y.value.value,shape:p.shape}}}),m=ae((s,d=!1)=>s.type==="primitive"?d?Ie:O._void:s.type==="tuple"?C.Tuple(...Object.values(s.value).map(n=>r(n.id))):C.Struct((0,H.mapObject)(s.value,n=>r(n.id)))),D=s=>(d,n)=>{let t=e.pallets.find(l=>l.name===d),p=u(t[s]);if(p.type!=="enum")throw null;let y=p.value[n];return{location:[t.index,y.idx],view:m(y,s==="calls")}},v=(s,d)=>{let n=e.pallets.find(t=>t.name===s).constants.find(t=>t.name===d);return a(n.type)};return{buildDefinition:a,callDecoder:h,buildEvent:D("events"),buildError:D("errors"),buildCall:D("calls"),buildConstant:v}}; | ||
"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-2f8cd6b33dbc501f595a518082ecb436f6b87c74.1.0", | ||
"version": "0.0.1-2fd415f1844f1ab7840350b883b06607be4b277b.1.0", | ||
"author": "Josep M Sobrepere (https://github.com/josepot)", | ||
@@ -43,4 +43,4 @@ "repository": { | ||
"dependencies": { | ||
"@polkadot-api/substrate-bindings": "0.0.1-2f8cd6b33dbc501f595a518082ecb436f6b87c74.1.0", | ||
"@polkadot-api/utils": "0.0.1-2f8cd6b33dbc501f595a518082ecb436f6b87c74.1.0" | ||
"@polkadot-api/substrate-bindings": "0.0.1-2fd415f1844f1ab7840350b883b06607be4b277b.1.0", | ||
"@polkadot-api/utils": "0.0.1-2fd415f1844f1ab7840350b883b06607be4b277b.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
342191
2917
+ Added@polkadot-api/substrate-bindings@0.0.1-2fd415f1844f1ab7840350b883b06607be4b277b.1.0(transitive)
+ Added@polkadot-api/utils@0.0.1-2fd415f1844f1ab7840350b883b06607be4b277b.1.0(transitive)
- Removed@polkadot-api/substrate-bindings@0.0.1-2f8cd6b33dbc501f595a518082ecb436f6b87c74.1.0(transitive)
- Removed@polkadot-api/utils@0.0.1-2f8cd6b33dbc501f595a518082ecb436f6b87c74.1.0(transitive)
Updated@polkadot-api/substrate-bindings@0.0.1-2fd415f1844f1ab7840350b883b06607be4b277b.1.0
Updated@polkadot-api/utils@0.0.1-2fd415f1844f1ab7840350b883b06607be4b277b.1.0