@@ -6,7 +6,7 @@ use slog::{debug, Logger};
6
6
7
7
use crate :: {
8
8
crypto_helper:: { MKMap , MKMapNode , MKTreeNode } ,
9
- entities:: { BlockRange , ChainPoint , ProtocolMessage , ProtocolMessagePartKey } ,
9
+ entities:: { BlockNumber , BlockRange , ProtocolMessage , ProtocolMessagePartKey } ,
10
10
signable_builder:: SignableBuilder ,
11
11
StdResult ,
12
12
} ;
@@ -19,7 +19,7 @@ use mockall::automock;
19
19
#[ async_trait]
20
20
pub trait TransactionsImporter : Send + Sync {
21
21
/// Returns all transactions up to the given beacon
22
- async fn import ( & self , up_to_beacon : & ChainPoint ) -> StdResult < ( ) > ;
22
+ async fn import ( & self , up_to_beacon : BlockNumber ) -> StdResult < ( ) > ;
23
23
}
24
24
25
25
/// Block Range Merkle roots retriever
@@ -29,13 +29,13 @@ pub trait BlockRangeRootRetriever: Send + Sync {
29
29
/// Returns a Merkle map of the block ranges roots up to a given beacon
30
30
async fn retrieve_block_range_roots (
31
31
& self ,
32
- up_to_beacon : & ChainPoint ,
32
+ up_to_beacon : BlockNumber ,
33
33
) -> StdResult < Box < dyn Iterator < Item = ( BlockRange , MKTreeNode ) > > > ;
34
34
35
35
/// Returns a Merkle map of the block ranges roots up to a given beacon
36
36
async fn compute_merkle_map_from_block_range_roots (
37
37
& self ,
38
- up_to_beacon : & ChainPoint ,
38
+ up_to_beacon : BlockNumber ,
39
39
) -> StdResult < MKMap < BlockRange , MKMapNode < BlockRange > > > {
40
40
let block_range_roots_iterator = self
41
41
. retrieve_block_range_roots ( up_to_beacon)
@@ -71,18 +71,18 @@ impl CardanoTransactionsSignableBuilder {
71
71
}
72
72
73
73
#[ async_trait]
74
- impl SignableBuilder < ChainPoint > for CardanoTransactionsSignableBuilder {
75
- async fn compute_protocol_message ( & self , beacon : ChainPoint ) -> StdResult < ProtocolMessage > {
74
+ impl SignableBuilder < BlockNumber > for CardanoTransactionsSignableBuilder {
75
+ async fn compute_protocol_message ( & self , beacon : BlockNumber ) -> StdResult < ProtocolMessage > {
76
76
debug ! (
77
77
self . logger,
78
- "Compute protocol message for CardanoTransactions at beacon : {beacon}"
78
+ "Compute protocol message for CardanoTransactions at block_number : {beacon}"
79
79
) ;
80
80
81
- self . transaction_importer . import ( & beacon) . await ?;
81
+ self . transaction_importer . import ( beacon) . await ?;
82
82
83
83
let mk_root = self
84
84
. block_range_root_retriever
85
- . compute_merkle_map_from_block_range_roots ( & beacon)
85
+ . compute_merkle_map_from_block_range_roots ( beacon)
86
86
. await ?
87
87
. compute_root ( ) ?;
88
88
@@ -93,7 +93,7 @@ impl SignableBuilder<ChainPoint> for CardanoTransactionsSignableBuilder {
93
93
) ;
94
94
protocol_message. set_message_part (
95
95
ProtocolMessagePartKey :: LatestBlockNumber ,
96
- beacon. block_number . to_string ( ) ,
96
+ beacon. to_string ( ) ,
97
97
) ;
98
98
99
99
Ok ( protocol_message)
@@ -125,10 +125,7 @@ mod tests {
125
125
#[ tokio:: test]
126
126
async fn test_compute_signable ( ) {
127
127
// Arrange
128
- let beacon = ChainPoint {
129
- block_number : 1453 ,
130
- ..ChainPoint :: dummy ( )
131
- } ;
128
+ let block_number = 1453 ;
132
129
let transactions = CardanoTransactionsBuilder :: new ( ) . build_transactions ( 3 ) ;
133
130
let mk_map = compute_mk_map_from_transactions ( transactions. clone ( ) ) ;
134
131
let mut transaction_importer = MockTransactionsImporter :: new ( ) ;
@@ -149,7 +146,7 @@ mod tests {
149
146
150
147
// Action
151
148
let signable = cardano_transactions_signable_builder
152
- . compute_protocol_message ( beacon . clone ( ) )
149
+ . compute_protocol_message ( block_number )
153
150
. await
154
151
. unwrap ( ) ;
155
152
@@ -161,14 +158,14 @@ mod tests {
161
158
) ;
162
159
signable_expected. set_message_part (
163
160
ProtocolMessagePartKey :: LatestBlockNumber ,
164
- format ! ( "{}" , beacon . block_number) ,
161
+ format ! ( "{}" , block_number) ,
165
162
) ;
166
163
assert_eq ! ( signable_expected, signable) ;
167
164
}
168
165
169
166
#[ tokio:: test]
170
167
async fn test_compute_signable_with_no_block_range_root_return_error ( ) {
171
- let beacon = ChainPoint :: dummy ( ) ;
168
+ let block_number = 50 ;
172
169
let mut transaction_importer = MockTransactionsImporter :: new ( ) ;
173
170
transaction_importer. expect_import ( ) . return_once ( |_| Ok ( ( ) ) ) ;
174
171
let mut block_range_root_retriever = MockBlockRangeRootRetriever :: new ( ) ;
@@ -182,7 +179,7 @@ mod tests {
182
179
) ;
183
180
184
181
let result = cardano_transactions_signable_builder
185
- . compute_protocol_message ( beacon . clone ( ) )
182
+ . compute_protocol_message ( block_number )
186
183
. await ;
187
184
188
185
assert ! ( result. is_err( ) ) ;
0 commit comments