import { LevelUp } from 'levelup' ; import MerklePatriciaTree from 'merkle-patricia-tree' ; export class Trie { private trie : MerklePatriciaTree ; get isCheckpoint ( ) { return this . trie . isCheckpoint ; } constructor ( public db ? , stateRoot ? ) { this . trie = new MerklePatriciaTree ( db , stateRoot ) ; } public get root ( ) { return this . trie . root ; } public async get ( key ) { return new Promise ( ( resolve , reject ) => { this . trie . get ( key , ( err , value ) => { if ( err ) { return reject ( err ) ; } else { return resolve ( value ) ; } } ) ; } ) ; } public async put ( key , value ) { return new Promise ( ( resolve , reject ) => this . trie . put ( key , value , err => { if ( err ) { return reject ( err ) ; } else { return resolve ( ) ; } } ) ) ; } public checkpoint ( ) { this . trie . checkpoint ( ) ; } public commit ( ) { return new Promise ( resolve => this . trie . commit ( resolve ) ) ; } public revert ( ) { return new Promise ( resolve => this . trie . revert ( resolve ) ) ; } }