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

@polkadot-api/metadata-builders

Package Overview
Dependencies
Maintainers
2
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 0.0.1-f000825b6d9815197ad6ec30ca3d96ef36aa4e8c.1.0 to 0.0.1-f396f3bae7aa63a344f7191da9837b2835286f75.1.0

20

dist/index.d.ts

@@ -207,3 +207,4 @@ import * as scale from '@polkadot-api/substrate-bindings';

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

@@ -213,3 +214,2 @@ number,

];
args: Codec<any>;
};

@@ -223,3 +223,3 @@ buildConstant: (pallet: string, constantName: string) => Codec<any>;

buildStorage: (pallet: string, entry: string) => string | null;
buildCall: (pallet: string, callName: string) => string | null;
buildCall: (pallet: string, name: string) => string | null;
buildEvent: (pallet: string, name: string) => string | null;

@@ -230,2 +230,10 @@ buildError: (pallet: string, name: string) => string | null;

type UnshapedDecoder = {
shape: Shape;
decoder: Decoder<Decoded>;
};
type VariantBasedBuild = (pallet: string, name: string) => {
view: UnshapedDecoder;
location: [number, number];
};
type GetViewBuilder = (metadata: V14) => {

@@ -237,2 +245,6 @@ buildDefinition: (idx: number) => {

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

@@ -364,2 +376,2 @@ interface DecodedCall {

export { type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CodeDeclarations, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives$1 as MetadataPrimitives, type NumberDecoded, type PrimitiveDecoded, type PrimitiveVar, type SequenceDecoded, type SequenceShape, type SequenceVar, type Shape, type StringDecoded, type StructDecoded, type StructShape, type StructVar, type TerminalVar, type TupleDecoded, type TupleShape, type TupleVar, type Var, type Variable, type VoidDecoded, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn, getStaticBuilder, getViewBuilder, primitiveTypes };
export { type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CodeDeclarations, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives$1 as MetadataPrimitives, type NumberDecoded, type PrimitiveDecoded, type PrimitiveVar, type SequenceDecoded, type SequenceShape, type SequenceVar, type Shape, type StringDecoded, type StructDecoded, type StructShape, type StructVar, type TerminalVar, type TupleDecoded, type TupleShape, type TupleVar, type UnshapedDecoder, type Var, type Variable, type VoidDecoded, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn, getStaticBuilder, getViewBuilder, primitiveTypes };

119

dist/index.js

@@ -540,2 +540,3 @@ "use strict";

var scale = __toESM(require("@polkadot-api/substrate-bindings"));
var import_utils = require("@polkadot-api/utils");
var _bytes = scale.Bin();

@@ -644,16 +645,10 @@ var isBytes2 = (input) => input.type === "primitive" && input.value === "u8";

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

@@ -669,8 +664,19 @@ const buildConstant = (pallet, constantName) => {

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

@@ -797,13 +803,2 @@ buildDefinition,

};
const buildCall = (pallet, callName) => {
try {
const palletEntry = metadata.pallets.find((x) => x.name === pallet);
const callsLookup = getLookupEntryDef(palletEntry.calls);
if (callsLookup.type !== "enum")
throw null;
return buildEnumEntry(callsLookup.value[callName]);
} catch (_) {
return null;
}
};
const buildVariant = (variantType) => (pallet, name) => {

@@ -834,3 +829,3 @@ try {

buildStorage: toStringEnhancer(buildStorage),
buildCall: toStringEnhancer(buildCall),
buildCall: toStringEnhancer(buildVariant("calls")),
buildEvent: toStringEnhancer(buildVariant("events")),

@@ -843,9 +838,9 @@ buildError: toStringEnhancer(buildVariant("errors")),

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

@@ -924,7 +919,7 @@ const bytes = _bytes2;

var StructDec = (input) => complexShapedDecoder(
{ codec: "Struct", shape: (0, import_utils.mapStringRecord)(input, (x) => x.shape) },
{ codec: "Struct", shape: (0, import_utils2.mapStringRecord)(input, (x) => x.shape) },
scale2.Struct.dec(input)
);
var EnumDec = (input, args) => complexShapedDecoder(
{ codec: "Enum", shape: (0, import_utils.mapStringRecord)(input, (x) => x.shape) },
{ codec: "Enum", shape: (0, import_utils2.mapStringRecord)(input, (x) => x.shape) },
scale2.Enum.dec(input, args)

@@ -952,2 +947,10 @@ );

// src/view-builder/view-builder.ts
var emptyTuple2 = complex.Tuple();
var toUnshapedDecoder = (fn) => (...args) => {
const value = fn(...args);
return {
shape: value.shape,
decoder: value
};
};
var withProp = (input, propName, propValue) => {

@@ -983,3 +986,3 @@ const decoder = (0, import_substrate_bindings2.enhanceDecoder)(input, (x) => ({

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

@@ -1051,9 +1054,3 @@ innerDocs

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

@@ -1089,4 +1086,40 @@ const palletIdx = import_substrate_bindings2.u8.dec(bytes);

});
return { buildDefinition, callDecoder };
const buildEnumEntry = toUnshapedDecoder(
(entry, forceTuple = false) => {
if (entry.type === "primitive")
return forceTuple ? emptyTuple2 : primitives._void;
return entry.type === "tuple" ? complex.Tuple(
...Object.values(entry.value).map((l) => getDecoder(l.id))
) : complex.Struct(
(0, import_utils3.mapObject)(
entry.value,
(x) => getDecoder(x.id)
)
);
}
);
const buildVariant = (type) => (pallet, name) => {
const palletEntry = metadata.pallets.find((x) => x.name === pallet);
const lookup = getLookupEntryDef(palletEntry[type]);
if (lookup.type !== "enum")
throw null;
const event = lookup.value[name];
return {
location: [palletEntry.index, event.idx],
view: buildEnumEntry(event, type === "calls")
};
};
const buildConstant = (pallet, constantName) => {
const storageEntry = metadata.pallets.find((x) => x.name === pallet).constants.find((s) => s.name === constantName);
return buildDefinition(storageEntry.type);
};
return {
buildDefinition,
callDecoder,
buildEvent: buildVariant("events"),
buildError: buildVariant("errors"),
buildCall: buildVariant("calls"),
buildConstant
};
};
//# sourceMappingURL=index.js.map

@@ -207,3 +207,4 @@ import * as scale from '@polkadot-api/substrate-bindings';

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

@@ -213,3 +214,2 @@ number,

];
args: Codec<any>;
};

@@ -223,3 +223,3 @@ buildConstant: (pallet: string, constantName: string) => Codec<any>;

buildStorage: (pallet: string, entry: string) => string | null;
buildCall: (pallet: string, callName: string) => string | null;
buildCall: (pallet: string, name: string) => string | null;
buildEvent: (pallet: string, name: string) => string | null;

@@ -230,2 +230,10 @@ buildError: (pallet: string, name: string) => string | null;

type UnshapedDecoder = {
shape: Shape;
decoder: Decoder<Decoded>;
};
type VariantBasedBuild = (pallet: string, name: string) => {
view: UnshapedDecoder;
location: [number, number];
};
type GetViewBuilder = (metadata: V14) => {

@@ -237,2 +245,6 @@ buildDefinition: (idx: number) => {

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

@@ -364,2 +376,2 @@ interface DecodedCall {

export { type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CodeDeclarations, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives$1 as MetadataPrimitives, type NumberDecoded, type PrimitiveDecoded, type PrimitiveVar, type SequenceDecoded, type SequenceShape, type SequenceVar, type Shape, type StringDecoded, type StructDecoded, type StructShape, type StructVar, type TerminalVar, type TupleDecoded, type TupleShape, type TupleVar, type Var, type Variable, type VoidDecoded, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn, getStaticBuilder, getViewBuilder, primitiveTypes };
export { type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CodeDeclarations, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives$1 as MetadataPrimitives, type NumberDecoded, type PrimitiveDecoded, type PrimitiveVar, type SequenceDecoded, type SequenceShape, type SequenceVar, type Shape, type StringDecoded, type StructDecoded, type StructShape, type StructVar, type TerminalVar, type TupleDecoded, type TupleShape, type TupleVar, type UnshapedDecoder, type Var, type Variable, type VoidDecoded, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn, getStaticBuilder, getViewBuilder, primitiveTypes };

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

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

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

"dependencies": {
"@polkadot-api/substrate-bindings": "0.0.1-f000825b6d9815197ad6ec30ca3d96ef36aa4e8c.1.0",
"@polkadot-api/utils": "0.0.1-f000825b6d9815197ad6ec30ca3d96ef36aa4e8c.1.0"
"@polkadot-api/substrate-bindings": "0.0.1-f396f3bae7aa63a344f7191da9837b2835286f75.1.0",
"@polkadot-api/utils": "0.0.1-f396f3bae7aa63a344f7191da9837b2835286f75.1.0"
},

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc