From b3f2a11e1ec9f555a038bd9c9de1e8674c310624 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Thu, 13 Jun 2019 21:37:57 +0200 Subject: [PATCH] KeyValue now extends Tuple instead of Struct (#1001) --- packages/types/src/type/KeyValue.spec.ts | 15 +++------------ packages/types/src/type/KeyValue.ts | 14 +++++--------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/packages/types/src/type/KeyValue.spec.ts b/packages/types/src/type/KeyValue.spec.ts index 159ea7d5d9..123a7b0d65 100644 --- a/packages/types/src/type/KeyValue.spec.ts +++ b/packages/types/src/type/KeyValue.spec.ts @@ -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'); diff --git a/packages/types/src/type/KeyValue.ts b/packages/types/src/type/KeyValue.ts index afc2fe1a5d..50e690917c 100644 --- a/packages/types/src/type/KeyValue.ts +++ b/packages/types/src/type/KeyValue.ts @@ -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; } }