@@ -35,75 +35,102 @@ const BLOCKCHAIN_BLOCK_INFO_KEY: &str = "blockchain_block_info";
3535pub type CertifiedBlock = CertifiedResult < Block < H256 > > ;
3636
3737/// A trait for interacting with a blockchain database
38- #[ async_trait:: async_trait]
3938pub trait DatabaseClient : Send + Sync {
4039 /// Initialize the database
41- async fn init ( & self , block : Option < Block < H256 > > , reset_database : bool ) -> anyhow:: Result < ( ) > ;
40+ fn init (
41+ & self ,
42+ block : Option < Block < H256 > > ,
43+ reset_database : bool ,
44+ ) -> impl Future < Output = anyhow:: Result < ( ) > > + Send ;
4245
4346 /// Delete/clear the tables
44- async fn clear ( & self ) -> anyhow:: Result < ( ) > ;
47+ fn clear ( & self ) -> impl Future < Output = anyhow:: Result < ( ) > > + Send ;
4548
4649 /// Returns whether the block hash corresponds to the one in the db
47- async fn check_if_same_block_hash ( & self , block : & Block < H256 > ) -> anyhow:: Result < bool > {
48- let block_number = block. number . 0 . to ( ) ;
49- let block_in_db = self . get_block_by_number ( block_number) . await ?;
50- Ok ( block. hash == block_in_db. hash )
50+ fn check_if_same_block_hash (
51+ & self ,
52+ block : & Block < H256 > ,
53+ ) -> impl Future < Output = anyhow:: Result < bool > > + Send {
54+ async {
55+ let block_number = block. number . 0 . to ( ) ;
56+ let block_in_db = self . get_block_by_number ( block_number) . await ?;
57+ Ok ( block. hash == block_in_db. hash )
58+ }
5159 }
5260
5361 /// Get a block from the database
54- async fn get_block_by_number ( & self , block_number : u64 ) -> anyhow:: Result < Block < H256 > > ;
62+ fn get_block_by_number (
63+ & self ,
64+ block_number : u64 ,
65+ ) -> impl Future < Output = anyhow:: Result < Block < H256 > > > + Send ;
5566
5667 /// Get a block from the database
57- async fn get_full_block_by_number (
68+ fn get_full_block_by_number (
5869 & self ,
5970 block_number : u64 ,
60- ) -> anyhow:: Result < Block < Transaction > > ;
71+ ) -> impl Future < Output = anyhow:: Result < Block < Transaction > > > + Send ;
6172
6273 /// Insert block data; this includes transactions and the blocks
63- async fn insert_block_data (
74+ fn insert_block_data (
6475 & self ,
6576 blocks : & [ Block < H256 > ] ,
6677 transactions : & [ Transaction ] ,
67- ) -> anyhow:: Result < ( ) > ;
78+ ) -> impl Future < Output = anyhow:: Result < ( ) > > + Send ;
6879
6980 /// Insert certified block data
70- async fn insert_certified_block_data ( & self , response : CertifiedBlock ) -> anyhow:: Result < ( ) > ;
81+ fn insert_certified_block_data (
82+ & self ,
83+ response : CertifiedBlock ,
84+ ) -> impl Future < Output = anyhow:: Result < ( ) > > + Send ;
7185
7286 /// Returns certified response for the last block
73- async fn get_last_certified_block_data ( & self ) -> anyhow:: Result < CertifiedBlock > ;
87+ fn get_last_certified_block_data (
88+ & self ,
89+ ) -> impl Future < Output = anyhow:: Result < CertifiedBlock > > + Send ;
7490
7591 /// Get genesis balances
76- async fn get_genesis_balances ( & self ) -> anyhow:: Result < Option < Vec < AccountBalance > > > ;
92+ fn get_genesis_balances (
93+ & self ,
94+ ) -> impl Future < Output = anyhow:: Result < Option < Vec < AccountBalance > > > > + Send ;
7795
7896 /// Insert genesis balances
79- async fn insert_genesis_balances (
97+ fn insert_genesis_balances (
8098 & self ,
8199 genesis_balances : & [ AccountBalance ] ,
82- ) -> anyhow:: Result < ( ) > ;
100+ ) -> impl Future < Output = anyhow:: Result < ( ) > > + Send ;
83101
84102 /// Get chain id
85- async fn get_chain_id ( & self ) -> anyhow:: Result < Option < u64 > > ;
103+ fn get_chain_id ( & self ) -> impl Future < Output = anyhow:: Result < Option < u64 > > > + Send ;
86104
87105 /// Insert chain_id
88- async fn insert_chain_id ( & self , chain_id : u64 ) -> anyhow:: Result < ( ) > ;
106+ fn insert_chain_id ( & self , chain_id : u64 ) -> impl Future < Output = anyhow:: Result < ( ) > > + Send ;
89107
90108 /// Get a transaction from the database
91- async fn get_transaction ( & self , tx_hash : H256 ) -> anyhow:: Result < Transaction > ;
109+ fn get_transaction (
110+ & self ,
111+ tx_hash : H256 ,
112+ ) -> impl Future < Output = anyhow:: Result < Transaction > > + Send ;
92113
93114 /// Get the latest block number
94- async fn get_latest_block_number ( & self ) -> anyhow:: Result < Option < u64 > > ;
115+ fn get_latest_block_number ( & self ) -> impl Future < Output = anyhow:: Result < Option < u64 > > > + Send ;
95116
96117 /// Get earliest block number
97- async fn get_earliest_block_number ( & self ) -> anyhow:: Result < u64 > ;
118+ fn get_earliest_block_number ( & self ) -> impl Future < Output = anyhow:: Result < u64 > > + Send ;
98119
99120 /// Delete latest blocks starting with `start_from`, and related transactions.
100121 /// Deleted blocks and transactions will be preserved in 'discarded' table with
101122 /// the given 'reason' and timestamp.
102- async fn discard_blocks_from ( & self , start_from : u64 , reason : & str ) -> anyhow:: Result < ( ) > ;
123+ fn discard_blocks_from (
124+ & self ,
125+ start_from : u64 ,
126+ reason : & str ,
127+ ) -> impl Future < Output = anyhow:: Result < ( ) > > + Send ;
103128
104129 /// Returns a discarded block by its hash.
105- async fn get_discarded_block_by_hash ( & self , block_hash : H256 )
106- -> anyhow:: Result < DiscardedBlock > ;
130+ fn get_discarded_block_by_hash (
131+ & self ,
132+ block_hash : H256 ,
133+ ) -> impl Future < Output = anyhow:: Result < DiscardedBlock > > + Send ;
107134
108135 /// Returns block info from storage.
109136 ///
@@ -115,10 +142,15 @@ pub trait DatabaseClient: Send + Sync {
115142 /// - safe_block_number: u64,
116143 /// - finalized_block_number: u64,
117144 /// - pending_block_number: u64,
118- async fn get_block_info ( & self ) -> anyhow:: Result < Option < BlockchainBlockInfo > > ;
145+ fn get_block_info (
146+ & self ,
147+ ) -> impl Future < Output = anyhow:: Result < Option < BlockchainBlockInfo > > > + Send ;
119148
120149 /// Stores blockchain block info.
121- async fn set_block_info ( & self , info : BlockchainBlockInfo ) -> anyhow:: Result < ( ) > ;
150+ fn set_block_info (
151+ & self ,
152+ info : BlockchainBlockInfo ,
153+ ) -> impl Future < Output = anyhow:: Result < ( ) > > + Send ;
122154}
123155
124156/// Discarded block with metadata.
0 commit comments