Pass registry to all codec types (#1592)
* Pass registry to all codec types
* Pass through registry inside API (where the rubber meets the road)
* Small additions
* Derive w/ registry
* Types are more-or-less covered
* Some test adjustments (guided by linting)
* Rid the world of some ../injector
* Additional cleanups, merge injector into registry
* Cleanup extrinsics (always passing registry)
* Remove injector imports (not all replaced)
* Typ spec cleanups
* Phase 1 - types seem lint-free
* rpc-{core,provider} lint free
* Start working through metadata
* Small metadata additions
* Some e2e tests (out-of-order)
* Down to a handful
* Fixup tests for packages/types/src/codec/*.spec.ts
* packages/types/src/codec passes all tests
* packages/types ok (Convert storage with registry fn)
* progress (sort out injection, dreaded find-before msg)
* Down to 1 lint issue...
* Linting done... along with on-demand import
* Exposed ordering
* Remove global injects
* Cleanup comments
* Add CHANGELOG & UPGRADING
* Apply suggestions from code review
Co-Authored-By: Amaury Martiny <amaury.martiny@protonmail.com>
* Update Metadata description
This commit is contained in:
co-authored by
Amaury Martiny
parent
099992627b
commit
011e24bd49
@@ -3,6 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { MetadataV0, MetadataV1 } from '@polkadot/types/interfaces/metadata';
|
||||
import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
@@ -32,8 +33,8 @@ type MetaVersions = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
||||
type MetaAsX = 'asV0' | 'asV1' | 'asV2' | 'asV3' | 'asV4' | 'asV5' | 'asV6' | 'asV7';
|
||||
|
||||
class MetadataEnum extends Enum {
|
||||
constructor (value?: any, index?: number) {
|
||||
super({
|
||||
constructor (registry: Registry, value?: any, index?: number) {
|
||||
super(registry, {
|
||||
V0: 'MetadataV0', // once rolled-out, can replace this with MetadataDeprecated
|
||||
V1: 'MetadataV1', // once rolled-out, can replace this with MetadataDeprecated
|
||||
V2: MetadataV2, // once rolled-out, can replace this with MetadataDeprecated
|
||||
@@ -206,11 +207,13 @@ class MetadataEnum extends Enum {
|
||||
export default class MetadataVersioned extends Struct {
|
||||
private _converted: Map<number, MetaMapped> = new Map();
|
||||
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
constructor (registry: Registry, value?: any) {
|
||||
super(registry, {
|
||||
magicNumber: MagicNumber,
|
||||
metadata: MetadataEnum
|
||||
}, value);
|
||||
|
||||
registry.setMetadata(this);
|
||||
}
|
||||
|
||||
private assertVersion (version: number): boolean {
|
||||
@@ -219,7 +222,7 @@ export default class MetadataVersioned extends Struct {
|
||||
return this.version === version;
|
||||
}
|
||||
|
||||
private getVersion<T extends MetaMapped, F extends MetaMapped> (version: MetaVersions, fromPrev: (input: F) => T): T {
|
||||
private getVersion<T extends MetaMapped, F extends MetaMapped> (version: MetaVersions, fromPrev: (registry: Registry, input: F) => T): T {
|
||||
const asCurr: MetaAsX = `asV${version}` as any;
|
||||
const asPrev: MetaAsX = `asV${version - 1}` as any;
|
||||
|
||||
@@ -228,7 +231,7 @@ export default class MetadataVersioned extends Struct {
|
||||
}
|
||||
|
||||
if (!this._converted.has(version)) {
|
||||
this._converted.set(version, fromPrev(this[asPrev] as F));
|
||||
this._converted.set(version, fromPrev(this.registry, this[asPrev] as F));
|
||||
}
|
||||
|
||||
return this._converted.get(version) as T;
|
||||
@@ -238,9 +241,9 @@ export default class MetadataVersioned extends Struct {
|
||||
* @description Returns the wrapped metadata as a limited calls-only (latest) version
|
||||
*/
|
||||
public get asCallsOnly (): MetadataVersioned {
|
||||
return new MetadataVersioned({
|
||||
return new MetadataVersioned(this.registry, {
|
||||
magicNumber: this.magicNumber,
|
||||
metadata: new MetadataEnum(toCallsOnly(this.asLatest), this.version)
|
||||
metadata: new MetadataEnum(this.registry, toCallsOnly(this.registry, this.asLatest), this.version)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -338,6 +341,6 @@ export default class MetadataVersioned extends Struct {
|
||||
}
|
||||
|
||||
public getUniqTypes (throwError: boolean): string[] {
|
||||
return getUniqTypes(this.asLatest, throwError);
|
||||
return getUniqTypes(this.registry, this.asLatest, throwError);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user