@polkadot-api/metadata-builders
Advanced tools
Comparing version 0.0.1-b85a35814e64d4ada9f9a09e268b7fe12d887dbb.1.0 to 0.0.1-b8785fd7807321e74707adbc1405318c0d8a5587.1.0
import * as scale from '@polkadot-api/substrate-bindings'; | ||
import { StringRecord, V15, Codec } from '@polkadot-api/substrate-bindings'; | ||
type VoidVar = { | ||
type: "primitive"; | ||
value: "_void"; | ||
}; | ||
type MetadataPrimitives = "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256"; | ||
@@ -12,6 +8,9 @@ type PrimitiveVar = { | ||
value: MetadataPrimitives; | ||
} | VoidVar; | ||
}; | ||
type VoidVar = { | ||
type: "void"; | ||
}; | ||
type CompactVar = { | ||
type: "compact"; | ||
isBig: boolean; | ||
isBig: boolean | null; | ||
}; | ||
@@ -24,3 +23,3 @@ type BitSequenceVar = { | ||
}; | ||
type TerminalVar = PrimitiveVar | CompactVar | BitSequenceVar | AccountId32; | ||
type TerminalVar = PrimitiveVar | VoidVar | CompactVar | BitSequenceVar | AccountId32; | ||
type TupleVar = { | ||
@@ -38,3 +37,6 @@ type: "tuple"; | ||
type: "enum"; | ||
value: StringRecord<(TupleVar | StructVar | VoidVar) & { | ||
value: StringRecord<({ | ||
type: "lookupEntry"; | ||
value: LookupEntry; | ||
} | VoidVar | TupleVar | StructVar) & { | ||
idx: number; | ||
@@ -218,4 +220,5 @@ }>; | ||
buildNamedTuple: (input: StructVar) => string | null; | ||
getAllGeneratedChecksums: () => string[]; | ||
}; | ||
export { type AccountId32, type ArrayVar, type BitSequenceVar, type CompactVar, type ComposedVar, type EnumVar, type LookupEntry, type MetadataPrimitives, type OptionVar, type PrimitiveVar, type ResultVar, type SequenceVar, type StructVar, type TerminalVar, type TupleVar, type Var, type VoidVar, getChecksumBuilder, getDynamicBuilder, getLookupFn }; |
@@ -40,3 +40,2 @@ "use strict"; | ||
// src/lookups.ts | ||
var voidVar = { type: "primitive", value: "_void" }; | ||
var getLookupFn = (lookupData) => { | ||
@@ -78,3 +77,3 @@ const lookups = /* @__PURE__ */ new Map(); | ||
if (def.value.length === 0) | ||
return voidVar; | ||
return { type: "void" }; | ||
if (def.value.length === 1) { | ||
@@ -109,4 +108,4 @@ if (isAccountId32SearchOn && path.join(",") === "sp_core,crypto,AccountId32") { | ||
const value = getLookupEntryDef(params[0].type); | ||
return value.type === "primitive" && value.value === "_void" ? ( | ||
// Option(_void) would return a Codec<undefined> which makes no sense | ||
return value.type === "void" ? ( | ||
// Option<void> would return a Codec<undefined> which makes no sense | ||
// Therefore, we better treat it as a bool | ||
@@ -129,3 +128,3 @@ { type: "primitive", value: "bool" } | ||
if (def.value.length === 0) | ||
return voidVar; | ||
return { type: "void" }; | ||
const enumValue = {}; | ||
@@ -137,5 +136,13 @@ const enumDocs = {}; | ||
if (x.fields.length === 0) { | ||
enumValue[key] = { ...voidVar, idx: x.index }; | ||
enumValue[key] = { type: "void", idx: x.index }; | ||
return; | ||
} | ||
if (x.fields.length === 1 && !x.fields[0].name) { | ||
enumValue[key] = { | ||
type: "lookupEntry", | ||
value: getLookupEntryDef(x.fields[0].type), | ||
idx: x.index | ||
}; | ||
return; | ||
} | ||
let allKey = true; | ||
@@ -176,3 +183,8 @@ const values = {}; | ||
if (def.tag === "array") { | ||
const { len } = def.value; | ||
const value = getLookupEntryDef(def.value.type); | ||
if (len === 0) | ||
return { type: "void" }; | ||
if (len === 1) | ||
return value; | ||
return { | ||
@@ -186,3 +198,3 @@ type: "array", | ||
if (def.value.length === 0) | ||
return voidVar; | ||
return { type: "void" }; | ||
if (def.value.length === 1) | ||
@@ -192,2 +204,10 @@ return getLookupEntryDef(def.value[0]); | ||
const innerDocs = def.value.map((x) => lookupData[x].docs); | ||
const areAllSame = value.every((v) => v.id === value[0].id); | ||
if (areAllSame && innerDocs.every((doc) => doc.length === 0)) { | ||
return { | ||
type: "array", | ||
value: value[0], | ||
len: value.length | ||
}; | ||
} | ||
return { | ||
@@ -207,2 +227,4 @@ type: "tuple", | ||
const translated = getLookupEntryDef(def.value); | ||
if (translated.type === "void") | ||
return { type: "compact", isBig: null }; | ||
const isBig = Number(translated.value.slice(1)) > 32; | ||
@@ -249,2 +271,4 @@ return { | ||
return scale[input.value]; | ||
if (input.type === "void") | ||
return scale._void; | ||
if (input.type === "AccountId32") | ||
@@ -256,5 +280,2 @@ return _accountId; | ||
return scale.bitSequence; | ||
if (input.type === "sequence" && input.value.type === "primitive" && input.value.value === "u8") { | ||
return _bytes; | ||
} | ||
const buildNextCodec = (nextInput) => buildCodec(nextInput, cache, stack, _accountId); | ||
@@ -272,2 +293,5 @@ const buildVector = (inner2, len) => { | ||
}; | ||
if (input.type === "sequence" && input.value.type === "primitive" && input.value.value === "u8") { | ||
return _bytes; | ||
} | ||
if (input.type === "array") { | ||
@@ -292,6 +316,6 @@ if (input.value.type === "primitive" && input.value.value === "u8") | ||
const dependencies = Object.values(input.value).map((v) => { | ||
if (v.type === "primitive") | ||
if (v.type === "void") | ||
return scale._void; | ||
if (v.type === "tuple" && v.value.length === 1) | ||
return buildNextCodec(v.value[0]); | ||
if (v.type === "lookupEntry") | ||
return buildNextCodec(v.value); | ||
return v.type === "tuple" ? buildTuple(v.value) : buildStruct(v.value); | ||
@@ -359,6 +383,6 @@ }); | ||
const buildEnumEntry = (entry) => { | ||
if (entry.type === "primitive") | ||
if (entry.type === "void") | ||
return scale._void; | ||
if (entry.type === "tuple" && entry.value.length === 1) | ||
return buildDefinition(entry.value[0].id); | ||
if (entry.type === "lookupEntry") | ||
return buildDefinition(entry.value.id); | ||
return entry.type === "tuple" ? scale.Tuple( | ||
@@ -425,3 +449,4 @@ ...Object.values(entry.value).map((l) => buildDefinition(l.id)) | ||
result: 5n, | ||
enum: 6n | ||
enum: 6n, | ||
void: 7n | ||
}; | ||
@@ -442,3 +467,2 @@ var runtimePrimitiveIds = { | ||
var metadataPrimitiveIds = { | ||
_void: runtimePrimitiveIds.undefined, | ||
bool: runtimePrimitiveIds.boolean, | ||
@@ -482,4 +506,6 @@ char: runtimePrimitiveIds.string, | ||
const children = Object.values(entry.value).flatMap((value) => { | ||
if (value.type === "primitive") | ||
if (value.type === "void") | ||
return []; | ||
if (value.type === "lookupEntry") | ||
return value.value; | ||
if (value.type === "struct") | ||
@@ -522,12 +548,11 @@ return Object.values(value.value); | ||
return getChecksum([shapeIds.primitive, metadataPrimitiveIds[input.value]]); | ||
if (input.type === "void") | ||
return getChecksum([shapeIds.void]); | ||
if (input.type === "compact") | ||
return getChecksum([ | ||
shapeIds.primitive, | ||
runtimePrimitiveIds[input.isBig ? "bigint" : "number"] | ||
runtimePrimitiveIds[input.isBig || input.isBig === null ? "bigint" : "number"] | ||
]); | ||
if (input.type === "bitSequence") | ||
return getChecksum([shapeIds.primitive, runtimePrimitiveIds.bitSequence]); | ||
if (input.type === "sequence" && input.value.type === "primitive" && input.value.value === "u8") { | ||
return getChecksum([shapeIds.primitive, runtimePrimitiveIds.byteSequence]); | ||
} | ||
if (input.type === "AccountId32") { | ||
@@ -537,7 +562,19 @@ return getChecksum([shapeIds.primitive, runtimePrimitiveIds.accountId]); | ||
if (input.type === "array") { | ||
const innerChecksum = buildNextChecksum(input.value); | ||
const innerValue = input.value; | ||
if (innerValue.type === "primitive" && innerValue.value === "u8") { | ||
return getChecksum([ | ||
shapeIds.primitive, | ||
runtimePrimitiveIds.byteSequence, | ||
BigInt(input.len) | ||
]); | ||
} | ||
const innerChecksum = buildNextChecksum(innerValue); | ||
return getChecksum([shapeIds.vector, innerChecksum, BigInt(input.len)]); | ||
} | ||
if (input.type === "sequence") { | ||
const innerChecksum = buildNextChecksum(input.value); | ||
const innerValue = input.value; | ||
if (innerValue.type === "primitive" && innerValue.value === "u8") { | ||
return getChecksum([shapeIds.primitive, runtimePrimitiveIds.byteSequence]); | ||
} | ||
const innerChecksum = buildNextChecksum(innerValue); | ||
return getChecksum([shapeIds.vector, innerChecksum]); | ||
@@ -560,5 +597,7 @@ } | ||
return structLikeBuilder(shapeIds.enum, input.value, (entry) => { | ||
if (entry.type === "lookupEntry") | ||
return buildNextChecksum(entry.value); | ||
switch (entry.type) { | ||
case "primitive": | ||
return metadataPrimitiveIds._void; | ||
case "void": | ||
return getChecksum([shapeIds.void]); | ||
case "tuple": | ||
@@ -740,3 +779,3 @@ return buildTuple(entry.value); | ||
const buildComposite = (input) => { | ||
if (input.type === "primitive") | ||
if (input.type === "void") | ||
return getChecksum([0n]); | ||
@@ -765,8 +804,10 @@ if (input.type === "tuple") { | ||
const palletEntry = metadata.pallets.find((x) => x.name === pallet); | ||
const callsLookup = getLookupEntryDef( | ||
const enumLookup = getLookupEntryDef( | ||
palletEntry[variantType] | ||
); | ||
if (callsLookup.type !== "enum") | ||
buildDefinition(enumLookup.id); | ||
if (enumLookup.type !== "enum") | ||
throw null; | ||
return buildComposite(callsLookup.value[name]); | ||
const entry = enumLookup.value[name]; | ||
return entry.type === "lookupEntry" ? buildDefinition(entry.value.id) : buildComposite(entry); | ||
} catch (_) { | ||
@@ -794,5 +835,6 @@ return null; | ||
buildComposite: toStringEnhancer(buildComposite), | ||
buildNamedTuple: toStringEnhancer(buildNamedTuple) | ||
buildNamedTuple: toStringEnhancer(buildNamedTuple), | ||
getAllGeneratedChecksums: () => Array.from(cache.values()).map((v) => v.toString(32)) | ||
}; | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var H=Object.create;var R=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var X=(e,r)=>{for(var u in r)R(e,u,{get:r[u],enumerable:!0})},I=(e,r,u,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of U(r))!Q.call(e,n)&&n!==u&&R(e,n,{get:()=>r[n],enumerable:!(s=N(r,n))||s.enumerable});return e};var Y=(e,r,u)=>(u=e!=null?H(J(e)):{},I(r||!e||!e.__esModule?R(u,"default",{value:e,enumerable:!0}):u,e)),Z=e=>I(R({},"__esModule",{value:!0}),e);var ce={};X(ce,{getChecksumBuilder:()=>se,getDynamicBuilder:()=>te,getLookupFn:()=>C});module.exports=Z(ce);var T={type:"primitive",value:"_void"},C=e=>{let r=new Map,u=new Set,s=l=>t=>{let c=r.get(t);if(c)return c;if(u.has(t)){let p={id:t};return r.set(t,p),p}u.add(t);let d=l(t);return c=r.get(t),c?Object.assign(c,d):(c={id:t,...d},r.set(t,c)),u.delete(t),c},n=!0,i=s(l=>{let{def:t,path:c,params:d}=e[l];if(t.tag==="composite"){if(t.value.length===0)return T;if(t.value.length===1)return n&&c.join(",")==="sp_core,crypto,AccountId32"?(n=!1,{type:"AccountId32"}):i(t.value[0].type);let p=!0,v={},o={};return t.value.forEach((m,a)=>{p=p&&!!m.name;let b=m.name||a;v[b]=i(m.type),o[b]=m.docs}),p?{type:"struct",value:v,innerDocs:o}:{type:"tuple",value:Object.values(v),innerDocs:Object.values(o)}}if(t.tag==="variant"){if(c.length===1&&c[0]==="Option"&&d.length===1&&d[0].name==="T"){let o=i(d[0].type);return o.type==="primitive"&&o.value==="_void"?{type:"primitive",value:"bool"}:{type:"option",value:o}}if(c.length===1&&c[0]==="Result"&&d.length===2&&d[0].name==="T"&&d[1].name==="E")return{type:"result",value:{ok:i(d[0].type),ko:i(d[1].type)}};if(t.value.length===0)return T;let p={},v={};return t.value.forEach(o=>{let m=o.name;if(v[m]=o.docs,o.fields.length===0){p[m]={...T,idx:o.index};return}let a=!0,b={},f={};o.fields.forEach((g,k)=>{a=a&&!!g.name;let V=g.name||k;b[V]=i(g.type),f[V]=g.docs}),p[m]=a?{type:"struct",value:b,innerDocs:f,idx:o.index}:{type:"tuple",value:Object.values(b),innerDocs:Object.values(f),idx:o.index}}),{type:"enum",value:p,innerDocs:v}}if(t.tag==="sequence")return{type:"sequence",value:i(t.value)};if(t.tag==="array")return{type:"array",value:i(t.value.type),len:t.value.len};if(t.tag==="tuple"){if(t.value.length===0)return T;if(t.value.length===1)return i(t.value[0]);let p=t.value.map(o=>i(o)),v=t.value.map(o=>e[o].docs);return{type:"tuple",value:p,innerDocs:v}}if(t.tag==="primitive")return{type:"primitive",value:t.value.tag};if(t.tag==="compact"){let p=i(t.value);return{type:"compact",isBig:Number(p.value.slice(1))>32}}return{type:t.tag}});return i};var y=Y(require("@polkadot-api/substrate-bindings"));var M=(e,r,u)=>(s,n,i,...l)=>{let{id:t}=s;if(n.has(t))return n.get(t);if(i.has(t)){let d=r(()=>n.get(t),s,...l);return n.set(t,d),d}i.add(t);let c=e(s,n,i,...l);return i.delete(t),n.has(t)&&(c=u(c,n.get(t),s,...l)),n.set(t,c),c};var _=require("@polkadot-api/utils"),$=y.Bin(),ee=(e,r,u,s)=>{if(e.type==="primitive")return y[e.value];if(e.type==="AccountId32")return s;if(e.type==="compact")return y.compact;if(e.type==="bitSequence")return y.bitSequence;if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return $;let n=o=>P(o,r,u,s),i=(o,m)=>{let a=n(o);return m?y.Vector(a,m):y.Vector(a)},l=o=>y.Tuple(...o.map(n)),t=o=>{let m=Object.fromEntries(Object.entries(o).map(([a,b])=>[a,n(b)]));return y.Struct(m)};if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?y.Bin(e.len):i(e.value,e.len);if(e.type==="sequence")return i(e.value);if(e.type==="tuple")return l(e.value);if(e.type==="struct")return t(e.value);if(e.type==="option")return y.Option(n(e.value));if(e.type==="result")return y.Result(n(e.value.ok),n(e.value.ko));let c=Object.values(e.value).map(o=>o.type==="primitive"?y._void:o.type==="tuple"&&o.value.length===1?n(o.value[0]):o.type==="tuple"?l(o.value):t(o.value)),d=Object.fromEntries(Object.keys(e.value).map((o,m)=>[o,c[m]])),p=Object.values(e.value).map(o=>o.idx);return p.every((o,m)=>o===m)?y.Variant(d):y.Variant(d,p)},P=M(ee,y.Self,e=>e),te=e=>{let r=e.lookup,u=C(r),s=y.AccountId(),n=new Map,i=a=>P(u(a),n,new Set,s),l=e.pallets.find(a=>a.name==="System")?.constants.find(a=>a.name==="SS58Prefix"),t;if(l)try{let a=i(l.type).dec(l.value);typeof a=="number"&&(t=a,s=y.AccountId(a))}catch{}let c=new Map,d=(a,b)=>{let f=c.get(a);f||c.set(a,f=y.Storage(a));let g=e.pallets.find(L=>L.name===a).storage.items.find(L=>L.name===b),k=(L,...q)=>{let D=f(...q);return{...D,len:L,fallback:g.modifier===1?D.dec(g.fallback):void 0}};if(g.type.tag==="plain")return k(0,b,i(g.type.value).dec);let{key:V,value:O,hashers:z}=g.type.value,W=i(O),x=z.map(L=>y[L.tag]),K=x.length===1?[[i(V),x[0]]]:u(V).value.map((L,q)=>[i(L.id),x[q]]);return k(x.length,b,W.dec,...K)},p=a=>a.type==="primitive"?y._void:a.type==="tuple"&&a.value.length===1?i(a.value[0].id):a.type==="tuple"?y.Tuple(...Object.values(a.value).map(b=>i(b.id))):y.Struct((0,_.mapObject)(a.value,b=>i(b.id))),v=(a,b)=>{let f=e.pallets.find(g=>g.name===a).constants.find(g=>g.name===b);return i(f.type)},o=a=>(b,f)=>{let g=e.pallets.find(O=>O.name===b),k=u(g[a]);if(k.type!=="enum")throw null;let V=k.value[f];return{location:[g.index,V.idx],codec:p(k.value[f])}},m=(a,b)=>{let f=e.apis.find(g=>g.name===a)?.methods.find(g=>g.name===b);if(!f)throw null;return{args:y.Tuple(...f.inputs.map(g=>i(g.type))),value:i(f.output)}};return{buildDefinition:i,buildStorage:d,buildEvent:o("events"),buildError:o("errors"),buildRuntimeCall:m,buildCall:o("calls"),buildConstant:v,ss58Prefix:t}};var j=require("@polkadot-api/substrate-bindings");var B=new TextEncoder,re=B.encode.bind(B),S=e=>{let r=new Uint8Array(e.length*8),u=new DataView(r.buffer);for(let s=0;s<e.length;s++)u.setBigUint64(s*8,e[s]);return(0,j.h64)(r)},F=e=>S(e.map(r=>(0,j.h64)(re(r)))),E={primitive:0n,vector:1n,tuple:2n,struct:3n,option:4n,result:5n,enum:6n},h={undefined:0n,number:1n,string:2n,bigint:3n,boolean:4n,bitSequence:5n,byteSequence:6n,accountId:7n},G={_void:h.undefined,bool:h.boolean,char:h.string,str:h.string,u8:h.number,u16:h.number,u32:h.number,u64:h.bigint,u128:h.bigint,u256:h.bigint,i8:h.number,i16:h.number,i32:h.number,i64:h.bigint,i128:h.bigint,i256:h.bigint},A=(e,r,u)=>{let s=Object.entries(r).sort(([l],[t])=>l.localeCompare(t)),n=F(s.map(([l])=>l)),i=S(s.map(([,l])=>u(l)));return S([e,n,i])},w=(e,r=new Map)=>{if(r.has(e.id))return r;switch(e.type){case"array":case"option":case"sequence":r.set(e.id,[e,new Set([e.value.id])]),w(e.value,r);break;case"enum":{let u=Object.values(e.value).flatMap(s=>s.type==="primitive"?[]:s.type==="struct"?Object.values(s.value):s.value);r.set(e.id,[e,new Set(u.map(s=>s.id))]),u.forEach(s=>w(s,r));break}case"result":r.set(e.id,[e,new Set([e.value.ok.id,e.value.ko.id])]),w(e.value.ok,r),w(e.value.ko,r);break;case"struct":{let u=Object.values(e.value);r.set(e.id,[e,new Set(u.map(s=>s.id))]),u.forEach(s=>w(s,r));break}case"tuple":r.set(e.id,[e,new Set(e.value.map(u=>u.id))]),e.value.forEach(u=>w(u,r));break;default:r.set(e.id,[e,new Set])}return r},ne=(e,r)=>{if(e.type==="primitive")return S([E.primitive,G[e.value]]);if(e.type==="compact")return S([E.primitive,h[e.isBig?"bigint":"number"]]);if(e.type==="bitSequence")return S([E.primitive,h.bitSequence]);if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return S([E.primitive,h.byteSequence]);if(e.type==="AccountId32")return S([E.primitive,h.accountId]);if(e.type==="array"){let n=r(e.value);return S([E.vector,n,BigInt(e.len)])}if(e.type==="sequence"){let n=r(e.value);return S([E.vector,n])}let u=n=>S([E.tuple,...n.map(r)]),s=n=>A(E.struct,n,r);return e.type==="tuple"?u(e.value):e.type==="struct"?s(e.value):e.type==="option"?S([E.option,r(e.value)]):e.type==="result"?S([E.result,r(e.value.ok),r(e.value.ko)]):A(E.enum,e.value,n=>{switch(n.type){case"primitive":return G._void;case"tuple":return u(n.value);case"struct":return s(n.value)}})},oe=e=>{let r=new Map,u=0,s=[],n=[];function i(l){let t={index:u,lowLink:u,onStack:!0};r.set(l,t),u++,s.push(l);let c=e.get(l)[1];for(let d of c){let p=r.get(d);p?p.onStack&&(t.lowLink=Math.min(t.lowLink,p.index)):(i(d),t.lowLink=Math.min(t.lowLink,r.get(d).lowLink))}if(t.lowLink===t.index){let d=new Set,p=-1;do p=s.pop(),r.get(p).onStack=!1,d.add(p);while(p!==l);d.size>1&&n.push(d)}}for(let l of e.keys())r.has(l)||i(l);return n},ie=e=>{let r=new Set(e.map((n,i)=>i)),u=new Map(e.map((n,i)=>[i,new Set]));e.forEach((n,i)=>{e.slice(i+1).forEach((l,t)=>{let c=t+i+1;new Set([...n,...l]).size!==n.size+l.size&&(u.get(i).add(c),u.get(c).add(i))})});let s=[];for(;r.size;){let n=new Set,i=[r.values().next().value];for(;i.length;){let l=i.pop();if(!r.has(l))continue;r.delete(l),e[l].forEach(c=>n.add(Number(c))),u.get(l).forEach(c=>i.push(c))}s.push(n)}return s},ae=(e,r)=>{let u=i=>{let l=i.values().next().value,t=r.get(l)[0];return Array.from(w(t).keys())},s=new Array;function n(i){s.includes(i)||(e.filter(t=>t!==i&&u(i).some(c=>t.has(c))).forEach(t=>n(t)),s.includes(i))||s.push(i)}return e.forEach(i=>n(i)),s},ue=(e,r)=>{if(r.has(e.id))return r.get(e.id);let u=w(e),s=oe(u),n=ie(s),i=ae(n,u),l=(t,c,d=!1)=>{if(!d&&r.has(t.id))return r.get(t.id);let p=ne(t,v=>l(v,c));return c(t.id,p),p};return i.forEach(t=>{t.forEach(c=>r.set(c,0n));for(let c=0;c<t.size;c++){let d=new Map;t.forEach(p=>l(u.get(p)[0],(v,o)=>{(t.has(v)?d:r).set(v,o)},!0)),Array.from(d.entries()).forEach(([p,v])=>r.set(p,v))}}),l(e,(t,c)=>r.set(t,c))},se=e=>{let r=e.lookup,u=C(r),s=new Map,n=o=>ue(u(o),s),i=(o,m)=>{try{let a=e.pallets.find(V=>V.name===o).storage.items.find(V=>V.name===m);if(a.type.tag==="plain")return n(a.type.value);let{key:b,value:f}=a.type.value,g=n(f),k=n(b);return S([g,k])}catch{return null}},l=(o,m)=>{try{let a=e.apis.find(k=>k.name===o)?.methods.find(k=>k.name===m);if(!a)throw null;let b=F(a.inputs.map(k=>k.name)),f=S(a.inputs.map(k=>n(k.type))),g=n(a.output);return S([b,f,g])}catch{return null}},t=o=>{if(o.type==="primitive")return S([0n]);if(o.type==="tuple"){let m=Object.values(o.value).map(a=>n(a.id));return S([E.tuple,...m])}return A(E.struct,o.value,m=>n(m.id))},c=o=>A(E.tuple,o.value,m=>n(m.id)),d=o=>(m,a)=>{try{let b=e.pallets.find(g=>g.name===m),f=u(b[o]);if(f.type!=="enum")throw null;return t(f.value[a])}catch{return null}},p=(o,m)=>{try{let a=e.pallets.find(b=>b.name===o).constants.find(b=>b.name===m);return n(a.type)}catch{return null}},v=o=>(...m)=>o(...m)?.toString(32)??null;return{buildDefinition:v(n),buildRuntimeCall:v(l),buildStorage:v(i),buildCall:v(d("calls")),buildEvent:v(d("events")),buildError:v(d("errors")),buildConstant:v(p),buildComposite:v(t),buildNamedTuple:v(c)}}; | ||
"use strict";var W=Object.create;var A=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var J=(e,r)=>{for(var s in r)A(e,s,{get:r[s],enumerable:!0})},D=(e,r,s,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of H(r))!N.call(e,n)&&n!==s&&A(e,n,{get:()=>r[n],enumerable:!(a=K(r,n))||a.enumerable});return e};var Q=(e,r,s)=>(s=e!=null?W(U(e)):{},D(r||!e||!e.__esModule?A(s,"default",{value:e,enumerable:!0}):s,e)),X=e=>D(A({},"__esModule",{value:!0}),e);var se={};J(se,{getChecksumBuilder:()=>ue,getDynamicBuilder:()=>$,getLookupFn:()=>C});module.exports=X(se);var C=e=>{let r=new Map,s=new Set,a=p=>t=>{let c=r.get(t);if(c)return c;if(s.has(t)){let l={id:t};return r.set(t,l),l}s.add(t);let m=p(t);return c=r.get(t),c?Object.assign(c,m):(c={id:t,...m},r.set(t,c)),s.delete(t),c},n=!0,o=a(p=>{let{def:t,path:c,params:m}=e[p];if(t.tag==="composite"){if(t.value.length===0)return{type:"void"};if(t.value.length===1)return n&&c.join(",")==="sp_core,crypto,AccountId32"?(n=!1,{type:"AccountId32"}):o(t.value[0].type);let l=!0,v={},i={};return t.value.forEach((d,u)=>{l=l&&!!d.name;let g=d.name||u;v[g]=o(d.type),i[g]=d.docs}),l?{type:"struct",value:v,innerDocs:i}:{type:"tuple",value:Object.values(v),innerDocs:Object.values(i)}}if(t.tag==="variant"){if(c.length===1&&c[0]==="Option"&&m.length===1&&m[0].name==="T"){let i=o(m[0].type);return i.type==="void"?{type:"primitive",value:"bool"}:{type:"option",value:i}}if(c.length===1&&c[0]==="Result"&&m.length===2&&m[0].name==="T"&&m[1].name==="E")return{type:"result",value:{ok:o(m[0].type),ko:o(m[1].type)}};if(t.value.length===0)return{type:"void"};let l={},v={};return t.value.forEach(i=>{let d=i.name;if(v[d]=i.docs,i.fields.length===0){l[d]={type:"void",idx:i.index};return}if(i.fields.length===1&&!i.fields[0].name){l[d]={type:"lookupEntry",value:o(i.fields[0].type),idx:i.index};return}let u=!0,g={},b={};i.fields.forEach((f,h)=>{u=u&&!!f.name;let V=f.name||h;g[V]=o(f.type),b[V]=f.docs}),l[d]=u?{type:"struct",value:g,innerDocs:b,idx:i.index}:{type:"tuple",value:Object.values(g),innerDocs:Object.values(b),idx:i.index}}),{type:"enum",value:l,innerDocs:v}}if(t.tag==="sequence")return{type:"sequence",value:o(t.value)};if(t.tag==="array"){let{len:l}=t.value,v=o(t.value.type);return l===0?{type:"void"}:l===1?v:{type:"array",value:v,len:t.value.len}}if(t.tag==="tuple"){if(t.value.length===0)return{type:"void"};if(t.value.length===1)return o(t.value[0]);let l=t.value.map(d=>o(d)),v=t.value.map(d=>e[d].docs);return l.every(d=>d.id===l[0].id)&&v.every(d=>d.length===0)?{type:"array",value:l[0],len:l.length}:{type:"tuple",value:l,innerDocs:v}}if(t.tag==="primitive")return{type:"primitive",value:t.value.tag};if(t.tag==="compact"){let l=o(t.value);return l.type==="void"?{type:"compact",isBig:null}:{type:"compact",isBig:Number(l.value.slice(1))>32}}return{type:t.tag}});return o};var y=Q(require("@polkadot-api/substrate-bindings"));var I=(e,r,s)=>(a,n,o,...p)=>{let{id:t}=a;if(n.has(t))return n.get(t);if(o.has(t)){let m=r(()=>n.get(t),a,...p);return n.set(t,m),m}o.add(t);let c=e(a,n,o,...p);return o.delete(t),n.has(t)&&(c=s(c,n.get(t),a,...p)),n.set(t,c),c};var M=require("@polkadot-api/utils"),Y=y.Bin(),Z=(e,r,s,a)=>{if(e.type==="primitive")return y[e.value];if(e.type==="void")return y._void;if(e.type==="AccountId32")return a;if(e.type==="compact")return y.compact;if(e.type==="bitSequence")return y.bitSequence;let n=i=>B(i,r,s,a),o=(i,d)=>{let u=n(i);return d?y.Vector(u,d):y.Vector(u)},p=i=>y.Tuple(...i.map(n)),t=i=>{let d=Object.fromEntries(Object.entries(i).map(([u,g])=>[u,n(g)]));return y.Struct(d)};if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return Y;if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?y.Bin(e.len):o(e.value,e.len);if(e.type==="sequence")return o(e.value);if(e.type==="tuple")return p(e.value);if(e.type==="struct")return t(e.value);if(e.type==="option")return y.Option(n(e.value));if(e.type==="result")return y.Result(n(e.value.ok),n(e.value.ko));let c=Object.values(e.value).map(i=>i.type==="void"?y._void:i.type==="lookupEntry"?n(i.value):i.type==="tuple"?p(i.value):t(i.value)),m=Object.fromEntries(Object.keys(e.value).map((i,d)=>[i,c[d]])),l=Object.values(e.value).map(i=>i.idx);return l.every((i,d)=>i===d)?y.Variant(m):y.Variant(m,l)},B=I(Z,y.Self,e=>e),$=e=>{let r=e.lookup,s=C(r),a=y.AccountId(),n=new Map,o=u=>B(s(u),n,new Set,a),p=e.pallets.find(u=>u.name==="System")?.constants.find(u=>u.name==="SS58Prefix"),t;if(p)try{let u=o(p.type).dec(p.value);typeof u=="number"&&(t=u,a=y.AccountId(u))}catch{}let c=new Map,m=(u,g)=>{let b=c.get(u);b||c.set(u,b=y.Storage(u));let f=e.pallets.find(L=>L.name===u).storage.items.find(L=>L.name===g),h=(L,...O)=>{let j=b(...O);return{...j,len:L,fallback:f.modifier===1?j.dec(f.fallback):void 0}};if(f.type.tag==="plain")return h(0,g,o(f.type.value).dec);let{key:V,value:x,hashers:G}=f.type.value,F=o(x),R=G.map(L=>y[L.tag]),z=R.length===1?[[o(V),R[0]]]:s(V).value.map((L,O)=>[o(L.id),R[O]]);return h(R.length,g,F.dec,...z)},l=u=>u.type==="void"?y._void:u.type==="lookupEntry"?o(u.value.id):u.type==="tuple"?y.Tuple(...Object.values(u.value).map(g=>o(g.id))):y.Struct((0,M.mapObject)(u.value,g=>o(g.id))),v=(u,g)=>{let b=e.pallets.find(f=>f.name===u).constants.find(f=>f.name===g);return o(b.type)},i=u=>(g,b)=>{let f=e.pallets.find(x=>x.name===g),h=s(f[u]);if(h.type!=="enum")throw null;let V=h.value[b];return{location:[f.index,V.idx],codec:l(h.value[b])}},d=(u,g)=>{let b=e.apis.find(f=>f.name===u)?.methods.find(f=>f.name===g);if(!b)throw null;return{args:y.Tuple(...b.inputs.map(f=>o(f.type))),value:o(b.output)}};return{buildDefinition:o,buildStorage:m,buildEvent:i("events"),buildError:i("errors"),buildRuntimeCall:d,buildCall:i("calls"),buildConstant:v,ss58Prefix:t}};var q=require("@polkadot-api/substrate-bindings");var P=new TextEncoder,ee=P.encode.bind(P),k=e=>{let r=new Uint8Array(e.length*8),s=new DataView(r.buffer);for(let a=0;a<e.length;a++)s.setBigUint64(a*8,e[a]);return(0,q.h64)(r)},_=e=>k(e.map(r=>(0,q.h64)(ee(r)))),E={primitive:0n,vector:1n,tuple:2n,struct:3n,option:4n,result:5n,enum:6n,void:7n},S={undefined:0n,number:1n,string:2n,bigint:3n,boolean:4n,bitSequence:5n,byteSequence:6n,accountId:7n},te={bool:S.boolean,char:S.string,str:S.string,u8:S.number,u16:S.number,u32:S.number,u64:S.bigint,u128:S.bigint,u256:S.bigint,i8:S.number,i16:S.number,i32:S.number,i64:S.bigint,i128:S.bigint,i256:S.bigint},T=(e,r,s)=>{let a=Object.entries(r).sort(([p],[t])=>p.localeCompare(t)),n=_(a.map(([p])=>p)),o=k(a.map(([,p])=>s(p)));return k([e,n,o])},w=(e,r=new Map)=>{if(r.has(e.id))return r;switch(e.type){case"array":case"option":case"sequence":r.set(e.id,[e,new Set([e.value.id])]),w(e.value,r);break;case"enum":{let s=Object.values(e.value).flatMap(a=>a.type==="void"?[]:a.type==="lookupEntry"?a.value:a.type==="struct"?Object.values(a.value):a.value);r.set(e.id,[e,new Set(s.map(a=>a.id))]),s.forEach(a=>w(a,r));break}case"result":r.set(e.id,[e,new Set([e.value.ok.id,e.value.ko.id])]),w(e.value.ok,r),w(e.value.ko,r);break;case"struct":{let s=Object.values(e.value);r.set(e.id,[e,new Set(s.map(a=>a.id))]),s.forEach(a=>w(a,r));break}case"tuple":r.set(e.id,[e,new Set(e.value.map(s=>s.id))]),e.value.forEach(s=>w(s,r));break;default:r.set(e.id,[e,new Set])}return r},re=(e,r)=>{if(e.type==="primitive")return k([E.primitive,te[e.value]]);if(e.type==="void")return k([E.void]);if(e.type==="compact")return k([E.primitive,S[e.isBig||e.isBig===null?"bigint":"number"]]);if(e.type==="bitSequence")return k([E.primitive,S.bitSequence]);if(e.type==="AccountId32")return k([E.primitive,S.accountId]);if(e.type==="array"){let n=e.value;if(n.type==="primitive"&&n.value==="u8")return k([E.primitive,S.byteSequence,BigInt(e.len)]);let o=r(n);return k([E.vector,o,BigInt(e.len)])}if(e.type==="sequence"){let n=e.value;if(n.type==="primitive"&&n.value==="u8")return k([E.primitive,S.byteSequence]);let o=r(n);return k([E.vector,o])}let s=n=>k([E.tuple,...n.map(r)]),a=n=>T(E.struct,n,r);return e.type==="tuple"?s(e.value):e.type==="struct"?a(e.value):e.type==="option"?k([E.option,r(e.value)]):e.type==="result"?k([E.result,r(e.value.ok),r(e.value.ko)]):T(E.enum,e.value,n=>{if(n.type==="lookupEntry")return r(n.value);switch(n.type){case"void":return k([E.void]);case"tuple":return s(n.value);case"struct":return a(n.value)}})},ne=e=>{let r=new Map,s=0,a=[],n=[];function o(p){let t={index:s,lowLink:s,onStack:!0};r.set(p,t),s++,a.push(p);let c=e.get(p)[1];for(let m of c){let l=r.get(m);l?l.onStack&&(t.lowLink=Math.min(t.lowLink,l.index)):(o(m),t.lowLink=Math.min(t.lowLink,r.get(m).lowLink))}if(t.lowLink===t.index){let m=new Set,l=-1;do l=a.pop(),r.get(l).onStack=!1,m.add(l);while(l!==p);m.size>1&&n.push(m)}}for(let p of e.keys())r.has(p)||o(p);return n},oe=e=>{let r=new Set(e.map((n,o)=>o)),s=new Map(e.map((n,o)=>[o,new Set]));e.forEach((n,o)=>{e.slice(o+1).forEach((p,t)=>{let c=t+o+1;new Set([...n,...p]).size!==n.size+p.size&&(s.get(o).add(c),s.get(c).add(o))})});let a=[];for(;r.size;){let n=new Set,o=[r.values().next().value];for(;o.length;){let p=o.pop();if(!r.has(p))continue;r.delete(p),e[p].forEach(c=>n.add(Number(c))),s.get(p).forEach(c=>o.push(c))}a.push(n)}return a},ie=(e,r)=>{let s=o=>{let p=o.values().next().value,t=r.get(p)[0];return Array.from(w(t).keys())},a=new Array;function n(o){a.includes(o)||(e.filter(t=>t!==o&&s(o).some(c=>t.has(c))).forEach(t=>n(t)),a.includes(o))||a.push(o)}return e.forEach(o=>n(o)),a},ae=(e,r)=>{if(r.has(e.id))return r.get(e.id);let s=w(e),a=ne(s),n=oe(a),o=ie(n,s),p=(t,c,m=!1)=>{if(!m&&r.has(t.id))return r.get(t.id);let l=re(t,v=>p(v,c));return c(t.id,l),l};return o.forEach(t=>{t.forEach(c=>r.set(c,0n));for(let c=0;c<t.size;c++){let m=new Map;t.forEach(l=>p(s.get(l)[0],(v,i)=>{(t.has(v)?m:r).set(v,i)},!0)),Array.from(m.entries()).forEach(([l,v])=>r.set(l,v))}}),p(e,(t,c)=>r.set(t,c))},ue=e=>{let r=e.lookup,s=C(r),a=new Map,n=i=>ae(s(i),a),o=(i,d)=>{try{let u=e.pallets.find(V=>V.name===i).storage.items.find(V=>V.name===d);if(u.type.tag==="plain")return n(u.type.value);let{key:g,value:b}=u.type.value,f=n(b),h=n(g);return k([f,h])}catch{return null}},p=(i,d)=>{try{let u=e.apis.find(h=>h.name===i)?.methods.find(h=>h.name===d);if(!u)throw null;let g=_(u.inputs.map(h=>h.name)),b=k(u.inputs.map(h=>n(h.type))),f=n(u.output);return k([g,b,f])}catch{return null}},t=i=>{if(i.type==="void")return k([0n]);if(i.type==="tuple"){let d=Object.values(i.value).map(u=>n(u.id));return k([E.tuple,...d])}return T(E.struct,i.value,d=>n(d.id))},c=i=>T(E.tuple,i.value,d=>n(d.id)),m=i=>(d,u)=>{try{let g=e.pallets.find(h=>h.name===d),b=s(g[i]);if(n(b.id),b.type!=="enum")throw null;let f=b.value[u];return f.type==="lookupEntry"?n(f.value.id):t(f)}catch{return null}},l=(i,d)=>{try{let u=e.pallets.find(g=>g.name===i).constants.find(g=>g.name===d);return n(u.type)}catch{return null}},v=i=>(...d)=>i(...d)?.toString(32)??null;return{buildDefinition:v(n),buildRuntimeCall:v(p),buildStorage:v(o),buildCall:v(m("calls")),buildEvent:v(m("events")),buildError:v(m("errors")),buildConstant:v(l),buildComposite:v(t),buildNamedTuple:v(c),getAllGeneratedChecksums:()=>Array.from(a.values()).map(i=>i.toString(32))}}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@polkadot-api/metadata-builders", | ||
"version": "0.0.1-b85a35814e64d4ada9f9a09e268b7fe12d887dbb.1.0", | ||
"version": "0.0.1-b8785fd7807321e74707adbc1405318c0d8a5587.1.0", | ||
"author": "Josep M Sobrepere (https://github.com/josepot)", | ||
@@ -43,7 +43,7 @@ "repository": { | ||
"dependencies": { | ||
"@polkadot-api/substrate-bindings": "0.0.1-b85a35814e64d4ada9f9a09e268b7fe12d887dbb.1.0", | ||
"@polkadot-api/utils": "0.0.1-b85a35814e64d4ada9f9a09e268b7fe12d887dbb.1.0" | ||
"@polkadot-api/substrate-bindings": "0.0.1-b8785fd7807321e74707adbc1405318c0d8a5587.1.0", | ||
"@polkadot-api/utils": "0.0.1-b8785fd7807321e74707adbc1405318c0d8a5587.1.0" | ||
}, | ||
"devDependencies": { | ||
"@polkadot-api/metadata-fixtures": "0.0.1-b85a35814e64d4ada9f9a09e268b7fe12d887dbb.1.0" | ||
"@polkadot-api/metadata-fixtures": "0.0.1-b8785fd7807321e74707adbc1405318c0d8a5587.1.0" | ||
}, | ||
@@ -50,0 +50,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
240885
11
1850
+ Added@polkadot-api/substrate-bindings@0.0.1-b8785fd7807321e74707adbc1405318c0d8a5587.1.0(transitive)
+ Added@polkadot-api/utils@0.0.1-b8785fd7807321e74707adbc1405318c0d8a5587.1.0(transitive)
- Removed@polkadot-api/substrate-bindings@0.0.1-b85a35814e64d4ada9f9a09e268b7fe12d887dbb.1.0(transitive)
- Removed@polkadot-api/utils@0.0.1-b85a35814e64d4ada9f9a09e268b7fe12d887dbb.1.0(transitive)
Updated@polkadot-api/substrate-bindings@0.0.1-b8785fd7807321e74707adbc1405318c0d8a5587.1.0
Updated@polkadot-api/utils@0.0.1-b8785fd7807321e74707adbc1405318c0d8a5587.1.0