1616
1717use super :: WriteBack ;
1818use crate :: {
19- Account , ActionData , Metadata , MetadataAddress , RegularAccount , RegularAccountAddress , Shard , ShardAddress ,
19+ Account , ActionData , IBCData , Metadata , MetadataAddress , RegularAccount , RegularAccountAddress , Shard , ShardAddress ,
2020} ;
2121use ckey:: Address ;
2222use merkle_trie:: { Result as TrieResult , Trie , TrieMut } ;
@@ -29,6 +29,7 @@ pub struct TopCache {
2929 metadata : WriteBack < Metadata > ,
3030 shard : WriteBack < Shard > ,
3131 action_data : WriteBack < ActionData > ,
32+ ibc_data : WriteBack < IBCData > ,
3233}
3334
3435impl TopCache {
@@ -38,13 +39,15 @@ impl TopCache {
3839 metadata : impl Iterator < Item = ( MetadataAddress , Metadata ) > ,
3940 shards : impl Iterator < Item = ( ShardAddress , Shard ) > ,
4041 action_data : impl Iterator < Item = ( H256 , ActionData ) > ,
42+ ibc_data : impl Iterator < Item = ( H256 , IBCData ) > ,
4143 ) -> Self {
4244 Self {
4345 account : WriteBack :: new_with_iter ( accounts) ,
4446 regular_account : WriteBack :: new_with_iter ( regular_accounts) ,
4547 metadata : WriteBack :: new_with_iter ( metadata) ,
4648 shard : WriteBack :: new_with_iter ( shards) ,
4749 action_data : WriteBack :: new_with_iter ( action_data) ,
50+ ibc_data : WriteBack :: new_with_iter ( ibc_data) ,
4851 }
4952 }
5053
@@ -54,6 +57,7 @@ impl TopCache {
5457 self . metadata . checkpoint ( ) ;
5558 self . shard . checkpoint ( ) ;
5659 self . action_data . checkpoint ( ) ;
60+ self . ibc_data . checkpoint ( ) ;
5761 }
5862
5963 pub fn discard_checkpoint ( & mut self ) {
@@ -62,6 +66,7 @@ impl TopCache {
6266 self . metadata . discard_checkpoint ( ) ;
6367 self . shard . discard_checkpoint ( ) ;
6468 self . action_data . discard_checkpoint ( ) ;
69+ self . ibc_data . discard_checkpoint ( ) ;
6570 }
6671
6772 pub fn revert_to_checkpoint ( & mut self ) {
@@ -70,6 +75,7 @@ impl TopCache {
7075 self . metadata . revert_to_checkpoint ( ) ;
7176 self . shard . revert_to_checkpoint ( ) ;
7277 self . action_data . revert_to_checkpoint ( ) ;
78+ self . ibc_data . revert_to_checkpoint ( ) ;
7379 }
7480
7581 pub fn commit < ' db > ( & mut self , trie : & mut ( dyn TrieMut + ' db ) ) -> TrieResult < ( ) > {
@@ -78,6 +84,7 @@ impl TopCache {
7884 self . metadata . commit ( trie) ?;
7985 self . shard . commit ( trie) ?;
8086 self . action_data . commit ( trie) ?;
87+ self . ibc_data . commit ( trie) ?;
8188 Ok ( ( ) )
8289 }
8390
@@ -142,6 +149,18 @@ impl TopCache {
142149 self . action_data . remove ( address)
143150 }
144151
152+ pub fn ibc_data ( & self , a : & H256 , db : & dyn Trie ) -> TrieResult < Option < IBCData > > {
153+ self . ibc_data . get ( a, db)
154+ }
155+
156+ pub fn ibc_data_mut ( & self , a : & H256 , db : & dyn Trie ) -> TrieResult < RefMut < ' _ , IBCData > > {
157+ self . ibc_data . get_mut ( a, db)
158+ }
159+
160+ pub fn remove_ibc_data ( & self , address : & H256 ) {
161+ self . ibc_data . remove ( address)
162+ }
163+
145164 pub fn cached_accounts ( & self ) -> Vec < ( Address , Option < Account > ) > {
146165 let mut items = self . account . items ( ) ;
147166 items. sort_unstable_by ( |lhs, rhs| lhs. 0 . cmp ( & rhs. 0 ) ) ;
@@ -171,6 +190,12 @@ impl TopCache {
171190 items. sort_unstable_by ( |lhs, rhs| lhs. 0 . cmp ( & rhs. 0 ) ) ;
172191 items. into_iter ( ) . map ( |( _, addr, item) | ( addr, item) ) . collect ( )
173192 }
193+
194+ pub fn cached_ibc_data ( & self ) -> Vec < ( H256 , Option < IBCData > ) > {
195+ let mut items = self . ibc_data . items ( ) ;
196+ items. sort_unstable_by ( |lhs, rhs| lhs. 0 . cmp ( & rhs. 0 ) ) ;
197+ items. into_iter ( ) . map ( |( _, addr, item) | ( addr, item) ) . collect ( )
198+ }
174199}
175200
176201impl Clone for TopCache {
@@ -181,6 +206,7 @@ impl Clone for TopCache {
181206 metadata : self . metadata . clone ( ) ,
182207 shard : self . shard . clone ( ) ,
183208 action_data : self . action_data . clone ( ) ,
209+ ibc_data : self . ibc_data . clone ( ) ,
184210 }
185211 }
186212}
0 commit comments