@@ -21,9 +21,9 @@ use std::{error, fmt, io, mem};
2121use bitcoin:: consensus:: encode as btcenc;
2222use secp256k1_zkp:: { self , RangeProof , SurjectionProof , Tweak } ;
2323
24- use crate :: hashes:: { Hash , sha256} ;
25- use crate :: transaction:: { Transaction , TxIn , TxOut } ;
24+ use crate :: hashes:: { sha256, Hash } ;
2625use crate :: pset;
26+ use crate :: transaction:: { Transaction , TxIn , TxOut } ;
2727
2828pub use bitcoin:: { self , consensus:: encode:: MAX_VEC_SIZE } ;
2929
@@ -61,7 +61,7 @@ pub enum Error {
6161 /// Hex parsing errors
6262 HexError ( crate :: hex:: Error ) ,
6363 /// Got a time-based locktime when expecting a height-based one, or vice-versa
64- BadLockTime ( crate :: LockTime )
64+ BadLockTime ( crate :: LockTime ) ,
6565}
6666
6767impl fmt:: Display for Error {
@@ -72,7 +72,11 @@ impl fmt::Display for Error {
7272 Error :: OversizedVectorAllocation {
7373 requested : ref r,
7474 max : ref m,
75- } => write ! ( f, "oversized vector allocation: requested {}, maximum {}" , r, m) ,
75+ } => write ! (
76+ f,
77+ "oversized vector allocation: requested {}, maximum {}" ,
78+ r, m
79+ ) ,
7680 Error :: ParseFailed ( ref e) => write ! ( f, "parse failed: {}" , e) ,
7781 Error :: UnexpectedEOF => write ! ( f, "unexpected EOF" ) ,
7882 Error :: InvalidConfidentialPrefix ( p) => {
@@ -174,7 +178,9 @@ pub fn deserialize<T: Decodable>(data: &[u8]) -> Result<T, Error> {
174178 if consumed == data. len ( ) {
175179 Ok ( rv)
176180 } else {
177- Err ( Error :: ParseFailed ( "data not consumed entirely when explicitly deserializing" ) )
181+ Err ( Error :: ParseFailed (
182+ "data not consumed entirely when explicitly deserializing" ,
183+ ) )
178184 }
179185}
180186
@@ -200,7 +206,10 @@ impl Decodable for sha256::Midstate {
200206 }
201207}
202208
203- pub ( crate ) fn consensus_encode_with_size < S : io:: Write > ( data : & [ u8 ] , mut s : S ) -> Result < usize , Error > {
209+ pub ( crate ) fn consensus_encode_with_size < S : io:: Write > (
210+ data : & [ u8 ] ,
211+ mut s : S ,
212+ ) -> Result < usize , Error > {
204213 let vi_len = bitcoin:: VarInt ( data. len ( ) as u64 ) . consensus_encode ( & mut s) ?;
205214 s. emit_slice ( data) ?;
206215 Ok ( vi_len + data. len ( ) )
@@ -252,7 +261,6 @@ impl Decodable for crate::locktime::Height {
252261 }
253262}
254263
255-
256264impl Encodable for crate :: locktime:: Time {
257265 fn consensus_encode < S : io:: Write > ( & self , s : S ) -> Result < usize , Error > {
258266 crate :: LockTime :: from ( * self ) . consensus_encode ( s)
@@ -267,7 +275,6 @@ impl Decodable for crate::locktime::Time {
267275 }
268276}
269277
270-
271278// Vectors
272279macro_rules! impl_vec {
273280 ( $type: ty) => {
@@ -310,7 +317,6 @@ impl_vec!(TxOut);
310317impl_vec ! ( Transaction ) ;
311318impl_vec ! ( TapLeafHash ) ;
312319
313-
314320macro_rules! impl_box_option {
315321 ( $type: ty) => {
316322 impl Encodable for Option <Box <$type>> {
@@ -326,15 +332,15 @@ macro_rules! impl_box_option {
326332 impl Decodable for Option <Box <$type>> {
327333 #[ inline]
328334 fn consensus_decode<D : io:: Read >( mut d: D ) -> Result <Self , Error > {
329- let v : Vec <u8 > = Decodable :: consensus_decode( & mut d) ?;
335+ let v: Vec <u8 > = Decodable :: consensus_decode( & mut d) ?;
330336 if v. is_empty( ) {
331337 Ok ( None )
332338 } else {
333339 Ok ( Some ( Box :: new( <$type>:: from_slice( & v) ?) ) )
334340 }
335341 }
336342 }
337- }
343+ } ;
338344}
339345// special implementations for elements only fields
340346impl Encodable for Tweak {
@@ -369,11 +375,12 @@ impl Encodable for SurjectionProof {
369375
370376impl Decodable for SurjectionProof {
371377 fn consensus_decode < D : io:: Read > ( d : D ) -> Result < Self , Error > {
372- Ok ( SurjectionProof :: from_slice ( & <Vec < u8 > >:: consensus_decode ( d) ?) ?)
378+ Ok ( SurjectionProof :: from_slice ( & <Vec < u8 > >:: consensus_decode (
379+ d,
380+ ) ?) ?)
373381 }
374382}
375383
376-
377384impl Encodable for sha256:: Hash {
378385 fn consensus_encode < S : io:: Write > ( & self , s : S ) -> Result < usize , Error > {
379386 self . to_byte_array ( ) . consensus_encode ( s)
@@ -382,7 +389,9 @@ impl Encodable for sha256::Hash {
382389
383390impl Decodable for sha256:: Hash {
384391 fn consensus_decode < D : io:: Read > ( d : D ) -> Result < Self , Error > {
385- Ok ( Self :: from_byte_array ( <<Self as Hash >:: Bytes >:: consensus_decode ( d) ?) )
392+ Ok ( Self :: from_byte_array (
393+ <<Self as Hash >:: Bytes >:: consensus_decode ( d) ?,
394+ ) )
386395 }
387396}
388397
@@ -394,7 +403,9 @@ impl Encodable for TapLeafHash {
394403
395404impl Decodable for TapLeafHash {
396405 fn consensus_decode < D : io:: Read > ( d : D ) -> Result < Self , Error > {
397- Ok ( Self :: from_byte_array ( <<Self as Hash >:: Bytes >:: consensus_decode ( d) ?) )
406+ Ok ( Self :: from_byte_array (
407+ <<Self as Hash >:: Bytes >:: consensus_decode ( d) ?,
408+ ) )
398409 }
399410}
400411
0 commit comments