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-872c78405d9cf314126433de635c6e48d3e528f7.1.0 to 0.0.1-8b97ddc9d38a23571c21e4f4ed1530816e6fc54c.1.0

41

dist/index.d.ts

@@ -39,2 +39,13 @@ import * as scale from '@polkadot-api/substrate-bindings';

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

@@ -49,3 +60,3 @@ type: "sequence";

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

@@ -336,2 +347,13 @@ type LookupEntry = {

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

@@ -355,3 +377,3 @@ codec: "Tuple";

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

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

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

@@ -380,3 +413,3 @@ codec: "Enum";

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

@@ -388,2 +421,2 @@ codec: PrimitiveDecoded["codec"];

export { type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CodeDeclarations, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives$1 as MetadataPrimitives, type NumberDecoded, type PrimitiveDecoded, type PrimitiveVar, type SequenceDecoded, type SequenceShape, type SequenceVar, type Shape, type StringDecoded, type StructDecoded, type StructShape, type StructVar, type TerminalVar, type TupleDecoded, type TupleShape, type TupleVar, type UnshapedDecoder, 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 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 };

@@ -76,3 +76,3 @@ "use strict";

const getLookupEntryDef = withCache2((id) => {
const { def } = lookupData[id];
const { def, path, params } = lookupData[id];
if (def.tag === "composite") {

@@ -103,2 +103,17 @@ if (def.value.length === 0)

if (def.tag === "variant") {
if (path.length === 1 && path[0] === "Option" && params.length === 1 && params[0].name === "T") {
return {
type: "option",
value: getLookupEntryDef(params[0].type)
};
}
if (path.length === 1 && path[0] === "Result" && params.length === 2 && params[0].name === "T" && params[1].name === "E") {
return {
type: "result",
value: {
ok: getLookupEntryDef(params[0].type),
ko: getLookupEntryDef(params[1].type)
}
};
}
if (def.value.length === 0)

@@ -346,2 +361,30 @@ return voidVar;

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

@@ -582,2 +625,9 @@ declarations.typeImports.add("Enum");

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

@@ -777,2 +827,9 @@ if (v.type === "primitive")

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

@@ -951,2 +1008,10 @@ if (v.type === "primitive")

);
var OptionDec = (input) => complexShapedDecoder(
{ codec: "Option", shape: input.shape },
scale2.Option.dec(input)
);
var ResultDec = (ok, ko) => complexShapedDecoder(
{ codec: "Result", shape: { ok: ok.shape, ko: ko.shape } },
scale2.Result.dec(ok, ko)
);
var selfDecoder = (value) => {

@@ -968,3 +1033,5 @@ let cache = (x) => {

Struct: StructDec,
Enum: EnumDec
Enum: EnumDec,
Option: OptionDec,
Result: ResultDec
};

@@ -1027,2 +1094,6 @@

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

@@ -1029,0 +1100,0 @@ if (v.type === "primitive")

@@ -39,2 +39,13 @@ import * as scale from '@polkadot-api/substrate-bindings';

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

@@ -49,3 +60,3 @@ type: "sequence";

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

@@ -336,2 +347,13 @@ type LookupEntry = {

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

@@ -355,3 +377,3 @@ codec: "Tuple";

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

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

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

@@ -380,3 +413,3 @@ codec: "Enum";

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

@@ -388,2 +421,2 @@ codec: PrimitiveDecoded["codec"];

export { type AccountIdDecoded, type ArrayDecoded, type ArrayShape, type ArrayVar, type BigNumberDecoded, type BitSequenceDecoded, type BitSequenceVar, type BoolDecoded, type BytesArrayDecoded, type BytesSequenceDecoded, type CodeDeclarations, type CompactVar, type ComplexDecoded, type ComplexShape, type ComposedVar, type Decoded, type DecodedCall, type EnumDecoded, type EnumShape, type EnumVar, type GetViewBuilder, type LookupEntry, type MetadataPrimitives$1 as MetadataPrimitives, type NumberDecoded, type PrimitiveDecoded, type PrimitiveVar, type SequenceDecoded, type SequenceShape, type SequenceVar, type Shape, type StringDecoded, type StructDecoded, type StructShape, type StructVar, type TerminalVar, type TupleDecoded, type TupleShape, type TupleVar, type UnshapedDecoder, 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 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 };

10

dist/min/index.js

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

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

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

"dependencies": {
"@polkadot-api/substrate-bindings": "0.0.1-872c78405d9cf314126433de635c6e48d3e528f7.1.0",
"@polkadot-api/utils": "0.0.1-872c78405d9cf314126433de635c6e48d3e528f7.1.0"
"@polkadot-api/substrate-bindings": "0.0.1-8b97ddc9d38a23571c21e4f4ed1530816e6fc54c.1.0",
"@polkadot-api/utils": "0.0.1-8b97ddc9d38a23571c21e4f4ed1530816e6fc54c.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