@polkadot-api/metadata-builders
Advanced tools
Comparing version 0.0.1-bf38c108a73db2172976e6f3ee09904f79424cb8.1.0 to 0.0.1-bffb8194f5e6e12148f7b2104f8a4f1623c12a94.1.0
@@ -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; | ||
@@ -226,0 +226,0 @@ buildError: (pallet: string, name: string) => string | null; |
@@ -254,8 +254,9 @@ "use strict"; | ||
if (input.type === "sequence" && input.value.type === "primitive" && input.value.value === "u8") { | ||
declarations.imports.add("Hex"); | ||
declarations.imports.add("Bin"); | ||
declarations.typeImports.add("HexString"); | ||
declarations.typeImports.add("Binary"); | ||
const variable = { | ||
id: "_bytesSeq", | ||
value: "Hex()", | ||
types: "HexString", | ||
value: "Bin()", | ||
types: "Binary", | ||
directDependencies: /* @__PURE__ */ new Set() | ||
@@ -325,10 +326,11 @@ }; | ||
} | ||
declarations.imports.add("Hex"); | ||
declarations.imports.add("Bin"); | ||
declarations.variables.set(varId, { | ||
id: varId, | ||
value: `Hex(${input.len})`, | ||
types: "HexString", | ||
value: `Bin(${input.len})`, | ||
types: "Binary", | ||
directDependencies: /* @__PURE__ */ new Set() | ||
}); | ||
declarations.typeImports.add("HexString"); | ||
declarations.typeImports.add("Binary"); | ||
return varId; | ||
@@ -353,19 +355,3 @@ } | ||
if (value.value.length === 1) { | ||
let result; | ||
const innerVal = value.value[0]; | ||
if (key.startsWith("Raw") && innerVal.type === "array" && isBytes(innerVal.value)) { | ||
const id = `_fixedStr${innerVal.len}`; | ||
result = id; | ||
if (!declarations.variables.has(id)) { | ||
declarations.imports.add("fixedStr"); | ||
declarations.variables.set(id, { | ||
id, | ||
value: `fixedStr(${innerVal.len})`, | ||
types: "string", | ||
directDependencies: /* @__PURE__ */ new Set() | ||
}); | ||
} | ||
} else { | ||
result = buildNextSyntax(value.value[0]); | ||
} | ||
let result = buildNextSyntax(value.value[0]); | ||
if (!declarations.variables.has(varName)) { | ||
@@ -557,3 +543,4 @@ declarations.variables.set(varName, { | ||
var scale = __toESM(require("@polkadot-api/substrate-bindings")); | ||
var _bytes = scale.Hex(); | ||
var import_utils = require("@polkadot-api/utils"); | ||
var _bytes = scale.Bin(); | ||
var isBytes2 = (input) => input.type === "primitive" && input.value === "u8"; | ||
@@ -584,3 +571,3 @@ var _buildCodec = (input, cache, stack, _accountId) => { | ||
if (isBytes2(input.value)) { | ||
return input.len === 32 && (input.id === 0 || input.id === 1) ? _accountId : scale.Hex(input.len); | ||
return input.len === 32 && (input.id === 0 || input.id === 1) ? _accountId : scale.Bin(input.len); | ||
} | ||
@@ -595,9 +582,7 @@ return buildVector(input.value, input.len); | ||
return buildStruct(input.value); | ||
const dependencies = Object.entries(input.value).map(([k, v]) => { | ||
const dependencies = Object.values(input.value).map((v) => { | ||
if (v.type === "primitive") | ||
return scale._void; | ||
if (v.type === "tuple" && v.value.length === 1) { | ||
const innerVal = v.value[0]; | ||
return k.startsWith("Raw") && innerVal.type === "array" && isBytes2(innerVal.value) ? scale.fixedStr(innerVal.len) : buildNextCodec(innerVal); | ||
} | ||
if (v.type === "tuple" && v.value.length === 1) | ||
return buildNextCodec(v.value[0]); | ||
return v.type === "tuple" ? buildTuple(v.value) : buildStruct(v.value); | ||
@@ -665,16 +650,10 @@ }); | ||
}; | ||
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)) | ||
); | ||
}; | ||
@@ -690,8 +669,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 { | ||
@@ -818,13 +808,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) => { | ||
@@ -855,3 +834,3 @@ try { | ||
buildStorage: toStringEnhancer(buildStorage), | ||
buildCall: toStringEnhancer(buildCall), | ||
buildCall: toStringEnhancer(buildVariant("calls")), | ||
buildEvent: toStringEnhancer(buildVariant("events")), | ||
@@ -864,9 +843,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) => { | ||
@@ -945,7 +924,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) | ||
@@ -973,2 +952,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) => { | ||
@@ -1004,3 +991,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", | ||
@@ -1072,9 +1059,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) => { | ||
@@ -1110,4 +1091,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; | ||
@@ -226,0 +226,0 @@ buildError: (pallet: string, name: string) => string | null; |
@@ -1,8 +0,8 @@ | ||
"use strict";var se=Object.create;var W=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var pe=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var le=(e,t)=>{for(var p in t)W(e,p,{get:t[p],enumerable:!0})},G=(e,t,p,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ue(t))!de.call(e,s)&&s!==p&&W(e,s,{get:()=>t[s],enumerable:!(r=ce(t,s))||r.enumerable});return e};var J=(e,t,p)=>(p=e!=null?se(pe(e)):{},G(t||!e||!e.__esModule?W(p,"default",{value:e,enumerable:!0}):p,e)),me=e=>G(W({},"__esModule",{value:!0}),e);var We={};le(We,{getChecksumBuilder:()=>Ee,getDynamicBuilder:()=>Se,getLookupFn:()=>T,getStaticBuilder:()=>ve,getViewBuilder:()=>ae,primitiveTypes:()=>M});module.exports=me(We);var $={type:"primitive",value:"_void"},T=e=>{let t=new Map,p=new Set,s=(d=>o=>{let h=t.get(o);if(h)return h;if(p.has(o)){let c={id:o};return t.set(o,c),c}p.add(o);let y=d(o);return h=t.get(o),h?Object.assign(h,y):(h={id:o,...y},t.set(o,h)),p.delete(o),h})(d=>{let{def:o}=e[d];if(o.tag==="composite"){if(o.value.length===0)return $;if(o.value.length===1)return s(o.value[0].type);let y=!0,c={},v={};return o.value.forEach((b,g)=>{y=y&&!!b.name;let u=b.name||g;c[u]=s(b.type),v[u]=b.docs}),y?{type:"struct",value:c,innerDocs:v}:{type:"tuple",value:Object.values(c),innerDocs:Object.values(v)}}if(o.tag==="variant"){if(o.value.length===0)return $;let y={},c={};return o.value.forEach(v=>{let b=v.name;if(c[b]=v.docs,v.fields.length===0){y[b]={...$,idx:v.index};return}let g=!0,u={},n={};v.fields.forEach((i,a)=>{g=g&&!!i.name;let l=i.name||a;u[l]=s(i.type),n[l]=i.docs}),y[b]=g?{type:"struct",value:u,innerDocs:n,idx:v.index}:{type:"tuple",value:Object.values(u),innerDocs:Object.values(n),idx:v.index}}),{type:"enum",value:y,innerDocs:c}}if(o.tag==="sequence")return{type:"sequence",value:s(o.value)};if(o.tag==="array")return{type:"array",value:s(o.value.type),len:o.value.len};if(o.tag==="tuple"){if(o.value.length===0)return $;if(o.value.length===1)return s(o.value[0]);let y=o.value.map(v=>s(v)),c=o.value.map(v=>e[v].docs);return{type:"tuple",value:y,innerDocs:c}}if(o.tag==="primitive")return{type:"primitive",value:o.value.tag};if(o.tag==="compact"){let y=s(o.value);return{type:"compact",isBig:Number(y.value.slice(1))>32}}return o.tag==="bitSequence"?{type:"bitSequence"}:{type:"primitive",value:o.value}});return s};var L=(e,t,p)=>(r,s,d,...o)=>{let{id:h}=r;if(s.has(h))return s.get(h);if(d.has(h)){let c=t(()=>s.get(h),r,...o);return s.set(h,c),c}d.add(h);let y=e(r,s,d,...o);return d.delete(h),s.has(h)&&(y=p(y,s.get(h),r,...o)),s.set(h,y),y};var M={_void:"undefined",bool:"boolean",char:"string",str:"string",u8:"number",u16:"number",u32:"number",u64:"bigint",u128:"bigint",u256:"bigint",i8:"number",i16:"number",i32:"number",i64:"bigint",i128:"bigint",i256:"bigint",compactNumber:"number",compactBn:"bigint",bitSequence:"{bitsLen: number, bytes: Uint8Array}",historicMetaCompat:"any"},I=(...e)=>e[0]+e.slice(1).map(t=>t[0].toUpperCase()+t.slice(1)).join(""),Y=e=>e.type==="primitive"&&e.value==="u8",O=e=>M[e]??`I${e}`,ye=(e,t,p,r,s)=>{if(e.type==="primitive")return r.imports.add(e.value),e.value;if(e.type==="compact"){let n=e.isBig?"compactBn":"compactNumber";return r.imports.add(n),n}if(e.type==="bitSequence")return r.imports.add(e.type),e.type;if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8"){r.imports.add("Hex"),r.typeImports.add("HexString");let n={id:"_bytesSeq",value:"Hex()",types:"HexString",directDependencies:new Set};return r.variables.has(n.id)||r.variables.set(n.id,n),n.id}if(r.variables.has(s(e.id,"circular")))return s(e.id,"circular");if(r.variables.has(s(e.id)))return s(e.id);let d=n=>z(n,t,p,r,s),o=(n,i,a)=>{r.imports.add("Vector");let l=d(i),S={id:n,value:`Vector(${(a?[l,a]:[l]).join(", ")})`,types:`Array<${O(l)}>`,directDependencies:new Set([l])};return r.variables.set(n,S),n},h=(n,i)=>{r.imports.add("Tuple");let a=i.map(d),l={id:n,value:`Tuple(${a.join(", ")})`,types:`[${a.map(O).join(", ")}]`,directDependencies:new Set(a)};return r.variables.set(n,l),n},y=(n,i)=>{r.imports.add("Struct");let a=Object.values(i).map(d),l={id:n,value:`Struct({${Object.keys(i).map((m,S)=>`${m}: ${a[S]}`).join(", ")}})`,types:`{${Object.keys(i).map((m,S)=>`${m}: ${O(a[S])}`).join(", ")}}`,directDependencies:new Set(a)};return r.variables.set(n,l),n},c=s(e.id);if(e.type==="array"){if(Y(e.value)){if(e.len===32&&(e.id===0||e.id===1)){r.imports.add("AccountId");let n="_accountId";return r.variables.set(n,{id:n,value:"AccountId()",types:"SS58String",directDependencies:new Set}),r.typeImports.add("SS58String"),n}return r.imports.add("Hex"),r.variables.set(c,{id:c,value:`Hex(${e.len})`,types:"HexString",directDependencies:new Set}),r.typeImports.add("HexString"),c}return o(c,e.value,e.len)}if(e.type==="sequence")return o(c,e.value);if(e.type==="tuple")return h(c,e.value);if(e.type==="struct")return y(c,e.value);r.imports.add("Enum");let v=Object.entries(e.value).map(([n,i])=>{if(i.type==="primitive")return r.imports.add(i.value),i.value;let a=I(c,n);if(i.type==="tuple"){if(i.value.length===1){let l,m=i.value[0];if(n.startsWith("Raw")&&m.type==="array"&&Y(m.value)){let S=`_fixedStr${m.len}`;l=S,r.variables.has(S)||(r.imports.add("fixedStr"),r.variables.set(S,{id:S,value:`fixedStr(${m.len})`,types:"string",directDependencies:new Set}))}else l=d(i.value[0]);return r.variables.has(a)||r.variables.set(a,{id:a,value:l,types:O(l),directDependencies:new Set([l])}),a}return h(a,i.value)}else y(a,i.value);return a}),b=Object.values(e.value).map(n=>n.idx),g=b.every((n,i)=>n===i),u=`{${Object.keys(e.value).map((n,i)=>`${n}: ${v[i]}`)}}${g?"":`, [${b.join(", ")}]`}`;return r.variables.set(c,{id:c,value:`Enum(${u})`,types:Object.keys(e.value).map((n,i)=>`{tag: '${n}', value: ${O(v[i])}}`).join(" | "),directDependencies:new Set(v)}),c},z=L(ye,(e,t,p,r)=>{p.imports.add("Self");let s=r(t.id),d={id:r(t.id,"circular"),types:`I${s}`,value:`Self(() => ${s})`,directDependencies:new Set([s])};return p.variables.set(d.id,d),d.id},e=>e),ve=e=>{let t={imports:new Set,typeImports:new Set(["Codec"]),variables:new Map},p=e.lookup,r=T(p),s=(a,...l)=>{let{path:m}=p[a],S=m.length===0?["cdc"+a]:["c",...m];return S.push(...l),I(...S)},d=new Map,o=a=>z(r(a),d,new Set,t,s),h=(a,l)=>{if(t.variables.has(l))return l;let m=a.map(x=>x.type).map(o),S=a.map(x=>x.name);t.imports.add("Tuple");let E={id:l,types:`[${S.map((x,V)=>`${x[0].toUpperCase()+x.slice(1)}: ${O(m[V])}`).join(", ")}]`,value:`Tuple(${m.join(", ")})`,directDependencies:new Set(m)};return t.variables.set(l,E),l},y="_emptyTuple",c=()=>(t.variables.has(y)||(t.imports.add("Tuple"),t.variables.set(y,{id:y,types:"[]",value:"Tuple()",directDependencies:new Set})),y),v=(a,l)=>{let m=e.pallets.find(j=>j.name===a).storage.items.find(j=>j.name===l);if(m.type.tag==="plain")return{key:c(),val:o(m.type.value)};let{key:S,value:E}=m.type.value,x=o(E);return{key:m.type.value.hashers.length===1?h([{name:"key",type:S}],s(S,"Tupled")):o(S),val:x}},b=a=>(l,m)=>{let S=r(e.pallets.find(x=>x.name===l)[a]);if(S.type!=="enum")throw null;let E=I(o(S.id),m);return!t.variables.has(E)&&S.value[m].type==="primitive"&&t.variables.set(E,{id:E,value:"_void",types:"undefined",directDependencies:new Set}),E},g=(a,l)=>{let m=r(e.pallets.find(x=>x.name===a).calls);if(m.type!=="enum")throw null;let S=m.value[l];if(S.type==="primitive")return c();if(S.type==="tuple")return I(o(m.id),l);let E=Object.entries(S.value).map(([x,V])=>({name:x,type:V.id}));return h(E,s(m.id,l,"Tupled"))},u=(a,l)=>{let m=e.pallets.find(S=>S.name===a).constants.find(S=>S.name===l);return o(m.type)},n=()=>{let a=`import type {${[...t.typeImports].join(", ")}} from "@polkadot-api/substrate-bindings"; | ||
`,l=`import {${[...t.imports].join(", ")}} from "@polkadot-api/substrate-bindings"; | ||
"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:()=>be,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 h=S.name||c;d[h]=s(S.type),m[h]=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,h={},t={};m.fields.forEach((o,i)=>{c=c&&!!o.name;let u=o.name||i;h[u]=s(o.type),t[u]=o.docs}),v[S]=c?{type:"struct",value:h,innerDocs:t,idx:m.index}:{type:"tuple",value:Object.values(h),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}`,he=(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((b,g)=>`${b}: ${i[g]}`).join(", ")}})`,types:`{${Object.keys(o).map((b,g)=>`${b}: ${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),h=`{${Object.keys(e.value).map((t,o)=>`${t}: ${m[o]}`)}}${c?"":`, [${S.join(", ")}]`}`;return n.variables.set(d,{id:d,value:`Enum(${h})`,types:Object.keys(e.value).map((t,o)=>`{tag: '${t}', value: ${j(m[o])}}`).join(" | "),directDependencies:new Set(m)}),d},z=w(he,(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),be=e=>{let r={imports:new Set,typeImports:new Set(["Codec"]),variables:new Map},p=e.lookup,n=P(p),s=(i,...u)=>{let{path:b}=p[i],g=b.length===0?["cdc"+i]:["c",...b];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 b=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(b[O])}`).join(", ")}]`,value:`Tuple(${b.join(", ")})`,directDependencies:new Set(b)};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 b=e.pallets.find(L=>L.name===i).storage.items.find(L=>L.name===u);if(b.type.tag==="plain")return{key:d(),val:a(b.type.value)};let{key:g,value:x}=b.type.value,E=a(x);return{key:b.type.value.hashers.length===1?y([{name:"key",type:g}],s(g,"Tupled")):a(g),val:E}},S=i=>(u,b)=>{let g=n(e.pallets.find(E=>E.name===u)[i]);if(g.type!=="enum")throw null;let x=W(a(g.id),b);return!r.variables.has(x)&&g.value[b].type==="primitive"&&r.variables.set(x,{id:x,value:"_void",types:"undefined",directDependencies:new Set}),x},c=(i,u)=>{let b=n(e.pallets.find(E=>E.name===i).calls);if(b.type!=="enum")throw null;let g=b.value[u];if(g.type==="primitive")return d();if(g.type==="tuple")return W(a(b.id),u);let x=Object.entries(g.value).map(([E,O])=>({name:E,type:O.id}));return y(x,s(b.id,u,"Tupled"))},h=(i,u)=>{let b=e.pallets.find(g=>g.name===i).constants.find(g=>g.name===u);return a(b.type)},t=()=>{let i=`import type {${[...r.typeImports].join(", ")}} from "@polkadot-api/substrate-bindings"; | ||
`,u=`import {${[...r.imports].join(", ")}} from "@polkadot-api/substrate-bindings"; | ||
`,m=[...t.variables.values()].map(S=>`type I${S.id} = ${S.types}; | ||
const ${S.id}: Codec<I${S.id}> = ${S.value};`).join(` | ||
`,b=[...r.variables.values()].map(g=>`type I${g.id} = ${g.types}; | ||
const ${g.id}: Codec<I${g.id}> = ${g.value};`).join(` | ||
`);return`${a}${l}${m}`},i=a=>M[a]??t.variables.get(a)?.types??`I${a}`;return{buildDefinition:o,buildStorage:v,buildEvent:b("events"),buildError:b("errors"),buildCall:g,buildConstant:u,getTypeFromVarName:i,getCode:n}};var f=J(require("@polkadot-api/substrate-bindings"));var he=f.Hex(),Q=e=>e.type==="primitive"&&e.value==="u8",be=(e,t,p,r)=>{if(e.type==="primitive")return f[e.value];if(e.type==="compact")return f.compact;if(e.type==="bitSequence")return f.bitSequence;if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return he;let s=g=>X(g,t,p,r),d=(g,u)=>{let n=s(g);return u?f.Vector(n,u):f.Vector(n)},o=g=>f.Tuple(...g.map(s)),h=g=>{let u=Object.fromEntries(Object.entries(g).map(([n,i])=>[n,s(i)]));return f.Struct(u)};if(e.type==="array")return Q(e.value)?e.len===32&&(e.id===0||e.id===1)?r:f.Hex(e.len):d(e.value,e.len);if(e.type==="sequence")return d(e.value);if(e.type==="tuple")return o(e.value);if(e.type==="struct")return h(e.value);let y=Object.entries(e.value).map(([g,u])=>{if(u.type==="primitive")return f._void;if(u.type==="tuple"&&u.value.length===1){let n=u.value[0];return g.startsWith("Raw")&&n.type==="array"&&Q(n.value)?f.fixedStr(n.len):s(n)}return u.type==="tuple"?o(u.value):h(u.value)}),c=Object.fromEntries(Object.keys(e.value).map((g,u)=>[g,y[u]])),v=Object.values(e.value).map(g=>g.idx);return v.every((g,u)=>g===u)?f.Enum(c):f.Enum(c,v)},X=L(be,f.Self,e=>e),ge=f.Tuple(),Se=e=>{let t=e.lookup,p=T(t),r=f.AccountId(),s=new Map,d=u=>X(p(u),s,new Set,r),o=e.pallets.find(u=>u.name==="System")?.constants.find(u=>u.name==="SS58Prefix"),h;if(o)try{let u=d(o.type).dec(o.value);typeof u=="number"&&(h=u,r=f.AccountId(u))}catch{}let y=new Map,c=(u,n)=>{let i=y.get(u);i||y.set(u,i=f.Storage(u));let a=e.pallets.find(C=>C.name===u).storage.items.find(C=>C.name===n),l=(C,...B)=>{let K=i(...B);return{...K,len:C,fallback:a.modifier===1?K.dec(a.fallback):void 0}};if(a.type.tag==="plain")return l(0,n,d(a.type.value).dec);let{key:m,value:S,hashers:E}=a.type.value,x=d(S),V=E.map(C=>f[C.tag]),j=V.length===1?[[d(m),V[0]]]:p(m).value.map((C,B)=>[d(C.id),V[B]]);return l(V.length,n,x.dec,...j)},v=(u,n)=>{let i=e.pallets.find(m=>m.name===u),a=p(i.calls);if(a.type!=="enum")throw null;let l=a.value[n];return{location:[i.index,l.idx],args:l.type==="primitive"?ge:f.Tuple(...Object.values(l.value).map(m=>d(m.id)))}},b=(u,n)=>{let i=e.pallets.find(a=>a.name===u).constants.find(a=>a.name===n);return d(i.type)},g=u=>(n,i)=>{let a=e.pallets.find(S=>S.name===n),l=p(a[u]);if(l.type!=="enum")throw null;let m=l.value[i];return{location:[a.index,m.idx],codec:m.type==="primitive"?f._void:d(l.id)}};return{buildDefinition:d,buildStorage:c,buildEvent:g("events"),buildError:g("errors"),buildCall:v,buildConstant:b,ss58Prefix:h}};var F=require("@polkadot-api/substrate-bindings");var Z=new TextEncoder,fe=Z.encode.bind(Z),k=(e,t)=>{let p=typeof t=="string",r=new Uint8Array((e.length+(p?1:0))*8),s=new DataView(r.buffer),d=0;p&&(s.setBigUint64(d,(0,F.h64)(fe(t))),d+=8);for(let o=0;o<e.length;o++,d+=8)s.setBigUint64(d,e[o]);return(0,F.h64)(r)},H={_void:0n,bool:1n,char:2n,str:3n,u8:4n,u16:5n,u32:6n,u64:7n,u128:8n,u256:9n,i8:5n,i16:5n,i32:6n,i64:7n,i128:8n,i256:9n,compacts:10n,compactb:11n,bitSequence:12n,historicMetaCompat:13n},De=14n,xe=(e,t,p)=>{if(t.has(e.id))return t.get(e.id);if(e.type==="primitive")return H[e.value];if(e.type==="compact")return H[e.isBig?"compactb":"compacts"];if(e.type==="bitSequence")return H.bitSequence;if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return De;let r=c=>ee(c,t,p),s=(c,v)=>{let b=r(c);return v?k([b,BigInt(v)],"Vector(,)"):k([b],"Vector()")},d=c=>k(c.map(r)),o=c=>k(Object.values(c).map(r),JSON.stringify(Object.keys(c)));if(e.type==="array")return s(e.value,e.len);if(e.type==="sequence")return s(e.value);if(e.type==="tuple")return d(e.value);if(e.type==="struct")return o(e.value);let h=Object.values(e.value).map(c=>c.type==="primitive"?0n:c.type==="tuple"?d(c.value):o(c.value)),y=Object.keys(e.value);return y.push("Enum"),k(h,JSON.stringify({Enum:y}))},ee=L(xe,()=>0n,e=>e),Ee=e=>{let t=e.lookup,p=T(t),r=new Map,s=b=>ee(p(b),r,new Set),d=(b,g)=>{try{let u=e.pallets.find(m=>m.name===b).storage.items.find(m=>m.name===g);if(u.type.tag==="plain")return k([s(u.type.value)]);let{key:n,value:i}=u.type.value,a=s(i),l=u.type.value.hashers.length===1?k([s(n)]):s(n);return k([a,l])}catch{return null}},o=b=>{if(b.type==="primitive")return 0n;let g=Object.values(b.value).map(u=>s(u.id));return b.type==="tuple"?k(g):k(g,JSON.stringify(Object.keys(b.value)))},h=(b,g)=>{try{let u=e.pallets.find(i=>i.name===b),n=p(u.calls);if(n.type!=="enum")throw null;return o(n.value[g])}catch{return null}},y=b=>(g,u)=>{try{let n=e.pallets.find(a=>a.name===g),i=p(n[b]);if(i.type!=="enum")throw null;return o(i.value[u])}catch{return null}},c=(b,g)=>{try{let u=e.pallets.find(n=>n.name===b).constants.find(n=>n.name===g);return s(u.type)}catch{return null}},v=b=>(...g)=>b(...g)?.toString(32)??null;return{buildDefinition:v(s),buildStorage:v(d),buildCall:v(h),buildEvent:v(y("events")),buildError:v(y("errors")),buildConstant:v(c)}};var oe=require("@polkadot-api/utils"),A=require("@polkadot-api/substrate-bindings");var R=require("@polkadot-api/utils"),D=J(require("@polkadot-api/substrate-bindings")),ke=R.toHex,te=(e,t)=>D.createDecoder(p=>{let r=p,s=r.i,d=e(r),o=ke(new Uint8Array(r.buffer.slice(s,r.i)));return{...t,value:d,input:o}}),_=(e,t,p)=>{let r=te(t,{codec:e,...p});return Object.assign(r,{shape:{codec:e}})},q=(e,t,p)=>{let r=te(t,{codec:e.codec,...p});return Object.assign(r,{shape:e})},U=(e=42)=>{let t=D.enhanceDecoder(D.AccountId(e).dec,p=>({address:p,ss58Prefix:e}));return _("AccountId",t,{})},Ve=e=>_("BytesArray",D.Hex.dec(e),{len:e}),Ce=["_void","bool","char","str","u8","u16","u32","i8","i16","i32","u64","u128","u256","i64","i128","i256","compactNumber","compactBn","bitSequence"],Te=Object.fromEntries(Ce.map(e=>[e,_(e,D[e].dec)])),P={...Te,Bytes:_("Bytes",D.Hex.dec()),BytesArray:Ve,AccountId:U()},Pe=e=>q({codec:"Sequence",shape:e.shape},D.Vector.dec(e)),Le=(e,t)=>q({codec:"Array",shape:e.shape,len:t},D.Vector.dec(e,t)),we=(...e)=>q({codec:"Tuple",shape:e.map(t=>t.shape)},D.Tuple.dec(...e)),Ae=e=>q({codec:"Struct",shape:(0,R.mapStringRecord)(e,t=>t.shape)},D.Struct.dec(e)),Oe=(e,t)=>q({codec:"Enum",shape:(0,R.mapStringRecord)(e,p=>p.shape)},D.Enum.dec(e,t)),re=e=>{let t=r=>{let s=e(),d=s;return t=s,d(r)},p=r=>t(r);return p.shape={codec:"_void"},p},w={Sequence:Pe,Array:Le,Tuple:we,Struct:Ae,Enum:Oe};var N=(e,t,p)=>{let r=(0,A.enhanceDecoder)(e,s=>({...s,[t]:p}));return r.shape=e.shape,r},je=e=>(t,p,r,s,...d)=>{let{path:o}=s[t.id],h=e(t,p,r,s,...d);return o.length?N(h,"path",o):h},Re=(e,t,p,r,s)=>{if(e.type==="primitive")return P[e.value];if(e.type==="compact")return e.isBig?P.compactBn:P.compactNumber;if(e.type==="bitSequence")return P.bitSequence;if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return P.Bytes;let d=i=>ie(i,t,p,r,s),o=(i,a)=>{let l=d(i);return a?w.Array(l,a):w.Sequence(l)},h=(i,a)=>N(w.Tuple(...i.map(d)),"innerDocs",a),y=(i,a)=>N(w.Struct((0,oe.mapStringRecord)(i,d)),"innerDocs",a);if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?e.len===32&&(e.id===0||e.id===1)?s:P.BytesArray(e.len):o(e.value,e.len);if(e.type==="sequence")return o(e.value);if(e.type==="tuple")return h(e.value,e.innerDocs);if(e.type==="struct")return y(e.value,e.innerDocs);let c=Object.values(e.value).map(i=>i.type==="primitive"?P._void:i.type==="tuple"&&i.value.length===1?d(i.value[0]):i.type==="tuple"?h(i.value,i.innerDocs):y(i.value,i.innerDocs)),v=Object.fromEntries(Object.keys(e.value).map((i,a)=>[i,c[a]])),b=Object.values(e.value).map(i=>i.idx),u=b.every((i,a)=>i===a)?w.Enum(v):w.Enum(v,b),n=(0,A.enhanceDecoder)(u,i=>{let a=e.innerDocs[i.value.tag];return{...i,docs:a}});return n.shape=u.shape,n},qe=je(Re),ie=L(qe,re,(e,t)=>(t.shape=e.shape,e)),ne=e=>`0x${e.toString(16).padEnd(2,"0")}`,ae=e=>{let t=e.lookup,p=new Map,r=c=>ie(s(c),p,new Set,t,d),s=T(t),d=P.AccountId,o=e.pallets.find(c=>c.name==="System")?.constants.find(c=>c.name==="SS58Prefix");if(o)try{let c=r(o.type)(o.value).value;typeof c=="number"&&(d=U(c))}catch{}let h=c=>{let v=r(c);return{shape:v.shape,decoder:v}},y=(0,A.createDecoder)(c=>{let v=A.u8.dec(c),b=e.pallets.find(a=>a.index===v);if(!b)throw new Error("Invalid Pallet");let g={value:{name:b.name,idx:v},input:ne(c[0])},u=r(b.calls),n=u(c);if(n.codec!=="Enum")throw null;let i={value:{name:n.value.tag,idx:c[1]},input:ne(c[1]),docs:n.docs};return{pallet:g,call:i,args:{value:n.value.value,shape:u.shape}}});return{buildDefinition:h,callDecoder:y}}; | ||
`);return`${i}${u}${b}`},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:h,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,h)=>{let t=s(c);return h?f.Vector(t,h):f.Vector(t)},a=c=>f.Tuple(...c.map(s)),y=c=>{let h=Object.fromEntries(Object.entries(c).map(([t,o])=>[t,s(o)]));return f.Struct(h)};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,h)=>[c,v[h]])),m=Object.values(e.value).map(c=>c.idx);return m.every((c,h)=>c===h)?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),b=(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 b(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 b(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),b=p(u[t]);if(b.type!=="enum")throw null;let g=b.value[i];return{location:[u.index,g.idx],codec:m(b.value[i])}},h=(t,o)=>{let i=e.pallets.find(g=>g.name===t),u=p(i.calls);if(u.type!=="enum")throw null;let b=u.value[o];return{location:[i.index,b.idx],args:m(u.value[o],!0)}};return{buildDefinition:l,buildStorage:d,buildEvent:c("events"),buildError:c("errors"),buildCall:h,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:h,value:t}=c.type.value,o=s(t),i=c.type.value.hashers.length===1?k([s(h)]):s(h);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 h=e.pallets.find(o=>o.name===S),t=p(h[m]);if(t.type!=="enum")throw null;return a(t.value[c])}catch{return null}},v=(m,S)=>{try{let c=e.pallets.find(h=>h.name===m).constants.find(h=>h.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),h=S.every((o,i)=>o===i)?C.Enum(m):C.Enum(m,S),t=(0,A.enhanceDecoder)(h,o=>{let i=e.innerDocs[o.value.tag];return{...o,docs:i}});return t.shape=h.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 h=A.u8.dec(c),t=e.pallets.find(g=>g.index===h);if(!t)throw new Error("Invalid Pallet");let o={value:{name:t.name,idx:h},input:oe(c[0])},i=n(t.calls),u=i(c);if(u.codec!=="Enum")throw null;let b={value:{name:u.value.tag,idx:c[1]},input:oe(c[1]),docs:u.docs};return{pallet:o,call:b,args:{value:u.value.value,shape:i.shape}}}),d=ne((c,h=!1)=>c.type==="primitive"?h?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=>(h,t)=>{let o=e.pallets.find(b=>b.name===h),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,h)=>{let t=e.pallets.find(o=>o.name===c).constants.find(o=>o.name===h);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-bf38c108a73db2172976e6f3ee09904f79424cb8.1.0", | ||
"version": "0.0.1-bffb8194f5e6e12148f7b2104f8a4f1623c12a94.1.0", | ||
"author": "Josep M Sobrepere (https://github.com/josepot)", | ||
@@ -43,4 +43,4 @@ "repository": { | ||
"dependencies": { | ||
"@polkadot-api/substrate-bindings": "0.0.1-bf38c108a73db2172976e6f3ee09904f79424cb8.1.0", | ||
"@polkadot-api/utils": "0.0.1-bf38c108a73db2172976e6f3ee09904f79424cb8.1.0" | ||
"@polkadot-api/substrate-bindings": "0.0.1-bffb8194f5e6e12148f7b2104f8a4f1623c12a94.1.0", | ||
"@polkadot-api/utils": "0.0.1-bffb8194f5e6e12148f7b2104f8a4f1623c12a94.1.0" | ||
}, | ||
@@ -47,0 +47,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
357236
2956
201
3
5
1
201
+ Added@polkadot-api/substrate-bindings@0.0.1-bffb8194f5e6e12148f7b2104f8a4f1623c12a94.1.0(transitive)
+ Added@polkadot-api/utils@0.0.1-bffb8194f5e6e12148f7b2104f8a4f1623c12a94.1.0(transitive)
- Removed@polkadot-api/substrate-bindings@0.0.1-bf38c108a73db2172976e6f3ee09904f79424cb8.1.0(transitive)
- Removed@polkadot-api/utils@0.0.1-bf38c108a73db2172976e6f3ee09904f79424cb8.1.0(transitive)
Updated@polkadot-api/substrate-bindings@0.0.1-bffb8194f5e6e12148f7b2104f8a4f1623c12a94.1.0
Updated@polkadot-api/utils@0.0.1-bffb8194f5e6e12148f7b2104f8a4f1623c12a94.1.0