Adjust PortableRegistry (#3811)
* Adjust PortableRegistry * Adjust formatting * Additional formatting picks * Readability * Replacement comment
This commit is contained in:
@@ -25,14 +25,14 @@ import type { ApprovalFlag, DefunctVoter, Renouncing, SetIndex, Vote, VoteIndex,
|
||||
import type { CreatedBlock, ImportedAux } from '@polkadot/types/interfaces/engine';
|
||||
import type { EthAccount, EthBlock, EthBloom, EthCallRequest, EthFilter, EthFilterAddress, EthFilterChanges, EthFilterTopic, EthFilterTopicEntry, EthFilterTopicInner, EthHeader, EthLog, EthReceipt, EthRichBlock, EthRichHeader, EthStorageProof, EthSubKind, EthSubParams, EthSubResult, EthSyncInfo, EthSyncStatus, EthTransaction, EthTransactionAction, EthTransactionCondition, EthTransactionRequest, EthTransactionSignature, EthTransactionStatus, EthWork, EthereumAccountId, EthereumLookupSource, EthereumSignature } from '@polkadot/types/interfaces/eth';
|
||||
import type { EvmAccount, EvmLog, EvmVicinity, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed } from '@polkadot/types/interfaces/evm';
|
||||
import type { AnySignature, EcdsaSignature, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV4, ExtrinsicSignature, ExtrinsicSignatureV4, ExtrinsicUnknown, ExtrinsicV4, ImmortalEra, MortalEra, MultiSignature, Signature, SignerPayload, Sr25519Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
import type { AnySignature, EcdsaSignature, Ed25519Signature, Era, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV4, ExtrinsicSignature, ExtrinsicSignatureV4, ExtrinsicUnknown, ExtrinsicV4, ImmortalEra, MortalEra, MultiSignature, Signature, SignerPayload, Sr25519Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
import type { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from '@polkadot/types/interfaces/genericAsset';
|
||||
import type { ActiveGilt, ActiveGiltsTotal, ActiveIndex, GiltBid } from '@polkadot/types/interfaces/gilt';
|
||||
import type { AuthorityIndex, AuthorityList, AuthoritySet, AuthoritySetChange, AuthoritySetChanges, AuthorityWeight, DelayKind, DelayKindBest, EncodedFinalityProofs, ForkTreePendingChange, ForkTreePendingChangeNode, GrandpaCommit, GrandpaEquivocation, GrandpaEquivocationProof, GrandpaEquivocationValue, GrandpaJustification, GrandpaPrecommit, GrandpaPrevote, GrandpaSignedPrecommit, JustificationNotification, KeyOwnerProof, NextAuthority, PendingChange, PendingPause, PendingResume, Precommits, Prevotes, ReportedRoundStates, RoundState, SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
|
||||
import type { IdentityFields, IdentityInfo, IdentityInfoAdditional, IdentityJudgement, RegistrarIndex, RegistrarInfo, Registration, RegistrationJudgement } from '@polkadot/types/interfaces/identity';
|
||||
import type { AuthIndex, AuthoritySignature, Heartbeat, HeartbeatTo244, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from '@polkadot/types/interfaces/imOnline';
|
||||
import type { CallIndex, LotteryConfig } from '@polkadot/types/interfaces/lottery';
|
||||
import type { ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV9, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV9, ModuleConstantMetadataLatest, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataLatest, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, PalletCallMetadataLatest, PalletCallMetadataV14, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletEventMetadataLatest, PalletEventMetadataV14, PalletMetadataLatest, PalletMetadataV14, PalletStorageMetadataLatest, PalletStorageMetadataV14, PortableRegistry, PortableType, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataLatest, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
|
||||
import type { ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV9, ModuleConstantMetadataLatest, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataLatest, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, PalletCallMetadataLatest, PalletCallMetadataV14, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletEventMetadataLatest, PalletEventMetadataV14, PalletMetadataLatest, PalletMetadataV14, PalletStorageMetadataLatest, PalletStorageMetadataV14, PortableRegistry, PortableType, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataLatest, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
|
||||
import type { MmrLeafProof } from '@polkadot/types/interfaces/mmr';
|
||||
import type { StorageKind } from '@polkadot/types/interfaces/offchain';
|
||||
import type { DeferredOffenceOf, Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
|
||||
@@ -386,6 +386,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<EncodedFinalityProofs>': Option<EncodedFinalityProofs>;
|
||||
'Option<EncodedJustification>': Option<EncodedJustification>;
|
||||
'Option<EpochAuthorship>': Option<EpochAuthorship>;
|
||||
'Option<Era>': Option<Era>;
|
||||
'Option<EraIndex>': Option<EraIndex>;
|
||||
'Option<EraPoints>': Option<EraPoints>;
|
||||
'Option<EraRewardPoints>': Option<EraRewardPoints>;
|
||||
@@ -395,6 +396,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<ErrorMetadataV11>': Option<ErrorMetadataV11>;
|
||||
'Option<ErrorMetadataV12>': Option<ErrorMetadataV12>;
|
||||
'Option<ErrorMetadataV13>': Option<ErrorMetadataV13>;
|
||||
'Option<ErrorMetadataV14>': Option<ErrorMetadataV14>;
|
||||
'Option<ErrorMetadataV9>': Option<ErrorMetadataV9>;
|
||||
'Option<EthAccount>': Option<EthAccount>;
|
||||
'Option<EthBlock>': Option<EthBlock>;
|
||||
@@ -436,6 +438,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<EventMetadataV11>': Option<EventMetadataV11>;
|
||||
'Option<EventMetadataV12>': Option<EventMetadataV12>;
|
||||
'Option<EventMetadataV13>': Option<EventMetadataV13>;
|
||||
'Option<EventMetadataV14>': Option<EventMetadataV14>;
|
||||
'Option<EventMetadataV9>': Option<EventMetadataV9>;
|
||||
'Option<EventRecord>': Option<EventRecord>;
|
||||
'Option<EvmAccount>': Option<EvmAccount>;
|
||||
@@ -483,12 +486,14 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<FunctionArgumentMetadataV11>': Option<FunctionArgumentMetadataV11>;
|
||||
'Option<FunctionArgumentMetadataV12>': Option<FunctionArgumentMetadataV12>;
|
||||
'Option<FunctionArgumentMetadataV13>': Option<FunctionArgumentMetadataV13>;
|
||||
'Option<FunctionArgumentMetadataV14>': Option<FunctionArgumentMetadataV14>;
|
||||
'Option<FunctionArgumentMetadataV9>': Option<FunctionArgumentMetadataV9>;
|
||||
'Option<FunctionMetadataLatest>': Option<FunctionMetadataLatest>;
|
||||
'Option<FunctionMetadataV10>': Option<FunctionMetadataV10>;
|
||||
'Option<FunctionMetadataV11>': Option<FunctionMetadataV11>;
|
||||
'Option<FunctionMetadataV12>': Option<FunctionMetadataV12>;
|
||||
'Option<FunctionMetadataV13>': Option<FunctionMetadataV13>;
|
||||
'Option<FunctionMetadataV14>': Option<FunctionMetadataV14>;
|
||||
'Option<FunctionMetadataV9>': Option<FunctionMetadataV9>;
|
||||
'Option<FundIndex>': Option<FundIndex>;
|
||||
'Option<FundInfo>': Option<FundInfo>;
|
||||
@@ -1299,6 +1304,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Vec<EncodedFinalityProofs>': Vec<EncodedFinalityProofs>;
|
||||
'Vec<EncodedJustification>': Vec<EncodedJustification>;
|
||||
'Vec<EpochAuthorship>': Vec<EpochAuthorship>;
|
||||
'Vec<Era>': Vec<Era>;
|
||||
'Vec<EraIndex>': Vec<EraIndex>;
|
||||
'Vec<EraPoints>': Vec<EraPoints>;
|
||||
'Vec<EraRewardPoints>': Vec<EraRewardPoints>;
|
||||
@@ -1308,6 +1314,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Vec<ErrorMetadataV11>': Vec<ErrorMetadataV11>;
|
||||
'Vec<ErrorMetadataV12>': Vec<ErrorMetadataV12>;
|
||||
'Vec<ErrorMetadataV13>': Vec<ErrorMetadataV13>;
|
||||
'Vec<ErrorMetadataV14>': Vec<ErrorMetadataV14>;
|
||||
'Vec<ErrorMetadataV9>': Vec<ErrorMetadataV9>;
|
||||
'Vec<EthAccount>': Vec<EthAccount>;
|
||||
'Vec<EthBlock>': Vec<EthBlock>;
|
||||
@@ -1349,6 +1356,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Vec<EventMetadataV11>': Vec<EventMetadataV11>;
|
||||
'Vec<EventMetadataV12>': Vec<EventMetadataV12>;
|
||||
'Vec<EventMetadataV13>': Vec<EventMetadataV13>;
|
||||
'Vec<EventMetadataV14>': Vec<EventMetadataV14>;
|
||||
'Vec<EventMetadataV9>': Vec<EventMetadataV9>;
|
||||
'Vec<EventRecord>': Vec<EventRecord>;
|
||||
'Vec<EvmAccount>': Vec<EvmAccount>;
|
||||
@@ -1396,12 +1404,14 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Vec<FunctionArgumentMetadataV11>': Vec<FunctionArgumentMetadataV11>;
|
||||
'Vec<FunctionArgumentMetadataV12>': Vec<FunctionArgumentMetadataV12>;
|
||||
'Vec<FunctionArgumentMetadataV13>': Vec<FunctionArgumentMetadataV13>;
|
||||
'Vec<FunctionArgumentMetadataV14>': Vec<FunctionArgumentMetadataV14>;
|
||||
'Vec<FunctionArgumentMetadataV9>': Vec<FunctionArgumentMetadataV9>;
|
||||
'Vec<FunctionMetadataLatest>': Vec<FunctionMetadataLatest>;
|
||||
'Vec<FunctionMetadataV10>': Vec<FunctionMetadataV10>;
|
||||
'Vec<FunctionMetadataV11>': Vec<FunctionMetadataV11>;
|
||||
'Vec<FunctionMetadataV12>': Vec<FunctionMetadataV12>;
|
||||
'Vec<FunctionMetadataV13>': Vec<FunctionMetadataV13>;
|
||||
'Vec<FunctionMetadataV14>': Vec<FunctionMetadataV14>;
|
||||
'Vec<FunctionMetadataV9>': Vec<FunctionMetadataV9>;
|
||||
'Vec<FundIndex>': Vec<FundIndex>;
|
||||
'Vec<FundInfo>': Vec<FundInfo>;
|
||||
@@ -2212,6 +2222,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
EncodedFinalityProofs: EncodedFinalityProofs;
|
||||
EncodedJustification: EncodedJustification;
|
||||
EpochAuthorship: EpochAuthorship;
|
||||
Era: Era;
|
||||
EraIndex: EraIndex;
|
||||
EraPoints: EraPoints;
|
||||
EraRewardPoints: EraRewardPoints;
|
||||
@@ -2221,6 +2232,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
ErrorMetadataV11: ErrorMetadataV11;
|
||||
ErrorMetadataV12: ErrorMetadataV12;
|
||||
ErrorMetadataV13: ErrorMetadataV13;
|
||||
ErrorMetadataV14: ErrorMetadataV14;
|
||||
ErrorMetadataV9: ErrorMetadataV9;
|
||||
EthAccount: EthAccount;
|
||||
EthBlock: EthBlock;
|
||||
@@ -2262,6 +2274,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
EventMetadataV11: EventMetadataV11;
|
||||
EventMetadataV12: EventMetadataV12;
|
||||
EventMetadataV13: EventMetadataV13;
|
||||
EventMetadataV14: EventMetadataV14;
|
||||
EventMetadataV9: EventMetadataV9;
|
||||
EventRecord: EventRecord;
|
||||
EvmAccount: EvmAccount;
|
||||
@@ -2309,12 +2322,14 @@ declare module '@polkadot/types/types/registry' {
|
||||
FunctionArgumentMetadataV11: FunctionArgumentMetadataV11;
|
||||
FunctionArgumentMetadataV12: FunctionArgumentMetadataV12;
|
||||
FunctionArgumentMetadataV13: FunctionArgumentMetadataV13;
|
||||
FunctionArgumentMetadataV14: FunctionArgumentMetadataV14;
|
||||
FunctionArgumentMetadataV9: FunctionArgumentMetadataV9;
|
||||
FunctionMetadataLatest: FunctionMetadataLatest;
|
||||
FunctionMetadataV10: FunctionMetadataV10;
|
||||
FunctionMetadataV11: FunctionMetadataV11;
|
||||
FunctionMetadataV12: FunctionMetadataV12;
|
||||
FunctionMetadataV13: FunctionMetadataV13;
|
||||
FunctionMetadataV14: FunctionMetadataV14;
|
||||
FunctionMetadataV9: FunctionMetadataV9;
|
||||
FundIndex: FundIndex;
|
||||
FundInfo: FundInfo;
|
||||
|
||||
@@ -18,7 +18,7 @@ export class DoNotConstruct implements Codec {
|
||||
|
||||
constructor (registry: Registry, typeName = 'DoNotConstruct') {
|
||||
this.registry = registry;
|
||||
this.#neverError = new Error(`Cannot construct unknown type ${typeName}`);
|
||||
this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
|
||||
|
||||
throw this.#neverError;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ function encodeStruct (registry: Registry, typeDef: TypeDef): string {
|
||||
return encodeSubTypes(registry, typeDef.sub, false, {
|
||||
...(
|
||||
typeDef.alias
|
||||
? { alias: [...typeDef.alias.entries()].reduce<Record<string, string>>((all, [k, v]) => ({
|
||||
? { _alias: [...typeDef.alias.entries()].reduce<Record<string, string>>((all, [k, v]) => ({
|
||||
...all,
|
||||
[k]: v
|
||||
}), {}) }
|
||||
@@ -153,12 +153,14 @@ const encoders: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef) => st
|
||||
encodeVecFixed(registry, typeDef)
|
||||
};
|
||||
|
||||
function encodeType (registry: Registry, typeDef: TypeDef): string {
|
||||
function encodeType (registry: Registry, typeDef: TypeDef, withLookup = true): string {
|
||||
const encoder = encoders[typeDef.info];
|
||||
|
||||
assert(encoder, () => `Cannot encode type ${stringify(typeDef)}`);
|
||||
|
||||
return typeDef.lookupName || encoder(registry, typeDef);
|
||||
return withLookup && typeDef.lookupName
|
||||
? typeDef.lookupName
|
||||
: encoder(registry, typeDef);
|
||||
}
|
||||
|
||||
export function encodeTypeDef (registry: Registry, typeDef: TypeDef): string {
|
||||
@@ -175,13 +177,8 @@ export function encodeTypeDef (registry: Registry, typeDef: TypeDef): string {
|
||||
}
|
||||
|
||||
export function withTypeString (registry: Registry, typeDef: Omit<TypeDef, 'type'>): TypeDef {
|
||||
const partial = { ...typeDef } as TypeDef;
|
||||
|
||||
// for the outer-most type, we ignore the lookupName
|
||||
delete partial.lookupName;
|
||||
|
||||
return {
|
||||
...typeDef,
|
||||
type: encodeType(registry, partial)
|
||||
type: encodeType(registry, typeDef as TypeDef, false)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ export interface TypeDef {
|
||||
length?: number;
|
||||
lookupIndex?: number;
|
||||
lookupName?: string;
|
||||
lookupNameRoot?: string;
|
||||
name?: string;
|
||||
namespace?: string;
|
||||
sub?: TypeDef | TypeDef[];
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { Vec } from '../codec/Vec';
|
||||
import type { PortableType } from '../interfaces/metadata';
|
||||
import type { SiField, SiLookupTypeId, SiType, SiTypeDefArray, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiVariant } from '../interfaces/scaleInfo';
|
||||
import type { SiField, SiLookupTypeId, SiPath, SiType, SiTypeDefArray, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiVariant } from '../interfaces/scaleInfo';
|
||||
import type { Type } from '../primitive/Type';
|
||||
import type { Registry, TypeDef } from '../types';
|
||||
|
||||
@@ -25,14 +25,16 @@ const PRIMITIVE_INK = ['AccountId', 'AccountIndex', 'Address', 'Balance'];
|
||||
|
||||
// These are types where we have a specific decoding/encoding override + helpers
|
||||
const PRIMITIVE_SP = [
|
||||
'node_runtime::Call',
|
||||
'node_runtime::Event',
|
||||
'sp_arithmetic::per_things::*',
|
||||
'sp_core::crypto::AccountId32',
|
||||
'sp_runtime::generic::era::Era',
|
||||
'sp_runtime::multiaddress::MultiAddress',
|
||||
'pallet_democracy::vote::Vote',
|
||||
'pallet_identity::types::Data',
|
||||
'primitive_types::H160',
|
||||
'primitive_types::H256',
|
||||
'primitive_types::H512'
|
||||
'pallet_identity::types::IdentityFields',
|
||||
'primitive_types::*'
|
||||
];
|
||||
|
||||
// These we never use these as top-level names, they are wrappers
|
||||
@@ -41,33 +43,84 @@ const WRAPPERS = ['Box', 'BTreeMap', 'Cow', 'Result', 'Option'];
|
||||
// These are reserved and conflicts with built-in Codec definitions
|
||||
const RESERVED = ['entries', 'hash', 'keys', 'size'];
|
||||
|
||||
// check if the path matches the PRIMITIVE_SP (with wildcards)
|
||||
function isPrimitivePath (path: SiPath): boolean {
|
||||
return !!path.length && (
|
||||
(
|
||||
path.length > 2 &&
|
||||
path[0].eq('ink_env') &&
|
||||
path[1].eq('types')
|
||||
) ||
|
||||
PRIMITIVE_INK.includes(path[path.length - 1].toString()) ||
|
||||
PRIMITIVE_SP
|
||||
.map((p) => p.split('::'))
|
||||
.some((parts) =>
|
||||
path.length === parts.length &&
|
||||
parts.every((p, index) =>
|
||||
p === '*' ||
|
||||
path[index].eq(p)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function removeDuplicateNames (names: (string | null)[]): (string | null)[] {
|
||||
return names.map((name, index): string | null =>
|
||||
!name || names.some((o, i) => index !== i && name === o)
|
||||
!name || WRAPPERS.includes(name) || names.some((o, i) => index !== i && name === o)
|
||||
? null
|
||||
: name
|
||||
);
|
||||
}
|
||||
|
||||
function extractName (types: PortableType[], { def, params, path }: SiType): string | null {
|
||||
if (def.isCompact) {
|
||||
// Do magic for compact naming
|
||||
const instanceType = types[def.asCompact.type.toNumber()];
|
||||
|
||||
if (instanceType.type.def.isPrimitive) {
|
||||
return `Compact${instanceType.type.def.asPrimitive.toString()}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (!path.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const parts = path.map((p) => stringUpperFirst(stringCamelCase(p)));
|
||||
|
||||
// sp_runtime::generic::digest::Digest -> sp_runtime::generic::Digest
|
||||
// sp_runtime::multiaddress::MultiAddress -> sp_runtime::MultiAddress
|
||||
if (parts.length >= 2 && parts[parts.length - 1].toLowerCase() === parts[parts.length - 2].toLowerCase()) {
|
||||
parts[parts.length - 2] = parts[parts.length - 1];
|
||||
parts.pop();
|
||||
}
|
||||
|
||||
let typeName = parts.join('');
|
||||
|
||||
if (parts.length === 2 && parts[parts.length - 1] === 'RawOrigin' && params.length === 2 && params[1].type.isSome) {
|
||||
// Do magic for RawOrigin lookup
|
||||
const instanceType = types[params[1].type.unwrap().toNumber()];
|
||||
|
||||
if (instanceType.type.path.length === 2) {
|
||||
typeName = `${typeName}${instanceType.type.path[1].toString()}`;
|
||||
}
|
||||
} else if (params.length === 1 && params[0].type.isSome) {
|
||||
// Do magic for single params primitive lookup
|
||||
const instanceType = types[params[0].type.unwrap().toNumber()];
|
||||
|
||||
if (instanceType.type.def.isPrimitive) {
|
||||
typeName = `${typeName}${instanceType.type.def.asPrimitive.toString()}`;
|
||||
}
|
||||
}
|
||||
|
||||
return typeName;
|
||||
}
|
||||
|
||||
function extractNames (types: PortableType[]): Record<number, string> {
|
||||
return removeDuplicateNames(
|
||||
types.map(({ type: { path } }): string | null => {
|
||||
if (!path.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const parts = path.map((p) => stringUpperFirst(stringCamelCase(p)));
|
||||
|
||||
if (parts.length >= 2 && parts[parts.length - 1] === parts[parts.length - 2]) {
|
||||
parts.pop();
|
||||
}
|
||||
|
||||
const typeName = parts.join('');
|
||||
|
||||
return WRAPPERS.includes(typeName) || ['frame_support'].includes(path[0].toString())
|
||||
? null
|
||||
: typeName;
|
||||
})
|
||||
types.map(({ type }) =>
|
||||
extractName(types, type)
|
||||
)
|
||||
).reduce<Record<number, string>>((all, name, index) => {
|
||||
if (name) {
|
||||
all[index] = name;
|
||||
@@ -124,10 +177,18 @@ export class GenericPortableRegistry extends Struct {
|
||||
|
||||
const extracted = this.#extract(this.getSiType(lookupId), lookupIndex);
|
||||
|
||||
Object.keys(extracted).forEach((key): void => {
|
||||
// these are safe since we are looking through the keys as set
|
||||
this.#typeDefs[lookupIndex][key as 'info'] = extracted[key as 'info'];
|
||||
Object.keys(extracted).forEach((k): void => {
|
||||
if (k !== 'lookupName' || extracted[k]) {
|
||||
// these are safe since we are looking through the keys as set
|
||||
this.#typeDefs[lookupIndex][k as 'info'] = extracted[k as 'info'];
|
||||
}
|
||||
});
|
||||
|
||||
// don't set lookupName on lower-level, we want to always direct to the type
|
||||
if (extracted.info === TypeDefInfo.Plain) {
|
||||
this.#typeDefs[lookupIndex].lookupNameRoot = this.#typeDefs[lookupIndex].lookupName;
|
||||
delete this.#typeDefs[lookupIndex].lookupName;
|
||||
}
|
||||
}
|
||||
|
||||
return this.#typeDefs[lookupIndex];
|
||||
@@ -138,7 +199,7 @@ export class GenericPortableRegistry extends Struct {
|
||||
const lookupIndex = lookupId.toNumber();
|
||||
|
||||
// Setup for a lookup on complex types
|
||||
return [TypeDefInfo.Enum, TypeDefInfo.Struct].includes(typeDef.info)
|
||||
return [TypeDefInfo.Enum, TypeDefInfo.Struct].includes(typeDef.info) && typeDef.lookupName
|
||||
? {
|
||||
docs: typeDef.docs,
|
||||
info: TypeDefInfo.Si,
|
||||
@@ -163,21 +224,10 @@ export class GenericPortableRegistry extends Struct {
|
||||
|
||||
#extract (type: SiType, lookupIndex: number): TypeDef {
|
||||
const path = [...type.path];
|
||||
|
||||
// We handle ink! here as well, although we still have a different registry there
|
||||
const isPrimitivePath = !!path.length && (
|
||||
(
|
||||
path.length > 2 &&
|
||||
path[0].eq('ink_env') &&
|
||||
path[1].eq('types')
|
||||
) ||
|
||||
PRIMITIVE_INK.includes(path[path.length - 1].toString()) ||
|
||||
PRIMITIVE_SP.includes(path.join('::'))
|
||||
);
|
||||
let typeDef: TypeDef;
|
||||
|
||||
try {
|
||||
if (isPrimitivePath) {
|
||||
if (isPrimitivePath(type.path)) {
|
||||
typeDef = this.#extractPrimitivePath(lookupIndex, type);
|
||||
} else if (type.def.isArray) {
|
||||
typeDef = this.#extractArray(lookupIndex, type.def.asArray);
|
||||
@@ -330,18 +380,22 @@ export class GenericPortableRegistry extends Struct {
|
||||
}
|
||||
|
||||
#extractPrimitivePath (_: number, type: SiType): TypeDef {
|
||||
const displayName = type.path[type.path.length - 1].toString();
|
||||
|
||||
return {
|
||||
displayName,
|
||||
info: TypeDefInfo.Plain,
|
||||
type: displayName
|
||||
type: type.path[type.path.length - 1].toString()
|
||||
};
|
||||
}
|
||||
|
||||
#extractSequence (lookupIndex: number, { type }: SiTypeDefSequence): TypeDef {
|
||||
const sub = this.#createSiDef(type);
|
||||
|
||||
if (sub.type === 'u8') {
|
||||
return {
|
||||
info: TypeDefInfo.Plain,
|
||||
type: 'Bytes'
|
||||
};
|
||||
}
|
||||
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Vec,
|
||||
lookupIndex,
|
||||
|
||||
@@ -20,6 +20,7 @@ export default {
|
||||
ExtrinsicPayloadUnknown: 'GenericExtrinsicPayloadUnknown',
|
||||
|
||||
// eras
|
||||
Era: 'ExtrinsicEra',
|
||||
ImmortalEra: 'GenericImmortalEra',
|
||||
MortalEra: 'GenericMortalEra',
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ export interface EcdsaSignature extends U8aFixed {}
|
||||
/** @name Ed25519Signature */
|
||||
export interface Ed25519Signature extends H512 {}
|
||||
|
||||
/** @name Era */
|
||||
export interface Era extends ExtrinsicEra {}
|
||||
|
||||
/** @name Extrinsic */
|
||||
export interface Extrinsic extends GenericExtrinsic {}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* eslint-disable */
|
||||
|
||||
import type { Bytes, Enum, GenericPortableRegistry, Option, Struct, Text, Type, Vec, bool, u8 } from '@polkadot/types';
|
||||
import type { SiLookupTypeId, SiType } from '@polkadot/types/interfaces/scaleInfo';
|
||||
import type { SiField, SiLookupTypeId, SiType } from '@polkadot/types/interfaces/scaleInfo';
|
||||
|
||||
/** @name ErrorMetadataLatest */
|
||||
export interface ErrorMetadataLatest extends ErrorMetadataV13 {}
|
||||
@@ -19,6 +19,15 @@ export interface ErrorMetadataV12 extends ErrorMetadataV11 {}
|
||||
/** @name ErrorMetadataV13 */
|
||||
export interface ErrorMetadataV13 extends ErrorMetadataV12 {}
|
||||
|
||||
/** @name ErrorMetadataV14 */
|
||||
export interface ErrorMetadataV14 extends Struct {
|
||||
readonly name: Text;
|
||||
readonly fields: Vec<SiField>;
|
||||
readonly index: u8;
|
||||
readonly docs: Vec<Text>;
|
||||
readonly args: Vec<Type>;
|
||||
}
|
||||
|
||||
/** @name ErrorMetadataV9 */
|
||||
export interface ErrorMetadataV9 extends Struct {
|
||||
readonly name: Text;
|
||||
@@ -40,6 +49,15 @@ export interface EventMetadataV12 extends EventMetadataV11 {}
|
||||
/** @name EventMetadataV13 */
|
||||
export interface EventMetadataV13 extends EventMetadataV12 {}
|
||||
|
||||
/** @name EventMetadataV14 */
|
||||
export interface EventMetadataV14 extends Struct {
|
||||
readonly name: Text;
|
||||
readonly fields: Vec<SiField>;
|
||||
readonly index: u8;
|
||||
readonly docs: Vec<Text>;
|
||||
readonly args: Vec<Type>;
|
||||
}
|
||||
|
||||
/** @name EventMetadataV9 */
|
||||
export interface EventMetadataV9 extends Struct {
|
||||
readonly name: Text;
|
||||
@@ -84,6 +102,9 @@ export interface FunctionArgumentMetadataV12 extends FunctionArgumentMetadataV11
|
||||
/** @name FunctionArgumentMetadataV13 */
|
||||
export interface FunctionArgumentMetadataV13 extends FunctionArgumentMetadataV12 {}
|
||||
|
||||
/** @name FunctionArgumentMetadataV14 */
|
||||
export interface FunctionArgumentMetadataV14 extends FunctionArgumentMetadataV13 {}
|
||||
|
||||
/** @name FunctionArgumentMetadataV9 */
|
||||
export interface FunctionArgumentMetadataV9 extends Struct {
|
||||
readonly name: Text;
|
||||
@@ -105,6 +126,15 @@ export interface FunctionMetadataV12 extends FunctionMetadataV11 {}
|
||||
/** @name FunctionMetadataV13 */
|
||||
export interface FunctionMetadataV13 extends FunctionMetadataV12 {}
|
||||
|
||||
/** @name FunctionMetadataV14 */
|
||||
export interface FunctionMetadataV14 extends Struct {
|
||||
readonly name: Text;
|
||||
readonly fields: Vec<SiField>;
|
||||
readonly index: u8;
|
||||
readonly docs: Vec<Text>;
|
||||
readonly args: Vec<FunctionArgumentMetadataLatest>;
|
||||
}
|
||||
|
||||
/** @name FunctionMetadataV9 */
|
||||
export interface FunctionMetadataV9 extends Struct {
|
||||
readonly name: Text;
|
||||
@@ -405,9 +435,20 @@ export interface StorageEntryTypeV10 extends Enum {
|
||||
readonly isPlain: boolean;
|
||||
readonly asPlain: Type;
|
||||
readonly isMap: boolean;
|
||||
readonly asMap: { hasher: StorageHasherV10; key: Type; value: Type; linked: bool; } & Struct;
|
||||
readonly asMap: {
|
||||
readonly hasher: StorageHasherV10;
|
||||
readonly key: Type;
|
||||
readonly value: Type;
|
||||
readonly linked: bool;
|
||||
} & Struct;
|
||||
readonly isDoubleMap: boolean;
|
||||
readonly asDoubleMap: { hasher: StorageHasherV10; key1: Type; key2: Type; value: Type; key2Hasher: StorageHasherV10; } & Struct;
|
||||
readonly asDoubleMap: {
|
||||
readonly hasher: StorageHasherV10;
|
||||
readonly key1: Type;
|
||||
readonly key2: Type;
|
||||
readonly value: Type;
|
||||
readonly key2Hasher: StorageHasherV10;
|
||||
} & Struct;
|
||||
}
|
||||
|
||||
/** @name StorageEntryTypeV11 */
|
||||
@@ -415,9 +456,20 @@ export interface StorageEntryTypeV11 extends Enum {
|
||||
readonly isPlain: boolean;
|
||||
readonly asPlain: Type;
|
||||
readonly isMap: boolean;
|
||||
readonly asMap: { hasher: StorageHasherV11; key: Type; value: Type; linked: bool; } & Struct;
|
||||
readonly asMap: {
|
||||
readonly hasher: StorageHasherV11;
|
||||
readonly key: Type;
|
||||
readonly value: Type;
|
||||
readonly linked: bool;
|
||||
} & Struct;
|
||||
readonly isDoubleMap: boolean;
|
||||
readonly asDoubleMap: { hasher: StorageHasherV11; key1: Type; key2: Type; value: Type; key2Hasher: StorageHasherV11; } & Struct;
|
||||
readonly asDoubleMap: {
|
||||
readonly hasher: StorageHasherV11;
|
||||
readonly key1: Type;
|
||||
readonly key2: Type;
|
||||
readonly value: Type;
|
||||
readonly key2Hasher: StorageHasherV11;
|
||||
} & Struct;
|
||||
}
|
||||
|
||||
/** @name StorageEntryTypeV12 */
|
||||
@@ -428,11 +480,26 @@ export interface StorageEntryTypeV13 extends Enum {
|
||||
readonly isPlain: boolean;
|
||||
readonly asPlain: Type;
|
||||
readonly isMap: boolean;
|
||||
readonly asMap: { hasher: StorageHasherV13; key: Type; value: Type; linked: bool; } & Struct;
|
||||
readonly asMap: {
|
||||
readonly hasher: StorageHasherV13;
|
||||
readonly key: Type;
|
||||
readonly value: Type;
|
||||
readonly linked: bool;
|
||||
} & Struct;
|
||||
readonly isDoubleMap: boolean;
|
||||
readonly asDoubleMap: { hasher: StorageHasherV13; key1: Type; key2: Type; value: Type; key2Hasher: StorageHasherV13; } & Struct;
|
||||
readonly asDoubleMap: {
|
||||
readonly hasher: StorageHasherV13;
|
||||
readonly key1: Type;
|
||||
readonly key2: Type;
|
||||
readonly value: Type;
|
||||
readonly key2Hasher: StorageHasherV13;
|
||||
} & Struct;
|
||||
readonly isNMap: boolean;
|
||||
readonly asNMap: { keyVec: Vec<Type>; hashers: Vec<StorageHasherV13>; value: Type; } & Struct;
|
||||
readonly asNMap: {
|
||||
readonly keyVec: Vec<Type>;
|
||||
readonly hashers: Vec<StorageHasherV13>;
|
||||
readonly value: Type;
|
||||
} & Struct;
|
||||
}
|
||||
|
||||
/** @name StorageEntryTypeV14 */
|
||||
@@ -440,11 +507,25 @@ export interface StorageEntryTypeV14 extends Enum {
|
||||
readonly isPlain: boolean;
|
||||
readonly asPlain: SiLookupTypeId;
|
||||
readonly isMap: boolean;
|
||||
readonly asMap: { hasher: StorageHasherV14; key: SiLookupTypeId; value: SiLookupTypeId; } & Struct;
|
||||
readonly asMap: {
|
||||
readonly hasher: StorageHasherV14;
|
||||
readonly key: SiLookupTypeId;
|
||||
readonly value: SiLookupTypeId;
|
||||
} & Struct;
|
||||
readonly isDoubleMap: boolean;
|
||||
readonly asDoubleMap: { hasher: StorageHasherV14; key1: SiLookupTypeId; key2: SiLookupTypeId; value: SiLookupTypeId; key2Hasher: StorageHasherV14; } & Struct;
|
||||
readonly asDoubleMap: {
|
||||
readonly hasher: StorageHasherV14;
|
||||
readonly key1: SiLookupTypeId;
|
||||
readonly key2: SiLookupTypeId;
|
||||
readonly value: SiLookupTypeId;
|
||||
readonly key2Hasher: StorageHasherV14;
|
||||
} & Struct;
|
||||
readonly isNMap: boolean;
|
||||
readonly asNMap: { key: SiLookupTypeId; hashers: Vec<StorageHasherV14>; value: SiLookupTypeId; } & Struct;
|
||||
readonly asNMap: {
|
||||
readonly key: SiLookupTypeId;
|
||||
readonly hashers: Vec<StorageHasherV14>;
|
||||
readonly value: SiLookupTypeId;
|
||||
} & Struct;
|
||||
}
|
||||
|
||||
/** @name StorageEntryTypeV9 */
|
||||
@@ -452,9 +533,20 @@ export interface StorageEntryTypeV9 extends Enum {
|
||||
readonly isPlain: boolean;
|
||||
readonly asPlain: Type;
|
||||
readonly isMap: boolean;
|
||||
readonly asMap: { hasher: StorageHasherV9; key: Type; value: Type; linked: bool; } & Struct;
|
||||
readonly asMap: {
|
||||
readonly hasher: StorageHasherV9;
|
||||
readonly key: Type;
|
||||
readonly value: Type;
|
||||
readonly linked: bool;
|
||||
} & Struct;
|
||||
readonly isDoubleMap: boolean;
|
||||
readonly asDoubleMap: { hasher: StorageHasherV9; key1: Type; key2: Type; value: Type; key2Hasher: StorageHasherV9; } & Struct;
|
||||
readonly asDoubleMap: {
|
||||
readonly hasher: StorageHasherV9;
|
||||
readonly key1: Type;
|
||||
readonly key2: Type;
|
||||
readonly value: Type;
|
||||
readonly key2Hasher: StorageHasherV9;
|
||||
} & Struct;
|
||||
}
|
||||
|
||||
/** @name StorageHasher */
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
import type { DefinitionsTypes } from '../../types';
|
||||
|
||||
import { SiVariant } from '../scaleInfo/definitions';
|
||||
|
||||
export const v14: DefinitionsTypes = {
|
||||
// registry
|
||||
PortableRegistry: 'GenericPortableRegistry',
|
||||
@@ -14,6 +16,21 @@ export const v14: DefinitionsTypes = {
|
||||
type: 'SiType'
|
||||
},
|
||||
|
||||
// compatibility with earlier layouts, i.e. don't break previous users
|
||||
ErrorMetadataV14: {
|
||||
...SiVariant,
|
||||
args: 'Vec<Type>'
|
||||
},
|
||||
EventMetadataV14: {
|
||||
...SiVariant,
|
||||
args: 'Vec<Type>'
|
||||
},
|
||||
FunctionArgumentMetadataV14: 'FunctionArgumentMetadataV13',
|
||||
FunctionMetadataV14: {
|
||||
...SiVariant,
|
||||
args: 'Vec<FunctionArgumentMetadataLatest>'
|
||||
},
|
||||
|
||||
// V14
|
||||
ExtrinsicMetadataV14: {
|
||||
type: 'SiLookupTypeId',
|
||||
|
||||
@@ -8,6 +8,13 @@ import { v0 } from './v0';
|
||||
// order important in structs... :)
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
export const SiVariant = {
|
||||
name: 'Text',
|
||||
fields: 'Vec<SiField>',
|
||||
index: 'u8',
|
||||
docs: 'Vec<Text>'
|
||||
};
|
||||
|
||||
export default {
|
||||
rpc: {},
|
||||
types: {
|
||||
@@ -69,11 +76,6 @@ export default {
|
||||
name: 'Text',
|
||||
type: 'Option<SiLookupTypeId>'
|
||||
},
|
||||
SiVariant: {
|
||||
name: 'Text',
|
||||
fields: 'Vec<SiField>',
|
||||
index: 'u8',
|
||||
docs: 'Vec<Text>'
|
||||
}
|
||||
SiVariant
|
||||
}
|
||||
} as Definitions;
|
||||
|
||||
Reference in New Issue
Block a user