@@ -652,13 +652,13 @@ impl Transaction {
652652impl_consensus_encoding ! ( TxOut , value, script_pubkey) ;
653653
654654impl Encodable for OutPoint {
655- fn consensus_encode < W : io:: Write > ( & self , w : & mut W ) -> Result < usize , io:: Error > {
655+ fn consensus_encode < W : io:: Write + ? Sized > ( & self , w : & mut W ) -> Result < usize , io:: Error > {
656656 let len = self . txid . consensus_encode ( w) ?;
657657 Ok ( len + self . vout . consensus_encode ( w) ?)
658658 }
659659}
660660impl Decodable for OutPoint {
661- fn consensus_decode < R : io:: Read > ( r : & mut R ) -> Result < Self , encode:: Error > {
661+ fn consensus_decode < R : io:: Read + ? Sized > ( r : & mut R ) -> Result < Self , encode:: Error > {
662662 Ok ( OutPoint {
663663 txid : Decodable :: consensus_decode ( r) ?,
664664 vout : Decodable :: consensus_decode ( r) ?,
@@ -667,7 +667,7 @@ impl Decodable for OutPoint {
667667}
668668
669669impl Encodable for TxIn {
670- fn consensus_encode < W : io:: Write > ( & self , w : & mut W ) -> Result < usize , io:: Error > {
670+ fn consensus_encode < W : io:: Write + ? Sized > ( & self , w : & mut W ) -> Result < usize , io:: Error > {
671671 let mut len = 0 ;
672672 len += self . previous_output . consensus_encode ( w) ?;
673673 len += self . script_sig . consensus_encode ( w) ?;
@@ -677,7 +677,7 @@ impl Encodable for TxIn {
677677}
678678impl Decodable for TxIn {
679679 #[ inline]
680- fn consensus_decode_from_finite_reader < R : io:: Read > ( r : & mut R ) -> Result < Self , encode:: Error > {
680+ fn consensus_decode_from_finite_reader < R : io:: Read + ? Sized > ( r : & mut R ) -> Result < Self , encode:: Error > {
681681 Ok ( TxIn {
682682 previous_output : Decodable :: consensus_decode_from_finite_reader ( r) ?,
683683 script_sig : Decodable :: consensus_decode_from_finite_reader ( r) ?,
@@ -688,7 +688,7 @@ impl Decodable for TxIn {
688688}
689689
690690impl Encodable for Transaction {
691- fn consensus_encode < W : io:: Write > ( & self , w : & mut W ) -> Result < usize , io:: Error > {
691+ fn consensus_encode < W : io:: Write + ? Sized > ( & self , w : & mut W ) -> Result < usize , io:: Error > {
692692 let mut len = 0 ;
693693 len += self . version . consensus_encode ( w) ?;
694694 // To avoid serialization ambiguity, no inputs means we use BIP141 serialization (see
@@ -718,7 +718,7 @@ impl Encodable for Transaction {
718718}
719719
720720impl Decodable for Transaction {
721- fn consensus_decode_from_finite_reader < R : io:: Read > ( r : & mut R ) -> Result < Self , encode:: Error > {
721+ fn consensus_decode_from_finite_reader < R : io:: Read + ? Sized > ( r : & mut R ) -> Result < Self , encode:: Error > {
722722 let version = i32:: consensus_decode_from_finite_reader ( r) ?;
723723 let input = Vec :: < TxIn > :: consensus_decode_from_finite_reader ( r) ?;
724724 // segwit
@@ -953,6 +953,19 @@ mod tests {
953953 use super :: EcdsaSighashType ;
954954 use crate :: util:: sighash:: SighashCache ;
955955
956+ const SOME_TX : & str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000" ;
957+
958+ #[ test]
959+ fn encode_to_unsized_writer ( ) {
960+ let mut buf = [ 0u8 ; 1024 ] ;
961+ let raw_tx = Vec :: from_hex ( SOME_TX ) . unwrap ( ) ;
962+ let tx: Transaction = Decodable :: consensus_decode ( & mut raw_tx. as_slice ( ) ) . unwrap ( ) ;
963+
964+ let size = tx. consensus_encode ( & mut & mut buf[ ..] ) . unwrap ( ) ;
965+ assert_eq ! ( size, SOME_TX . len( ) / 2 ) ;
966+ assert_eq ! ( raw_tx, & buf[ ..size] ) ;
967+ }
968+
956969 #[ test]
957970 fn test_outpoint ( ) {
958971 assert_eq ! ( OutPoint :: from_str( "i don't care" ) ,
0 commit comments