KeyValue now extends Tuple instead of Struct (#1001)
This commit is contained in:
committed by
Amaury Martiny
parent
c17d8a7c80
commit
b3f2a11e1e
@@ -15,18 +15,12 @@ describe('KeyValue', () => {
|
||||
0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11
|
||||
])
|
||||
).toJSON()
|
||||
).toEqual({
|
||||
key: '0x11223344',
|
||||
value: '0x998877665544332211'
|
||||
});
|
||||
).toEqual(['0x11223344', '0x998877665544332211']);
|
||||
});
|
||||
|
||||
it('encodes KeyValue from JSON', () => {
|
||||
expect(
|
||||
new KeyValue({
|
||||
key: '0x11223344',
|
||||
value: '0x998877665544332211'
|
||||
}).toU8a()
|
||||
new KeyValue(['0x11223344', '0x998877665544332211']).toU8a()
|
||||
).toEqual(
|
||||
new Uint8Array([
|
||||
4 << 2,
|
||||
@@ -38,10 +32,7 @@ describe('KeyValue', () => {
|
||||
});
|
||||
|
||||
it('exposes the properties for key/value', () => {
|
||||
const kv = new KeyValue({
|
||||
key: '0x11223344',
|
||||
value: '0x998877665544332211'
|
||||
});
|
||||
const kv = new KeyValue(['0x11223344', '0x998877665544332211']);
|
||||
|
||||
expect(kv.key.toHex()).toEqual('0x11223344');
|
||||
expect(kv.value.toHex()).toEqual('0x998877665544332211');
|
||||
|
||||
@@ -5,15 +5,11 @@
|
||||
import { AnyU8a } from '../types';
|
||||
|
||||
import Option from '../codec/Option';
|
||||
import Struct from '../codec/Struct';
|
||||
import Tuple from '../codec/Tuple';
|
||||
import StorageData from '../primitive/StorageData';
|
||||
import StorageKey from '../primitive/StorageKey';
|
||||
|
||||
type KeyValueValue = {
|
||||
key?: AnyU8a,
|
||||
value?: AnyU8a
|
||||
};
|
||||
type KeyValueValue = [AnyU8a, AnyU8a];
|
||||
|
||||
/**
|
||||
* @name KeyValue
|
||||
@@ -21,9 +17,9 @@ type KeyValueValue = {
|
||||
* KeyValue structure. Since most of the keys and resultant values in Subtrate are
|
||||
* hashed and/or encoded, this does not wrap [[Text]], but rather a [[Bytes]]
|
||||
* for the keys and values. (Not to be confused with the KeyValue in [[Metadata]], that
|
||||
* is actually for Maps, whereas this is a representation of actaul storage values)
|
||||
* is actually for Maps, whereas this is a representation of actual storage values)
|
||||
*/
|
||||
export default class KeyValue extends Struct {
|
||||
export default class KeyValue extends Tuple {
|
||||
constructor (value?: KeyValueValue | Uint8Array) {
|
||||
super({
|
||||
key: StorageKey,
|
||||
@@ -35,14 +31,14 @@ export default class KeyValue extends Struct {
|
||||
* @description The [[StorageKey]]
|
||||
*/
|
||||
get key (): StorageKey {
|
||||
return this.get('key') as StorageKey;
|
||||
return this[0] as StorageKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[StorageData]]
|
||||
*/
|
||||
get value (): StorageData {
|
||||
return this.get('value') as StorageData;
|
||||
return this[1] as StorageData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user