2121use crate :: consensus:: { Decodable , Encodable , encode} ;
2222use crate :: hash_types:: { MerkleRootMasternodeList , MerkleRootQuorums } ;
2323use crate :: io:: { Error , ErrorKind } ;
24- use crate :: prelude:: Vec ;
2524use crate :: { VarInt , io} ;
25+ use crate :: bls_sig_utils:: BLSSignature ;
2626
2727/// A Coinbase payload. This is contained as the payload of a coinbase special transaction.
2828/// The Coinbase payload is described in DIP4.
@@ -36,7 +36,7 @@ pub struct CoinbasePayload {
3636 pub merkle_root_masternode_list : MerkleRootMasternodeList ,
3737 pub merkle_root_quorums : MerkleRootQuorums ,
3838 pub best_cl_height : Option < u32 > ,
39- pub best_cl_signature : Option < Vec < u8 > > ,
39+ pub best_cl_signature : Option < BLSSignature > ,
4040 pub asset_locked_amount : Option < u64 > ,
4141}
4242
@@ -93,9 +93,16 @@ impl Decodable for CoinbasePayload {
9393 let height = u32:: consensus_decode ( r) ?;
9494 let merkle_root_masternode_list = MerkleRootMasternodeList :: consensus_decode ( r) ?;
9595 let merkle_root_quorums = MerkleRootQuorums :: consensus_decode ( r) ?;
96- let best_cl_height = if version >= 3 { Some ( u32:: consensus_decode ( r) ?) } else { None } ;
96+ let best_cl_height = if version >= 3 {
97+ let value = u8:: consensus_decode ( r) ?;
98+ match value {
99+ 253 => Some ( u16:: consensus_decode ( r) ? as u32 ) ,
100+ 254 => Some ( u32:: consensus_decode ( r) ?) ,
101+ _ => Some ( value as u32 )
102+ }
103+ } else { None } ;
97104 let best_cl_signature =
98- if version >= 3 { Some ( Vec :: < u8 > :: consensus_decode ( r) ?) } else { None } ;
105+ if version >= 3 { Some ( BLSSignature :: consensus_decode ( r) ?) } else { None } ;
99106 let asset_locked_amount = if version >= 3 { Some ( u64:: consensus_decode ( r) ?) } else { None } ;
100107 Ok ( CoinbasePayload {
101108 version,
@@ -112,7 +119,7 @@ impl Decodable for CoinbasePayload {
112119#[ cfg( test) ]
113120mod tests {
114121 use hashes:: Hash ;
115-
122+ use crate :: bls_sig_utils :: BLSSignature ;
116123 use crate :: consensus:: Encodable ;
117124 use crate :: hash_types:: { MerkleRootMasternodeList , MerkleRootQuorums } ;
118125 use crate :: transaction:: special_transaction:: coinbase:: CoinbasePayload ;
@@ -127,7 +134,7 @@ mod tests {
127134 merkle_root_masternode_list : MerkleRootMasternodeList :: all_zeros ( ) ,
128135 merkle_root_quorums : MerkleRootQuorums :: all_zeros ( ) ,
129136 best_cl_height : Some ( 900 ) ,
130- best_cl_signature : Some ( vec ! [ 0 ; 96 ] ) ,
137+ best_cl_signature : Some ( BLSSignature :: from ( [ 0 ; 96 ] ) ) ,
131138 asset_locked_amount : Some ( 10000 ) ,
132139 } ;
133140 assert_eq ! ( payload. size( ) , * want) ;
0 commit comments