Add basic hashdb (wrong package) (#160)

This commit is contained in:
Jaco Greeff
2018-07-03 15:06:38 +02:00
committed by GitHub
parent 243df6d030
commit 538069c24b
2 changed files with 32 additions and 6 deletions
+25
View File
@@ -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;
}
}
+7 -6
View File
@@ -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
}