Rename Code .registry to .$registry (#5428)

* Adapt $registry getter, deprecate registry

* warnGet adjustments

* Additional adjustments
This commit is contained in:
Jaco
2023-01-19 13:54:34 +02:00
committed by GitHub
parent abc68bf2e2
commit dd6826fadd
47 changed files with 235 additions and 146 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ export function getBlock (instanceId: string, api: DeriveApi): (hash: Uint8Array
])
),
map(([signedBlock, events, [, validators, author]]) =>
createSignedBlockExtended(events.registry, signedBlock, events, validators, author)
createSignedBlockExtended(events.$registry, signedBlock, events, validators, author)
)
)
);
+1 -1
View File
@@ -35,7 +35,7 @@ export function getHeader (instanceId: string, api: DeriveApi): (blockHash: Uint
getAuthorDetails(header, queryAt)
),
map(([header, validators, author]) =>
createHeaderExtended((validators || header).registry, header, validators, author)
createHeaderExtended((validators || header).$registry, header, validators, author)
)
)
);
@@ -39,7 +39,7 @@ export function subscribeNewHeads (instanceId: string, api: DeriveApi): () => Ob
map(([header, validators, author]): HeaderExtended => {
header.$createdAtHash = header.hash;
return createHeaderExtended(header.registry, header, validators, author);
return createHeaderExtended(header.$registry, header, validators, author);
})
)
);
+1 -1
View File
@@ -712,7 +712,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
decorated.sizeAt = decorateMethod((blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable<u64> =>
getQueryAt(blockHash).pipe(
switchMap((q) =>
this._rpcCore.state.getStorageSize(getArgs(args, q.creator.meta.registry), blockHash))));
this._rpcCore.state.getStorageSize(getArgs(args, q.creator.meta.$registry), blockHash))));
// .keys() & .entries() only available on map types
if (creator.iterKey && creator.meta.type.isMap) {
+3 -3
View File
@@ -160,7 +160,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
first(),
switchMap((signingInfo): Observable<RuntimeDispatchInfo> => {
// setup our options (same way as in signAndSend)
const eraOptions = makeEraOptions(api, this.registry, allOptions, signingInfo);
const eraOptions = makeEraOptions(api, this.$registry, allOptions, signingInfo);
const signOptions = makeSignOptions(api, eraOptions, {});
const u8a = this.isSigned
? api.tx(this).signFake(address, signOptions).toU8a()
@@ -244,7 +244,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
return api.derive.tx.signingInfo(address, options.nonce, options.era).pipe(
first(),
mergeMap(async (signingInfo): Promise<UpdateInfo> => {
const eraOptions = makeEraOptions(api, this.registry, options, signingInfo);
const eraOptions = makeEraOptions(api, this.$registry, options, signingInfo);
let updateId = -1;
if (isKeyringPair(account)) {
@@ -316,7 +316,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
throw new Error('No signer specified, either via api.setSigner or via sign options. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.');
}
const payload = this.registry.createTypeUnsafe<SignerPayload>('SignerPayload', [objectSpread({}, options, {
const payload = this.$registry.createTypeUnsafe<SignerPayload>('SignerPayload', [objectSpread({}, options, {
address,
blockNumber: header ? header.number : 0,
method: this.method
+1 -1
View File
@@ -33,7 +33,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes,
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
}, {});
const { lookup, pallets, registry } = meta.asLatest;
const { $registry: registry, lookup, pallets } = meta.asLatest;
const modules = pallets
.filter(({ constants }) => constants.length > 0)
+1 -1
View File
@@ -77,7 +77,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes,
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
}, {});
const { lookup, pallets, registry } = meta.asLatest;
const { $registry: registry, lookup, pallets } = meta.asLatest;
const modules = pallets
.filter(({ events }) => events.isSome)
.map(({ events, name }) => ({
+1 -1
View File
@@ -240,7 +240,7 @@ function generateRegistry (registry: Registry, filtered: [PortableType, TypeDef]
function generateLookup (destDir: string, entries: [string, HexString][]): void {
entries.reduce<string[]>((exclude, [subPath, staticMeta]): string[] => {
const { lookup, registry } = initMeta(staticMeta).metadata.asLatest;
const { $registry: registry, lookup } = initMeta(staticMeta).metadata.asLatest;
const filtered = getFilteredTypes(lookup, exclude);
generateLookupDefs(registry, filtered, destDir, subPath);
+1 -1
View File
@@ -83,7 +83,7 @@ export function generateCallTypes (meta: Metadata, dest: string, extraTypes: Ext
// find the system.Version in metadata
let apis: Apis | null = null;
const { pallets, registry } = meta.asLatest;
const { $registry: registry, pallets } = meta.asLatest;
const sysp = pallets.find(({ name }) => name.eq('System'));
if (sysp) {
+1 -1
View File
@@ -256,7 +256,7 @@ function addConstants ({ lookup, pallets }: MetadataLatest): string {
}
/** @internal */
function addStorage ({ lookup, pallets, registry }: MetadataLatest): string {
function addStorage ({ $registry: registry, lookup, pallets }: MetadataLatest): string {
const { substrate } = getSubstrateStorage(registry);
const moduleSections = pallets
.sort(sortByName)
+8 -4
View File
@@ -16,11 +16,10 @@ import { compareArray, warnGet } from '../utils';
* @noInheritDoc
*/
export abstract class AbstractArray<T extends Codec> extends Array<T> implements IVec<T> {
readonly registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
public $isStorageFallback?: boolean;
readonly $registry: Registry;
/**
* @description This ensures that operators such as clice, filter, map, etc. return
@@ -33,7 +32,7 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
protected constructor (registry: Registry, length: number) {
super(length);
this.registry = registry;
this.$registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
@@ -56,6 +55,11 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
@@ -75,7 +79,7 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
+8 -4
View File
@@ -11,18 +11,17 @@ import { warnGet } from '../utils';
* @description A type extends the Base class, when it holds a value
*/
export abstract class AbstractBase<T extends Codec> implements Codec {
readonly registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
public $isStorageFallback?: boolean;
readonly $registry: Registry;
readonly #raw: T;
protected constructor (registry: Registry, value: T, initialU8aLength?: number) {
this.$initialU8aLength = initialU8aLength;
this.#raw = value;
this.registry = registry;
this.$registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
@@ -45,6 +44,11 @@ export abstract class AbstractBase<T extends Codec> implements Codec {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
@@ -56,7 +60,7 @@ export abstract class AbstractBase<T extends Codec> implements Codec {
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
public get inner (): T {
+10 -6
View File
@@ -74,13 +74,12 @@ function decodeAbstractInt (value: Exclude<AnyNumber, Uint8Array> | Record<strin
* @noInheritDoc
*/
export abstract class AbstractInt extends BN implements INumber {
readonly registry: Registry;
public $createdAtHash?: IU8a;
readonly $encodedLength: number;
public $initialU8aLength?: number;
public $isStorageFallback?: boolean;
readonly $isUnsigned: boolean;
readonly $registry: Registry;
readonly #bitLength: UIntBitLength;
@@ -97,7 +96,7 @@ export abstract class AbstractInt extends BN implements INumber {
: decodeAbstractInt(value, isSigned)
);
this.registry = registry;
this.$registry = registry;
this.#bitLength = bitLength;
this.$encodedLength = this.$initialU8aLength = this.#bitLength / 8;
this.$isUnsigned = !isSigned;
@@ -137,11 +136,16 @@ export abstract class AbstractInt extends BN implements INumber {
return warnGet(this, 'isUnsigned');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/**
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
@@ -228,7 +232,7 @@ export abstract class AbstractInt extends BN implements INumber {
? 'everything'
// FIXME In the case of multiples we need some way of detecting which instance this belongs
// to. as it stands we will always format (incorrectly) against the first token defined
: formatBalance(this, { decimals: this.registry.chainDecimals[0], withSi: true, withUnit: this.registry.chainTokens[0] });
: formatBalance(this, { decimals: this.$registry.chainDecimals[0], withSi: true, withUnit: this.$registry.chainTokens[0] });
}
const [, divisor] = FORMATTERS.find(([type]) => type === rawType) || [];
@@ -267,7 +271,7 @@ export abstract class AbstractInt extends BN implements INumber {
// NOTE In the case of balances, which have a special meaning on the UI
// and can be interpreted differently, return a specific value for it so
// underlying it always matches (no matter which length it actually is)
return this instanceof this.registry.createClassUnsafe('Balance')
return this instanceof this.$registry.createClassUnsafe('Balance')
? 'Balance'
: `${this.$isUnsigned ? 'u' : 'i'}${this.bitLength()}`;
}
+9 -5
View File
@@ -47,17 +47,16 @@ function decodeCompact<T extends INumber> (registry: Registry, Type: CodecClass<
* a number and making the compact representation thereof
*/
export class Compact<T extends INumber> implements ICompact<T> {
readonly registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
public $isStorageFallback?: boolean;
readonly $registry: Registry;
readonly #Type: CodecClass<T>;
readonly #raw: T;
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0, { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
this.registry = registry;
this.$registry = registry;
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
const [raw, decodedLength] = decodeCompact<T>(registry, this.#Type, value);
@@ -86,6 +85,11 @@ export class Compact<T extends INumber> implements ICompact<T> {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
public static with<O extends INumber> (Type: CodecClass<O> | string): CodecClass<Compact<O>> {
let definition: CodecClass<O> | undefined;
@@ -111,7 +115,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
@@ -201,7 +205,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
* @description Returns the base runtime type name for this instance
*/
public toRawType (): string {
return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
return `Compact<${this.$registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
}
/**
@@ -12,7 +12,7 @@ import { warnGet } from '../utils';
* An unknown type that fails on construction with the type info
*/
export class DoNotConstruct implements Codec {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
public $isStorageFallback?: boolean;
@@ -20,7 +20,7 @@ export class DoNotConstruct implements Codec {
#neverError: Error;
constructor (registry: Registry, typeName = 'DoNotConstruct') {
this.registry = registry;
this.$registry = registry;
this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
throw this.#neverError;
@@ -46,6 +46,11 @@ export class DoNotConstruct implements Codec {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
public static with (typeName?: string): CodecClass {
return class extends DoNotConstruct {
constructor (registry: Registry) {
+9 -4
View File
@@ -183,7 +183,7 @@ function decodeEnum (registry: Registry, def: TypesDef, value?: unknown, index?:
* an extension to enum where the value type is determined by the actual index.
*/
export class Enum implements IEnum {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
@@ -206,7 +206,7 @@ export class Enum implements IEnum {
this.$isBasic = isBasic;
this.registry = registry;
this.$registry = registry;
this.#def = def;
this.#isIndexed = isIndexed;
this.#indexes = Object.values(def).map(({ index }) => index);
@@ -233,6 +233,11 @@ export class Enum implements IEnum {
return warnGet(this, 'initialU8aLength');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/** @deprecated Use $isBasic instead. This getter will be removed in a future version */
public get isBasic (): boolean {
return warnGet(this, 'isBasic');
@@ -300,7 +305,7 @@ export class Enum implements IEnum {
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
@@ -455,7 +460,7 @@ export class Enum implements IEnum {
const entries = Object.entries(this.#def);
return typesToMap(this.registry, entries.reduce<[CodecClass[], string[]]>((out, [key, { Type }], i) => {
return typesToMap(this.$registry, entries.reduce<[CodecClass[], string[]]>((out, [key, { Type }], i) => {
out[0][i] = Type;
out[1][i] = key;
+7 -3
View File
@@ -14,16 +14,15 @@ import { warnGet } from '../utils';
* Implements a type that does not contain anything (apart from `null`)
*/
export class Null implements Codec {
readonly registry: Registry;
public $createdAtHash?: IU8a;
readonly $encodedLength = 0;
public $initialU8aLength = 0;
public $isStorageFallback?: boolean;
readonly $isEmpty = true;
readonly $registry: Registry;
constructor (registry: Registry) {
this.registry = registry;
this.$registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
@@ -46,6 +45,11 @@ export class Null implements Codec {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/**
* @description returns a hash of the contents
*/
+10 -5
View File
@@ -66,7 +66,7 @@ function decodeOption (registry: Registry, Type: CodecClass, value?: unknown): C
* with a value if/as required/found.
*/
export class Option<T extends Codec> implements IOption<T> {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
@@ -83,7 +83,7 @@ export class Option<T extends Codec> implements IOption<T> {
: new Type(registry, value.subarray(1))
: decodeOption(registry, Type, value);
this.registry = registry;
this.$registry = registry;
this.#Type = Type;
this.#raw = decoded as T;
@@ -112,6 +112,11 @@ export class Option<T extends Codec> implements IOption<T> {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
public static with<O extends Codec> (Type: CodecClass<O> | string): CodecClass<Option<O>> {
let definition: CodecClass<O> | undefined;
@@ -140,7 +145,7 @@ export class Option<T extends Codec> implements IOption<T> {
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
@@ -238,7 +243,7 @@ export class Option<T extends Codec> implements IOption<T> {
* @description Returns the base runtime type name for this instance
*/
public toRawType (isBare?: boolean): string {
const wrapped = this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType();
const wrapped = this.$registry.getClassName(this.#Type) || new this.#Type(this.$registry).toRawType();
return isBare
? wrapped
@@ -299,6 +304,6 @@ export class Option<T extends Codec> implements IOption<T> {
public unwrapOrDefault (): T {
return this.isSome
? this.unwrap()
: new this.#Type(this.registry);
: new this.#Type(this.$registry);
}
}
+2 -2
View File
@@ -109,7 +109,7 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
public get Types (): string[] {
return this.#Types[1].length
? this.#Types[1]
: this.#Types[0].map((T) => new T(this.registry).toRawType());
: this.#Types[0].map((T) => new T(this.$registry).toRawType());
}
/**
@@ -126,7 +126,7 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
*/
public toRawType (): string {
const types = this.#Types[0].map((T) =>
this.registry.getClassName(T) || new T(this.registry).toRawType()
this.$registry.getClassName(T) || new T(this.$registry).toRawType()
);
return `(${types.join(',')})`;
+2 -2
View File
@@ -115,7 +115,7 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
// convert type first, this removes overhead from the eq
const other = _other instanceof this.#Type
? _other
: new this.#Type(this.registry, _other);
: new this.#Type(this.$registry, _other);
for (let i = 0; i < this.length; i++) {
if (other.eq(this[i])) {
@@ -130,6 +130,6 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
* @description Returns the base runtime type name for this instance
*/
public toRawType (): string {
return `Vec<${this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType()}>`;
return `Vec<${this.$registry.getClassName(this.#Type) || new this.#Type(this.$registry).toRawType()}>`;
}
}
+1 -1
View File
@@ -57,7 +57,7 @@ export class VecFixed<T extends Codec> extends AbstractArray<T> {
* @description The type for the items
*/
public get Type (): string {
return new this.#Type(this.registry).toRawType();
return new this.#Type(this.$registry).toRawType();
}
/**
@@ -70,7 +70,7 @@ function decodeSet<V extends Codec> (registry: Registry, valType: CodecClass<V>
}
export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V> {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
@@ -83,7 +83,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
super(sortSet(values));
this.registry = registry;
this.$registry = registry;
this.$initialU8aLength = decodedLength;
this.#ValClass = ValClass;
}
@@ -108,6 +108,11 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
public static with<V extends Codec> (valType: CodecClass<V> | string): CodecClass<BTreeSet<V>> {
return class extends BTreeSet<V> {
constructor (registry: Registry, value?: Uint8Array | string | Set<any>) {
@@ -133,7 +138,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
* @description Returns a hash of the value
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
@@ -210,7 +215,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
* @description Returns the base runtime type name for this instance
*/
public toRawType (): string {
return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
return `BTreeSet<${this.$registry.getClassName(this.#ValClass) || new this.#ValClass(this.$registry).toRawType()}>`;
}
/**
+9 -4
View File
@@ -94,7 +94,7 @@ function decodeMap<K extends Codec, V extends Codec> (registry: Registry, keyTyp
}
export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V> implements IMap<K, V> {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
@@ -109,7 +109,7 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
super(type === 'BTreeMap' ? sortMap(decoded) : decoded);
this.registry = registry;
this.$registry = registry;
this.$initialU8aLength = decodedLength;
this.#KeyClass = KeyClass;
this.#ValClass = ValClass;
@@ -136,6 +136,11 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
@@ -153,7 +158,7 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
* @description Returns a hash of the value
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
@@ -245,7 +250,7 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
* @description Returns the base runtime type name for this instance
*/
public toRawType (): string {
return `${this.#type}<${this.registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
return `${this.#type}<${this.$registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.$registry).toRawType()},${this.$registry.getClassName(this.#ValClass) || new this.#ValClass(this.$registry).toRawType()}>`;
}
/**
@@ -103,7 +103,7 @@ export class WrapperKeepOpaque<T extends Codec> extends Bytes {
* @description Returns the base runtime type name for this instance
*/
public override toRawType (): string {
return `${this.#opaqueName}<${this.registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.registry).toRawType())}>`;
return `${this.#opaqueName}<${this.$registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.$registry).toRawType())}>`;
}
/**
+8 -3
View File
@@ -15,7 +15,7 @@ import { warnGet } from '../utils';
* @noInheritDoc
*/
export class bool extends Boolean implements Codec {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
readonly $encodedLength = 1;
@@ -31,7 +31,7 @@ export class bool extends Boolean implements Codec {
: !!value
);
this.registry = registry;
this.$registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
@@ -54,11 +54,16 @@ export class bool extends Boolean implements Codec {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/**
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
+8 -3
View File
@@ -36,7 +36,7 @@ function decodeDate (value: CodecDate | Date | AnyNumber): Date {
* @noInheritDoc
*/
export class CodecDate extends Date implements INumber {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
readonly $encodedLength = BITLENGTH / 8;
@@ -46,7 +46,7 @@ export class CodecDate extends Date implements INumber {
constructor (registry: Registry, value: CodecDate | Date | AnyNumber = 0) {
super(decodeDate(value));
this.registry = registry;
this.$registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
@@ -69,11 +69,16 @@ export class CodecDate extends Date implements INumber {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/**
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
+8 -4
View File
@@ -21,12 +21,11 @@ interface Options {
* in some eth_* RPCs
*/
export class Float extends Number implements IFloat {
readonly registry: Registry;
public $createdAtHash?: IU8a;
readonly $encodedLength: number;
public $initialU8aLength?: number;
public $isStorageFallback?: boolean;
readonly $registry: Registry;
readonly #bitLength: 32 | 64;
@@ -42,7 +41,7 @@ export class Float extends Number implements IFloat {
this.#bitLength = bitLength;
this.$encodedLength = bitLength / 8;
this.$initialU8aLength = this.$encodedLength;
this.registry = registry;
this.$registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
@@ -65,6 +64,11 @@ export class Float extends Number implements IFloat {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
public static with (bitLength: 32 | 64): CodecClass<Float> {
return class extends Float {
constructor (registry: Registry, value?: AnyFloat) {
@@ -77,7 +81,7 @@ export class Float extends Number implements IFloat {
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
+8 -3
View File
@@ -22,7 +22,7 @@ function decodeJson (value?: Record<string, unknown> | null): [string, any][] {
* @noInheritDoc
*/
export class Json extends Map<string, any> implements Codec {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
readonly $encodedLength = 0;
@@ -34,7 +34,7 @@ export class Json extends Map<string, any> implements Codec {
super(decoded);
this.registry = registry;
this.$registry = registry;
objectProperties(this, decoded.map(([k]) => k), (k) => this.get(k));
}
@@ -59,11 +59,16 @@ export class Json extends Map<string, any> implements Codec {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/**
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
+8 -3
View File
@@ -18,7 +18,7 @@ import { warnGet } from '../utils';
* @noInheritDoc
*/
export class Raw extends Uint8Array implements IU8a {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
@@ -35,7 +35,7 @@ export class Raw extends Uint8Array implements IU8a {
constructor (registry: Registry, value?: AnyU8a, initialU8aLength?: number) {
super(u8aToU8a(value));
this.registry = registry;
this.$registry = registry;
this.$initialU8aLength = initialU8aLength;
}
@@ -59,6 +59,11 @@ export class Raw extends Uint8Array implements IU8a {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
@@ -70,7 +75,7 @@ export class Raw extends Uint8Array implements IU8a {
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
+8 -3
View File
@@ -92,7 +92,7 @@ function decodeSet (setValues: SetValues, value: string[] | Set<string> | Uint8A
* a bitwise representation of the values.
*/
export class CodecSet extends Set<string> implements ISet<string> {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
@@ -104,7 +104,7 @@ export class CodecSet extends Set<string> implements ISet<string> {
constructor (registry: Registry, setValues: SetValues, value?: string[] | Set<string> | Uint8Array | BN | number | string, bitLength = 8) {
super(decodeSet(setValues, value, bitLength));
this.registry = registry;
this.$registry = registry;
this.#allowed = setValues;
this.#byteLength = bitLength / 8;
}
@@ -129,6 +129,11 @@ export class CodecSet extends Set<string> implements ISet<string> {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
public static with (values: SetValues, bitLength?: number): CodecClass<CodecSet> {
return class extends CodecSet {
static {
@@ -161,7 +166,7 @@ export class CodecSet extends Set<string> implements ISet<string> {
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
+10 -5
View File
@@ -103,7 +103,7 @@ export class Struct<
V extends { [K in keyof S]: any } = { [K in keyof S]: any },
// type names, mapped by key, name of Class in S
E extends { [K in keyof S]: string } = { [K in keyof S]: string }> extends Map<keyof S, Codec> implements IStruct<keyof S> {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
@@ -123,7 +123,7 @@ export class Struct<
super(decoded);
this.$initialU8aLength = decodedLength;
this.registry = registry;
this.$registry = registry;
this.#jsonMap = jsonMap;
this.#Types = typeMap;
}
@@ -148,6 +148,11 @@ export class Struct<
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
public static with<S extends TypesDef> (Types: S, jsonMap?: Map<string, string>): CodecClass<Struct<S>> {
let definition: Definition | undefined;
@@ -207,7 +212,7 @@ export class Struct<
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
@@ -218,7 +223,7 @@ export class Struct<
const [Types, keys] = this.#Types;
for (let i = 0; i < keys.length; i++) {
result[keys[i]] = new Types[i](this.registry).toRawType();
result[keys[i]] = new Types[i](this.$registry).toRawType();
}
return result as E;
@@ -340,7 +345,7 @@ export class Struct<
* @description Returns the base runtime type name for this instance
*/
public toRawType (): string {
return stringify(typesToMap(this.registry, this.#Types));
return stringify(typesToMap(this.$registry, this.#Types));
}
/**
+8 -3
View File
@@ -50,7 +50,7 @@ function decodeText (value?: null | AnyString | AnyU8a | { toString: () => strin
* @noInheritDoc
*/
export class Text extends String implements IText {
readonly registry: Registry;
readonly $registry: Registry;
public $createdAtHash?: IU8a;
public $initialU8aLength?: number;
@@ -63,7 +63,7 @@ export class Text extends String implements IText {
super(str);
this.registry = registry;
this.$registry = registry;
this.$initialU8aLength = decodedLength;
}
@@ -87,6 +87,11 @@ export class Text extends String implements IText {
return warnGet(this, 'isEmpty');
}
/** @deprecated Use $registry instead. This getter will be removed in a future version */
public get registry (): Registry {
return warnGet(this, 'registry');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
@@ -98,7 +103,7 @@ export class Text extends String implements IText {
* @description returns a hash of the contents
*/
public get hash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
+10 -5
View File
@@ -26,6 +26,9 @@ interface CodecDeprecated {
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version. */
readonly isEmpty: boolean;
/** @deprecated Use $registry instead. This getter will be removed in a future version. */
readonly registry: Registry;
}
/**
@@ -75,16 +78,18 @@ export interface Codec extends CodecDeprecated {
*/
$isStorageFallback?: boolean;
/**
* @description
* The type registry associated with this object, as available when this type
* was initially created.
*/
readonly $registry: Registry;
/**
* @description Returns a hash of the value
*/
readonly hash: IU8a;
/**
* @description The registry associated with this object
*/
readonly registry: Registry;
/**
* @description Compares the value of the input to see if there is a match
*/
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
type Getters = 'createdAtHash' | 'encodedLength' | 'initialU8aLength' | 'isBasic' | 'isEmpty' | 'isNone' | 'isUnsigned';
type Getters = 'createdAtHash' | 'encodedLength' | 'hash' | 'initialU8aLength' | 'isBasic' | 'isEmpty' | 'isNone' | 'isUnsigned' | 'registry';
const hasWarned: Record<string, boolean> = {};
@@ -67,7 +67,7 @@ export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
*/
public get genesisHash (): BlockHash {
// NOTE only v3+
return this.inner.genesisHash || this.registry.createTypeUnsafe('Hash', []);
return this.inner.genesisHash || this.$registry.createTypeUnsafe('Hash', []);
}
/**
@@ -89,7 +89,7 @@ export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
*/
public get specVersion (): INumber {
// NOTE only v3+
return this.inner.specVersion || this.registry.createTypeUnsafe('u32', []);
return this.inner.specVersion || this.$registry.createTypeUnsafe('u32', []);
}
/**
@@ -97,7 +97,7 @@ export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
*/
public get tip (): ICompact<INumber> {
// NOTE from v2+
return this.inner.tip || this.registry.createTypeUnsafe('Compact<Balance>', []);
return this.inner.tip || this.$registry.createTypeUnsafe('Compact<Balance>', []);
}
/**
@@ -105,7 +105,7 @@ export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
*/
public get transactionVersion (): INumber {
// NOTE only v4+
return this.inner.transactionVersion || this.registry.createTypeUnsafe('u32', []);
return this.inner.transactionVersion || this.$registry.createTypeUnsafe('u32', []);
}
/**
@@ -150,7 +150,7 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign
public toRaw (): SignerPayloadRaw {
const payload = this.toPayload();
const data = u8aToHex(
this.registry
this.$registry
.createTypeUnsafe('ExtrinsicPayload', [payload, { version: payload.version }])
// NOTE Explicitly pass the bare flag so the method is encoded un-prefixed (non-decodable, for signing only)
.toU8a({ method: true })
@@ -116,6 +116,6 @@ export class GenericExtrinsicPayloadV4 extends Struct {
// means that the data-as-signed is un-decodable, but is also doesn't need
// the extra information, only the pure data (and is not decoded) ...
// The same applies to V1..V3, if we have a V5, carry this comment
return sign(this.registry, signerPair, this.toU8a({ method: true }), this.#signOptions);
return sign(this.$registry, signerPair, this.toU8a({ method: true }), this.#signOptions);
}
}
@@ -141,9 +141,9 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
*/
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | HexString, payload: ExtrinsicPayloadValue | Uint8Array | HexString): IExtrinsicSignature {
return this._injectSignature(
toAddress(this.registry, signer),
this.registry.createTypeUnsafe('ExtrinsicSignature', [signature]),
new GenericExtrinsicPayloadV4(this.registry, payload)
toAddress(this.$registry, signer),
this.$registry.createTypeUnsafe('ExtrinsicSignature', [signature]),
new GenericExtrinsicPayloadV4(this.$registry, payload)
);
}
@@ -153,7 +153,7 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
public createPayload (method: Call, options: SignatureOptions): GenericExtrinsicPayloadV4 {
const { era, runtimeVersion: { specVersion, transactionVersion } } = options;
return new GenericExtrinsicPayloadV4(this.registry, objectSpread<ExtrinsicPayloadValue>({}, options, {
return new GenericExtrinsicPayloadV4(this.$registry, objectSpread<ExtrinsicPayloadValue>({}, options, {
era: era || IMMORTAL_ERA,
method: method.toHex(),
specVersion,
@@ -172,8 +172,8 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
const payload = this.createPayload(method, options);
return this._injectSignature(
toAddress(this.registry, account.addressRaw),
this.registry.createTypeUnsafe('ExtrinsicSignature', [payload.sign(account)]),
toAddress(this.$registry, account.addressRaw),
this.$registry.createTypeUnsafe('ExtrinsicSignature', [payload.sign(account)]),
payload
);
}
@@ -189,8 +189,8 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
const payload = this.createPayload(method, options);
return this._injectSignature(
toAddress(this.registry, address),
this.registry.createTypeUnsafe('ExtrinsicSignature', [FAKE_SIGNATURE]),
toAddress(this.$registry, address),
this.$registry.createTypeUnsafe('ExtrinsicSignature', [FAKE_SIGNATURE]),
payload
);
}
+1 -1
View File
@@ -67,7 +67,7 @@ class BaseAccountId extends U8aFixed {
* @description Returns the string representation of the value
*/
public override toString (): string {
return encodeAddress(this, this.registry.chainSS58);
return encodeAddress(this, this.$registry.chainSS58);
}
/**
+2 -2
View File
@@ -87,7 +87,7 @@ export class GenericAccountIndex extends u32 {
}
// convert and compare
return super.eq(this.registry.createTypeUnsafe('AccountIndex', [other]));
return super.eq(this.$registry.createTypeUnsafe('AccountIndex', [other]));
}
/**
@@ -117,7 +117,7 @@ export class GenericAccountIndex extends u32 {
public override toString (): string {
const length = GenericAccountIndex.calcLength(this);
return encodeAddress(this.toU8a().subarray(0, length), this.registry.chainSS58);
return encodeAddress(this.toU8a().subarray(0, length), this.$registry.chainSS58);
}
/**
+1 -1
View File
@@ -39,7 +39,7 @@ export class GenericBlock extends Struct {
* @description Encodes a content [[Hash]] for the block
*/
public get contentHash (): IU8a {
return this.registry.hash(this.toU8a());
return this.$registry.hash(this.toU8a());
}
/**
+4 -4
View File
@@ -158,7 +158,7 @@ export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implement
* @description The argument definitions
*/
public get argsDef (): ArgsDef {
return getArgsDef(this.registry, this.meta);
return getArgsDef(this.$registry, this.meta);
}
/**
@@ -193,14 +193,14 @@ export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implement
* @description Returns the name of the method
*/
public get method (): string {
return this.registry.findMetaCall(this.callIndex).method;
return this.$registry.findMetaCall(this.callIndex).method;
}
/**
* @description Returns the module containing the method
*/
public get section (): string {
return this.registry.findMetaCall(this.callIndex).section;
return this.$registry.findMetaCall(this.callIndex).section;
}
/**
@@ -217,7 +217,7 @@ export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implement
let call: CallFunction | undefined;
try {
call = this.registry.findMetaCall(this.callIndex);
call = this.$registry.findMetaCall(this.callIndex);
} catch (error) {
// swallow
}
@@ -83,15 +83,15 @@ export class GenericConsensusEngineId extends U8aFixed {
public extractAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId | undefined {
if (sessionValidators?.length) {
if (this.isAura) {
return getAuraAuthor(this.registry, bytes, sessionValidators);
return getAuraAuthor(this.$registry, bytes, sessionValidators);
} else if (this.isBabe) {
return getBabeAuthor(this.registry, bytes, sessionValidators);
return getBabeAuthor(this.$registry, bytes, sessionValidators);
}
}
// For pow & Moonbeam, the bytes are the actual author
if (this.isPow || bytes.length === 20) {
return getBytesAsAuthor(this.registry, bytes);
return getBytesAsAuthor(this.$registry, bytes);
}
return undefined;
+1 -1
View File
@@ -80,7 +80,7 @@ export class GenericVote extends U8aFixed {
super(registry, decoded, 8);
this.#aye = (decoded[0] & AYE_BITS) === AYE_BITS;
this.#conviction = this.registry.createTypeUnsafe('Conviction', [decoded[0] & CON_MASK]);
this.#conviction = this.$registry.createTypeUnsafe('Conviction', [decoded[0] & CON_MASK]);
}
/**
@@ -65,7 +65,7 @@ export class MetadataVersioned extends Struct {
}
if (!this.#converted.has(version)) {
this.#converted.set(version, fromPrev(this.registry, this[asPrev] as F, this.version));
this.#converted.set(version, fromPrev(this.$registry, this[asPrev] as F, this.version));
}
return this.#converted.get(version) as T;
@@ -82,9 +82,9 @@ export class MetadataVersioned extends Struct {
* @description Returns the wrapped metadata as a limited calls-only (latest) version
*/
public get asCallsOnly (): MetadataVersioned {
return new MetadataVersioned(this.registry, {
return new MetadataVersioned(this.$registry, {
magicNumber: this.magicNumber,
metadata: this.registry.createTypeUnsafe('MetadataAll', [toCallsOnly(this.registry, this.asLatest), LATEST_VERSION])
metadata: this.$registry.createTypeUnsafe('MetadataAll', [toCallsOnly(this.$registry, this.asLatest), LATEST_VERSION])
});
}
@@ -154,7 +154,7 @@ export class MetadataVersioned extends Struct {
}
public getUniqTypes (throwError: boolean): string[] {
return getUniqTypes(this.registry, this.asLatest, throwError);
return getUniqTypes(this.$registry, this.asLatest, throwError);
}
/**
@@ -388,7 +388,7 @@ function removeDupeNames (lookup: PortableRegistry, portable: PortableType[], na
/** @internal */
function registerTypes (lookup: PortableRegistry, lookups: Record<string, string>, names: Record<number, string>, params: Record<string, SiTypeParameter[]>): void {
// Register the types we extracted
lookup.registry.register(lookups);
lookup.$registry.register(lookups);
// Try and extract the AccountId/Address/Signature type from UncheckedExtrinsic
if (params.SpRuntimeUncheckedExtrinsic) {
@@ -408,7 +408,7 @@ function registerTypes (lookup: PortableRegistry, lookups: Record<string, string
nsAccountId = lookup.getSiType(idParam.type.unwrap()).path.join('::');
}
lookup.registry.register({
lookup.$registry.register({
AccountId: ['sp_core::crypto::AccountId32'].includes(nsAccountId)
? 'AccountId32'
: ['account::AccountId20', 'primitive_types::H160'].includes(nsAccountId)
@@ -435,7 +435,7 @@ function registerTypes (lookup: PortableRegistry, lookups: Record<string, string
const weightDef = lookup.getTypeDef(`Lookup${weight[0]}`);
lookup.registry.register({
lookup.$registry.register({
Weight: Array.isArray(weightDef.sub) && weightDef.sub.length !== 1
// we have a complex structure
? 'SpWeightsWeightV2Weight'
@@ -501,7 +501,7 @@ function extractTypeInfo (lookup: PortableRegistry, portable: PortableType[]): T
const { lookupIndex, name, params: p } = dedup[i];
names[lookupIndex] = name;
lookups[name] = lookup.registry.createLookupType(lookupIndex);
lookups[name] = lookup.$registry.createLookupType(lookupIndex);
params[name] = p;
}
@@ -583,7 +583,7 @@ export class PortableRegistry extends Struct implements ILookup {
info: TypeDefInfo.DoNotConstruct,
lookupIndex,
lookupName,
type: this.registry.createLookupType(lookupIndex)
type: this.$registry.createLookupType(lookupIndex)
};
// Set named items since we will get into circular lookups along the way
@@ -645,14 +645,14 @@ export class PortableRegistry extends Struct implements ILookup {
info: TypeDefInfo.Si,
lookupIndex,
lookupName: this.#names[lookupIndex],
type: this.registry.createLookupType(lookupId)
type: this.$registry.createLookupType(lookupId)
}
: typeDef;
}
#getLookupId (lookupId: SiLookupTypeId | string | number): number {
if (isString(lookupId)) {
if (!this.registry.isLookupType(lookupId)) {
if (!this.$registry.isLookupType(lookupId)) {
throw new Error(`PortableRegistry: Expected a lookup string type, found ${lookupId}`);
}
@@ -703,7 +703,7 @@ export class PortableRegistry extends Struct implements ILookup {
throw new Error('Only support for [Type; <length>], where length <= 2048');
}
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: TypeDefInfo.VecFixed,
length,
sub: this.#createSiDef(type)
@@ -735,7 +735,7 @@ export class PortableRegistry extends Struct implements ILookup {
}
#extractCompact (_: number, { type }: SiTypeDefCompact): TypeDef {
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: TypeDefInfo.Compact,
sub: this.#createSiDef(type)
});
@@ -751,7 +751,7 @@ export class PortableRegistry extends Struct implements ILookup {
throw new Error(`BTreeMap requires 2 parameters, found ${params.length}`);
}
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: TypeDefInfo.BTreeMap,
sub: params.map(({ type }) => this.#createSiDef(type.unwrap()))
});
@@ -760,7 +760,7 @@ export class PortableRegistry extends Struct implements ILookup {
throw new Error(`BTreeSet requires 1 parameter, found ${params.length}`);
}
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: TypeDefInfo.BTreeSet,
sub: this.#createSiDef(params[0].type.unwrap())
});
@@ -769,7 +769,7 @@ export class PortableRegistry extends Struct implements ILookup {
throw new Error(`Range requires 1 parameter, found ${params.length}`);
}
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: pathFirst === 'Range'
? TypeDefInfo.Range
: TypeDefInfo.RangeInclusive,
@@ -781,7 +781,7 @@ export class PortableRegistry extends Struct implements ILookup {
throw new Error(`WrapperOpaque requires 1 parameter, found ${params.length}`);
}
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: pathLast === 'WrapperKeepOpaque'
? TypeDefInfo.WrapperKeepOpaque
: TypeDefInfo.WrapperOpaque,
@@ -801,9 +801,9 @@ export class PortableRegistry extends Struct implements ILookup {
throw new Error('Set handling expects param/field as single entries');
}
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: TypeDefInfo.Set,
length: this.registry.createTypeUnsafe<u32>(this.registry.createLookupType(fields[0].type), []).bitLength(),
length: this.$registry.createTypeUnsafe<u32>(this.$registry.createLookupType(fields[0].type), []).bitLength(),
sub: this.getSiType(params[0].type.unwrap()).def.asVariant.variants.map(({ index, name }): TypeDef => ({
// This will be an issue > 2^53 - 1 ... don't have those (yet)
index: index.toNumber(),
@@ -855,7 +855,7 @@ export class PortableRegistry extends Struct implements ILookup {
const [sub, alias] = this.#extractFieldsAlias(fields);
return withTypeString(this.registry, objectSpread(
return withTypeString(this.$registry, objectSpread(
{
info: isTuple // Tuple check first
? TypeDefInfo.Tuple
@@ -940,7 +940,7 @@ export class PortableRegistry extends Struct implements ILookup {
};
}
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: TypeDefInfo.Vec,
lookupIndex,
lookupName: this.#names[lookupIndex],
@@ -960,7 +960,7 @@ export class PortableRegistry extends Struct implements ILookup {
const sub = ids.map((t) => this.#createSiDef(t));
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: TypeDefInfo.Tuple,
lookupIndex,
lookupName: this.#names[lookupIndex],
@@ -979,13 +979,13 @@ export class PortableRegistry extends Struct implements ILookup {
// NOTE This is opt-in (unhandled), not by default
// if (sub.type === 'bool') {
// return withTypeString(this.registry, {
// return withTypeString(this.$registry, {
// info: TypeDefInfo.Plain,
// type: 'OptionBool'
// });
// }
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: TypeDefInfo.Option,
sub: this.#createSiDef(params[0].type.unwrap())
});
@@ -994,7 +994,7 @@ export class PortableRegistry extends Struct implements ILookup {
throw new Error(`Result requires 2 parameters, found ${params.length}`);
}
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: TypeDefInfo.Result,
sub: params.map(({ type }, index) =>
objectSpread({
@@ -1043,7 +1043,7 @@ export class PortableRegistry extends Struct implements ILookup {
);
});
return withTypeString(this.registry, {
return withTypeString(this.$registry, {
info: TypeDefInfo.Enum,
lookupIndex,
lookupName: this.#names[lookupIndex],
+2 -2
View File
@@ -236,11 +236,11 @@ export class StorageKey<A extends AnyTuple = AnyTuple> extends Bytes implements
this.#section = section || this.#section;
if (meta) {
this.#outputType = unwrapStorageType(this.registry, meta.type);
this.#outputType = unwrapStorageType(this.$registry, meta.type);
}
try {
this.#args = decodeArgsFromMeta(this.registry, this.toU8a(true), meta);
this.#args = decodeArgsFromMeta(this.$registry, this.toU8a(true), meta);
} catch (error) {
// ignore...
}