1
+ use mithril_common:: entities:: { CardanoTransactionsSnapshot , SignedEntity } ;
1
2
use mithril_common:: messages:: CardanoTransactionsSetProofMessagePart ;
2
3
use mithril_common:: {
3
4
entities:: { CardanoTransactionsSetProof , TransactionHash } ,
@@ -11,21 +12,20 @@ pub struct ToCardanoTransactionsProofsMessageAdapter;
11
12
impl ToCardanoTransactionsProofsMessageAdapter {
12
13
/// Turn an entity instance into message.
13
14
pub fn try_adapt (
14
- certificate_hash : & str ,
15
+ signed_entity : SignedEntity < CardanoTransactionsSnapshot > ,
15
16
transactions_set_proofs : Vec < CardanoTransactionsSetProof > ,
16
17
transaction_hashes_to_certify : Vec < TransactionHash > ,
17
- latest_immutable_file_number : u64 ,
18
18
) -> StdResult < CardanoTransactionsProofsMessage > {
19
19
let transactions_hashes_not_certified = compute_not_certified_transactions (
20
20
& transactions_set_proofs,
21
21
& transaction_hashes_to_certify,
22
22
) ;
23
23
24
24
Ok ( CardanoTransactionsProofsMessage :: new (
25
- certificate_hash ,
25
+ & signed_entity . certificate_id ,
26
26
try_adapt_set_proof_message ( transactions_set_proofs) ?,
27
27
transactions_hashes_not_certified,
28
- latest_immutable_file_number ,
28
+ signed_entity . artifact . beacon . immutable_file_number ,
29
29
) )
30
30
}
31
31
}
@@ -78,33 +78,33 @@ mod tests {
78
78
let transactions_hashes_certified = & transaction_hashes[ 0 ..5 ] ;
79
79
let transactions_hashes_non_certified = & transaction_hashes[ 5 ..] ;
80
80
81
- let mut transactions_set_proofs = Vec :: new ( ) ;
82
- for transaction_hashes_in_chunk in transactions_hashes_certified. chunks ( 2 ) {
83
- let mk_proof = MKProof :: from_leaves ( transaction_hashes_in_chunk) . unwrap ( ) ;
84
- transactions_set_proofs. push ( CardanoTransactionsSetProof :: new (
85
- transaction_hashes_in_chunk. to_vec ( ) ,
86
- mk_proof,
87
- ) )
88
- }
89
-
90
- let certificate_hash = "certificate_hash" ;
91
- let latest_immutable_file_number = 1234 ;
81
+ let transactions_set_proofs = transactions_hashes_certified
82
+ . chunks ( 2 )
83
+ . map ( |transaction_hashes_in_chunk| {
84
+ let mk_proof = MKProof :: from_leaves ( transaction_hashes_in_chunk) . unwrap ( ) ;
85
+ CardanoTransactionsSetProof :: new ( transaction_hashes_in_chunk. to_vec ( ) , mk_proof)
86
+ } )
87
+ . collect :: < Vec < _ > > ( ) ;
88
+
89
+ let signed_entity = SignedEntity :: < CardanoTransactionsSnapshot > :: dummy ( ) ;
90
+
92
91
let message = ToCardanoTransactionsProofsMessageAdapter :: try_adapt (
93
- certificate_hash ,
92
+ signed_entity . clone ( ) ,
94
93
transactions_set_proofs. clone ( ) ,
95
94
transaction_hashes. to_vec ( ) ,
96
- latest_immutable_file_number,
97
95
)
98
96
. unwrap ( ) ;
99
- let transactions_set_proofs = transactions_set_proofs
97
+
98
+ let transactions_set_proof_message_part = transactions_set_proofs
100
99
. into_iter ( )
101
100
. map ( |p| p. try_into ( ) . unwrap ( ) )
102
101
. collect ( ) ;
102
+
103
103
let expected_message = CardanoTransactionsProofsMessage :: new (
104
- certificate_hash ,
105
- transactions_set_proofs ,
104
+ & signed_entity . certificate_id ,
105
+ transactions_set_proof_message_part ,
106
106
transactions_hashes_non_certified. to_vec ( ) ,
107
- latest_immutable_file_number ,
107
+ signed_entity . artifact . beacon . immutable_file_number ,
108
108
) ;
109
109
assert_eq ! ( expected_message, message) ;
110
110
}
0 commit comments