From 538069c24bfc666f9641699ef818949095640e55 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 3 Jul 2018 15:06:38 +0200 Subject: [PATCH] Add basic hashdb (wrong package) (#160) --- packages/trie-db/src/Hash.ts | 25 +++++++++++++++++++++++++ packages/trie-db/src/types.d.ts | 13 +++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 packages/trie-db/src/Hash.ts diff --git a/packages/trie-db/src/Hash.ts b/packages/trie-db/src/Hash.ts new file mode 100644 index 000000000..4266fac23 --- /dev/null +++ b/packages/trie-db/src/Hash.ts @@ -0,0 +1,25 @@ +// Copyright 2017-2018 @polkadot/trie-db authors & contributors +// This software may be modified and distributed under the terms +// of the MPL-2.0 license. See the LICENSE file for details. + +import { BaseDb } from './types'; + +type StorageHash = { + [index: string]: Uint8Array +}; + +export default class HashDb implements BaseDb { + private storage: StorageHash = {}; + + del (key: Uint8Array): void { + delete this.storage[key.toString()]; + } + + get (key: Uint8Array): Uint8Array | null { + return this.storage[key.toString()] || null; + } + + put (key: Uint8Array, value: Uint8Array): void { + this.storage[key.toString()] = value; + } +} diff --git a/packages/trie-db/src/types.d.ts b/packages/trie-db/src/types.d.ts index 99c171394..22cb90c3b 100644 --- a/packages/trie-db/src/types.d.ts +++ b/packages/trie-db/src/types.d.ts @@ -2,14 +2,15 @@ // This software may be modified and distributed under the terms // of the MPL-2.0 license. See the LICENSE file for details. -import { Trie$Pairs } from '@polkadot/trie-hash/types'; - -export interface TrieDb { - checkpoint: () => void, - commit: () => void, +export interface BaseDb { del: (key: Uint8Array) => void, get: (key: Uint8Array) => Uint8Array | null, - put: (key: Uint8Array, value: Uint8Array) => void, + put: (key: Uint8Array, value: Uint8Array) => void +} + +export interface TrieDb extends BaseDb { + checkpoint: () => void, + commit: () => void, revert: () => void, trieRoot: () => Uint8Array }