@@ -31,8 +31,8 @@ use primitives::{Bytes, H256};
3131use util_error:: UtilError ;
3232
3333use super :: {
34- Account , Asset , AssetAddress , AssetScheme , AssetSchemeAddress , Backend , CacheableItem , Metadata , MetadataAddress ,
35- Shard , ShardAddress , ShardBackend , TopBackend ,
34+ Account , ActionHandler , Asset , AssetAddress , AssetScheme , AssetSchemeAddress , Backend , CacheableItem , Metadata ,
35+ MetadataAddress , Shard , ShardAddress , ShardBackend , TopBackend ,
3636} ;
3737
3838const STATE_CACHE_BLOCKS : usize = 12 ;
@@ -125,14 +125,16 @@ pub struct StateDB {
125125 commit_hash : Option < H256 > ,
126126 /// Number of the committing block or `None` if not committed yet.
127127 commit_number : Option < BlockNumber > ,
128+
129+ custom_handlers : Vec < Arc < ActionHandler > > ,
128130}
129131
130132impl StateDB {
131133 /// Create a new instance wrapping `JournalDB` and the maximum allowed size
132134 /// of the LRU cache in bytes. Actual used memory may (read: will) be higher due to bookkeeping.
133135 // TODO: make the cache size actually accurate by moving the account storage cache
134136 // into the `AccountCache` structure as its own `LruCache<(Address, H256), H256>`.
135- pub fn new ( db : Box < JournalDB > , cache_size : usize ) -> StateDB {
137+ pub fn new ( db : Box < JournalDB > , cache_size : usize , custom_handlers : Vec < Arc < ActionHandler > > ) -> StateDB {
136138 assert_eq ! (
137139 100 ,
138140 ACCOUNT_CACHE_RATIO
@@ -197,12 +199,13 @@ impl StateDB {
197199 parent_hash : None ,
198200 commit_hash : None ,
199201 commit_number : None ,
202+ custom_handlers,
200203 }
201204 }
202205
203- pub fn new_with_memorydb ( cache_size : usize ) -> Self {
206+ pub fn new_with_memorydb ( cache_size : usize , custom_handlers : Vec < Arc < ActionHandler > > ) -> Self {
204207 let memorydb = Arc :: new ( kvdb_memorydb:: create ( 0 ) ) ;
205- StateDB :: new ( journaldb:: new ( memorydb, Algorithm :: Archive , None ) , cache_size)
208+ StateDB :: new ( journaldb:: new ( memorydb, Algorithm :: Archive , None ) , cache_size, custom_handlers )
206209 }
207210
208211 /// Journal all recent operations under the given era and ID.
@@ -427,6 +430,7 @@ impl StateDB {
427430 parent_hash : Some ( parent. clone ( ) ) ,
428431 commit_hash : None ,
429432 commit_number : None ,
433+ custom_handlers : self . custom_handlers . clone ( ) ,
430434 }
431435 }
432436
@@ -541,6 +545,8 @@ impl Clone for StateDB {
541545 parent_hash : None ,
542546 commit_hash : None ,
543547 commit_number : None ,
548+
549+ custom_handlers : self . custom_handlers . clone ( ) ,
544550 }
545551 }
546552}
@@ -609,6 +615,10 @@ impl TopBackend for StateDB {
609615 F : FnOnce ( Option < & mut Account > ) -> U , {
610616 self . get_cached_with ( a, f, & self . account_cache )
611617 }
618+
619+ fn custom_handlers ( & self ) -> & [ Arc < ActionHandler > ] {
620+ & self . custom_handlers
621+ }
612622}
613623
614624impl ShardBackend for StateDB {
0 commit comments