@@ -652,13 +652,13 @@ impl Transaction {
652
652
impl_consensus_encoding ! ( TxOut , value, script_pubkey) ;
653
653
654
654
impl 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 > {
656
656
let len = self . txid . consensus_encode ( w) ?;
657
657
Ok ( len + self . vout . consensus_encode ( w) ?)
658
658
}
659
659
}
660
660
impl 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 > {
662
662
Ok ( OutPoint {
663
663
txid : Decodable :: consensus_decode ( r) ?,
664
664
vout : Decodable :: consensus_decode ( r) ?,
@@ -667,7 +667,7 @@ impl Decodable for OutPoint {
667
667
}
668
668
669
669
impl 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 > {
671
671
let mut len = 0 ;
672
672
len += self . previous_output . consensus_encode ( w) ?;
673
673
len += self . script_sig . consensus_encode ( w) ?;
@@ -677,7 +677,7 @@ impl Encodable for TxIn {
677
677
}
678
678
impl Decodable for TxIn {
679
679
#[ 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 > {
681
681
Ok ( TxIn {
682
682
previous_output : Decodable :: consensus_decode_from_finite_reader ( r) ?,
683
683
script_sig : Decodable :: consensus_decode_from_finite_reader ( r) ?,
@@ -688,7 +688,7 @@ impl Decodable for TxIn {
688
688
}
689
689
690
690
impl 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 > {
692
692
let mut len = 0 ;
693
693
len += self . version . consensus_encode ( w) ?;
694
694
// To avoid serialization ambiguity, no inputs means we use BIP141 serialization (see
@@ -718,7 +718,7 @@ impl Encodable for Transaction {
718
718
}
719
719
720
720
impl 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 > {
722
722
let version = i32:: consensus_decode_from_finite_reader ( r) ?;
723
723
let input = Vec :: < TxIn > :: consensus_decode_from_finite_reader ( r) ?;
724
724
// segwit
@@ -953,6 +953,19 @@ mod tests {
953
953
use super :: EcdsaSighashType ;
954
954
use crate :: util:: sighash:: SighashCache ;
955
955
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
+
956
969
#[ test]
957
970
fn test_outpoint ( ) {
958
971
assert_eq ! ( OutPoint :: from_str( "i don't care" ) ,
0 commit comments