* Start of trie-db re-implementation * WIP commit * More WIP * WIP, seems complete, untested * Ported trie-db operational * Add Ethereum trie tests * Use u8aConcat to construct u8a * Basic RocksDb interface * Combine engines into DB, expand tests * Update Trie with transaction wrapper * LevelDb (sync) interface * Remove unused (for now) package (compatibility) * trie-d -> trie-db-old, trie-db-ext -> trie-db * Version bump * Skip old trie tests (package to be removed) * Skip tests (fixed) * Remove non-used RocksDb spec * Skip FileFlat tests (deprecated?)
55 lines
1.1 KiB
TypeScript
55 lines
1.1 KiB
TypeScript
// Copyright 2017-2018 @polkadot/db authors & contributors
|
|
// This software may be modified and distributed under the terms
|
|
// of the ISC license. See the LICENSE file for details.
|
|
|
|
import { BaseDb, ProgressCb } from '../types';
|
|
|
|
// import logger from '@polkadot/util/logger';
|
|
// import u8aToHex from '@polkadot/util/u8a/toHex';
|
|
|
|
type Storage = {
|
|
[index: string]: Uint8Array
|
|
};
|
|
|
|
// const l = logger('db/memory');
|
|
|
|
export default class MemoryDb implements BaseDb {
|
|
private storage: Storage;
|
|
|
|
constructor () {
|
|
this.storage = {};
|
|
}
|
|
|
|
close (): void {
|
|
// noop
|
|
}
|
|
|
|
open (): void {
|
|
// noop
|
|
}
|
|
|
|
maintain (fn: ProgressCb): void {
|
|
fn({
|
|
isCompleted: true,
|
|
keys: Object.keys(this.storage).length,
|
|
percent: 100
|
|
});
|
|
}
|
|
|
|
del (key: Uint8Array): void {
|
|
delete this.storage[key.toString()];
|
|
}
|
|
|
|
get (key: Uint8Array): Uint8Array | null {
|
|
// l.debug(() => ['get', u8aToHex(key)]);
|
|
|
|
return this.storage[key.toString()] || null;
|
|
}
|
|
|
|
put (key: Uint8Array, value: Uint8Array): void {
|
|
// l.debug(() => ['put', u8aToHex(key), u8aToHex(value)]);
|
|
|
|
this.storage[key.toString()] = value;
|
|
}
|
|
}
|