From 4d95d622a9181ae8e2987a74bdf1cfd254ac3079 Mon Sep 17 00:00:00 2001 From: Alex Wang Date: Tue, 16 Apr 2019 04:36:17 +0000 Subject: [PATCH] fix: fix double map Merged in check (pull request #2) Approved-by: Ian He --- packages/types/src/Metadata/v0/Modules.ts | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/types/src/Metadata/v0/Modules.ts b/packages/types/src/Metadata/v0/Modules.ts index c1b95c0402..f5a73ac5fd 100644 --- a/packages/types/src/Metadata/v0/Modules.ts +++ b/packages/types/src/Metadata/v0/Modules.ts @@ -151,7 +151,7 @@ export class DoubleMapType extends Struct { get key1 (): Text { return this.get('key1') as Text; } - + /** * @description The mapped key as [[Text]] */ @@ -213,14 +213,22 @@ export class MapType extends Struct { class PlainType extends Type { } -export class StorageFunctionType extends EnumType { +export class StorageFunctionType extends EnumType { constructor (value?: any, index?: number) { super({ PlainType, - MapType + MapType, + DoubleMapType }, value, index); } + /** + * @description `true` if the storage entry is a doublemap + */ + get isDoubleMap (): boolean { + return this.toNumber() === 2; + } + /** * @description `true` if the storage entry is a map */ @@ -228,6 +236,13 @@ export class StorageFunctionType extends EnumType { return this.toNumber() === 1; } + /** + * @description The value as a mapped value + */ + get asDoubleMap (): DoubleMapType { + return this.value as DoubleMapType; + } + /** * @description The value as a mapped value */ @@ -246,6 +261,10 @@ export class StorageFunctionType extends EnumType { * @description Returns the string representation of the value */ toString (): string { + if (this.isDoubleMap) { + return this.asDoubleMap.value.toString(); + } + if (this.isMap) { if (this.asMap.isLinked) { return `(${this.asMap.value.toString()}, Linkage<${this.asMap.key.toString()}>)`;