Start supporting double map (#843)

* double map fix

* update metadata to prevent error using double map
This commit is contained in:
Xiliang Chen
2019-05-13 11:53:46 +02:00
committed by Amaury Martiny
parent e1ec95a2f3
commit 46fee3125d
4 changed files with 47 additions and 38 deletions
+9 -5
View File
@@ -109,11 +109,15 @@ export default class MetadataV3 extends Struct implements MetadataInterface {
return this.modules.map((mod) =>
mod.storage.isNone
? []
: mod.storage.unwrap().map((fn) =>
fn.type.isMap
? [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()]
: [fn.type.asType.toString()]
)
: mod.storage.unwrap().map((fn) => {
if (fn.type.isMap) {
return [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()];
} else if (fn.type.isDoubleMap) {
return [fn.type.asDoubleMap.key1.toString(), fn.type.asDoubleMap.key2.toString(), fn.type.asDoubleMap.value.toString()];
} else {
return [fn.type.asType.toString()];
}
})
);
}
+14 -13
View File
@@ -11,6 +11,7 @@ import Struct from '../../codec/Struct';
import Vector from '../../codec/Vector';
import Bytes from '../../primitive/Bytes';
import Text from '../../primitive/Text';
import Type from '../../primitive/Type';
import {
MapType,
PlainType,
@@ -27,25 +28,25 @@ export {
export class DoubleMapType extends Struct {
constructor (value?: any) {
super({
key1: Text,
key2: Text,
value: Text,
key1: Type,
key2: Type,
value: Type,
key2Hasher: Text
}, value);
}
/**
* @description The mapped key as [[Text]]
* @description The mapped key as [[Type]]
*/
get key1 (): Text {
return this.get('key1') as Text;
get key1 (): Type {
return this.get('key1') as Type;
}
/**
* @description The mapped key as [[Text]]
* @description The mapped key as [[Type]]
*/
get key2 (): Text {
return this.get('key2') as Text;
get key2 (): Type {
return this.get('key2') as Type;
}
/**
@@ -56,10 +57,10 @@ export class DoubleMapType extends Struct {
}
/**
* @description The mapped key as [[Text]]
* @description The mapped key as [[Type]]
*/
get value (): Text {
return this.get('value') as Text;
get value (): Type {
return this.get('value') as Type;
}
}
@@ -125,7 +126,7 @@ export class StorageFunctionType extends EnumType<PlainType | MapType | DoubleMa
*/
toString (): string {
if (this.isDoubleMap) {
return this.asDoubleMap.toString();
return this.asDoubleMap.value.toString();
}
if (this.isMap) {
+9 -5
View File
@@ -109,11 +109,15 @@ export default class MetadataV4 extends Struct implements MetadataInterface {
return this.modules.map((mod) =>
mod.storage.isNone
? []
: mod.storage.unwrap().map((fn) =>
fn.type.isMap
? [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()]
: [fn.type.asType.toString()]
)
: mod.storage.unwrap().map((fn) => {
if (fn.type.isMap) {
return [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()];
} else if (fn.type.isDoubleMap) {
return [fn.type.asDoubleMap.key1.toString(), fn.type.asDoubleMap.key2.toString(), fn.type.asDoubleMap.value.toString()];
} else {
return [fn.type.asType.toString()];
}
})
);
}
+15 -15
View File
@@ -114,32 +114,32 @@ export class DoubleMapType extends Struct {
constructor (value?: any) {
super({
hasher: StorageHasher,
key1: Text,
key2: Text,
value: Text,
key1: Type,
key2: Type,
value: Type,
key2Hasher: Text
}, value);
}
/**
* @description The hashing algorithm used to hash keys, as [[Text]]
* @description The hashing algorithm used to hash keys, as [[StorageHasher]]
*/
get hasher (): Text {
return this.get('hasher') as Text;
get hasher (): StorageHasher {
return this.get('hasher') as StorageHasher;
}
/**
* @description The mapped key as [[Text]]
* @description The mapped key as [[Type]]
*/
get key1 (): Text {
return this.get('key1') as Text;
get key1 (): Type {
return this.get('key1') as Type;
}
/**
* @description The mapped key as [[Text]]
* @description The mapped key as [[Type]]
*/
get key2 (): Text {
return this.get('key2') as Text;
get key2 (): Type {
return this.get('key2') as Type;
}
/**
@@ -150,10 +150,10 @@ export class DoubleMapType extends Struct {
}
/**
* @description The mapped key as [[Text]]
* @description The mapped key as [[Type]]
*/
get value (): Text {
return this.get('value') as Text;
get value (): Type {
return this.get('value') as Type;
}
}