Start supporting double map (#843)
* double map fix * update metadata to prevent error using double map
This commit is contained in:
committed by
Amaury Martiny
parent
e1ec95a2f3
commit
46fee3125d
@@ -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()];
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()];
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user