Trie implements TxDb interface fully

This commit is contained in:
Jaco Greeff
2018-09-01 22:44:45 +02:00
parent c59b3347fc
commit 130163b74e
2 changed files with 16 additions and 4 deletions
+2 -2
View File
@@ -21,6 +21,6 @@ export interface BaseDb {
put (key: Uint8Array, value: Uint8Array): void;
}
export interface TxDb extends BaseDb {
transaction (fn: () => boolean): boolean;
export interface TxDb <T = any> extends BaseDb {
transaction (fn: () => boolean): T;
}
+14 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { TxDb } from '@polkadot/db/types';
import { TxDb, ProgressCb } from '@polkadot/db/types';
import { Node, NodeBranch, NodeEncodedOrEmpty, NodeKv, NodeNotEmpty, NodeType } from './types';
import MemoryDb from '@polkadot/db/Memory';
@@ -20,7 +20,7 @@ import { EMPTY_HASH, EMPTY_U8A } from './constants';
const l = logger('trie/db');
export default class Trie {
export default class Trie implements TxDb<Uint8Array> {
private db: TxDb;
private txRoot: Uint8Array;
private rootHash: Uint8Array;
@@ -61,6 +61,18 @@ export default class Trie {
}
}
open (): void {
this.db.open();
}
close (): void {
this.db.close();
}
maintain (fn: ProgressCb): void {
this.db.maintain(fn);
}
del (key: Uint8Array) {
l.debug(() => ['del', { key }]);