fix: fix double map

Merged in check (pull request #2)

Approved-by: Ian He <ian-he@outlook.com>
This commit is contained in:
Alex Wang
2019-04-16 04:36:17 +00:00
committed by Ian He
parent 327c20ddea
commit 4d95d622a9
+22 -3
View File
@@ -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<PlainType | MapType> {
export class StorageFunctionType extends EnumType<PlainType | MapType | DoubleMapType> {
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<PlainType | MapType> {
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<PlainType | MapType> {
* @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()}>)`;