Add basic hashdb (wrong package) (#160)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Vendored
+7
-6
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user