Rename Code .registry to .$registry (#5428)
* Adapt $registry getter, deprecate registry * warnGet adjustments * Additional adjustments
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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...
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user