@@ -6,7 +6,8 @@ pub mod derived;
6
6
use bitcoin:: Transaction as BitcoinTransaction ;
7
7
use bitcoin:: Witness as BitcoinWitness ;
8
8
use bitcoin:: address;
9
- use bitcoin:: address:: WitnessProgram as BitcoinWitnessProgram ;
9
+ use bitcoin:: WitnessProgram as BitcoinWitnessProgram ;
10
+ use bitcoin:: WitnessVersion as BitcoinWitnessVersion ;
10
11
use bitcoin:: key:: TweakedPublicKey as BitcoinTweakedPublicKey ;
11
12
use bitcoin:: key:: XOnlyPublicKey ;
12
13
use bitcoin:: hashes:: Hash ;
@@ -18,16 +19,13 @@ use bitcoin::secp256k1::Error as SecpError;
18
19
use bitcoin:: secp256k1:: ecdsa:: RecoveryId ;
19
20
use bitcoin:: secp256k1:: ecdsa:: RecoverableSignature as SecpRecoverableSignature ;
20
21
use bitcoin:: secp256k1:: Scalar as SecpScalar ;
21
- use bitcoin :: bech32;
22
+ use bech32;
22
23
23
24
use core:: convert:: TryInto ; // Bindings need at least rustc 1.34
24
25
use alloc:: borrow:: ToOwned ;
25
26
use core:: ffi:: c_void;
26
27
27
- #[ cfg( feature = "std" ) ]
28
- pub ( crate ) use std:: io:: { self , Cursor , Read } ;
29
- #[ cfg( feature = "no-std" ) ]
30
- pub ( crate ) use core2:: io:: { self , Cursor , Read } ;
28
+ pub ( crate ) use bitcoin:: io:: { self , Cursor , Read } ;
31
29
#[ cfg( feature = "no-std" ) ]
32
30
use alloc:: { boxed:: Box , vec:: Vec , string:: String } ;
33
31
@@ -90,12 +88,12 @@ impl Into<u128> for U128 {
90
88
#[ repr( C ) ]
91
89
pub struct WitnessVersion ( u8 ) ;
92
90
93
- impl From < address :: WitnessVersion > for WitnessVersion {
94
- fn from ( o : address :: WitnessVersion ) -> Self { Self ( o. to_num ( ) ) }
91
+ impl From < BitcoinWitnessVersion > for WitnessVersion {
92
+ fn from ( o : BitcoinWitnessVersion ) -> Self { Self ( o. to_num ( ) ) }
95
93
}
96
- impl Into < address :: WitnessVersion > for WitnessVersion {
97
- fn into ( self ) -> address :: WitnessVersion {
98
- address :: WitnessVersion :: try_from ( self . 0 ) . expect ( "WitnessVersion objects must be in the range 0..=16" )
94
+ impl Into < BitcoinWitnessVersion > for WitnessVersion {
95
+ fn into ( self ) -> BitcoinWitnessVersion {
96
+ BitcoinWitnessVersion :: try_from ( self . 0 ) . expect ( "WitnessVersion objects must be in the range 0..=16" )
99
97
}
100
98
}
101
99
@@ -116,7 +114,7 @@ impl WitnessProgram {
116
114
pub ( crate ) fn into_bitcoin ( mut self ) -> BitcoinWitnessProgram {
117
115
BitcoinWitnessProgram :: new (
118
116
self . version . into ( ) ,
119
- self . program . into_rust ( ) ,
117
+ self . program . as_slice ( ) ,
120
118
) . expect ( "Program length was previously checked" )
121
119
}
122
120
}
@@ -322,6 +320,8 @@ pub enum Secp256k1Error {
322
320
InvalidPublicKeySum ,
323
321
/// The only valid parity values are 0 or 1.
324
322
InvalidParityValue ,
323
+ /// Invalid Elligator Swift Value
324
+ InvalidEllSwift ,
325
325
}
326
326
impl Secp256k1Error {
327
327
pub ( crate ) fn from_rust ( err : SecpError ) -> Self {
@@ -336,6 +336,7 @@ impl Secp256k1Error {
336
336
SecpError :: InvalidTweak => Secp256k1Error :: InvalidTweak ,
337
337
SecpError :: NotEnoughMemory => Secp256k1Error :: NotEnoughMemory ,
338
338
SecpError :: InvalidPublicKeySum => Secp256k1Error :: InvalidPublicKeySum ,
339
+ SecpError :: InvalidEllSwift => Secp256k1Error :: InvalidEllSwift ,
339
340
SecpError :: InvalidParityValue ( _) => Secp256k1Error :: InvalidParityValue ,
340
341
}
341
342
}
@@ -352,6 +353,7 @@ impl Secp256k1Error {
352
353
Secp256k1Error :: InvalidTweak => SecpError :: InvalidTweak ,
353
354
Secp256k1Error :: NotEnoughMemory => SecpError :: NotEnoughMemory ,
354
355
Secp256k1Error :: InvalidPublicKeySum => SecpError :: InvalidPublicKeySum ,
356
+ Secp256k1Error :: InvalidEllSwift => SecpError :: InvalidEllSwift ,
355
357
Secp256k1Error :: InvalidParityValue => SecpError :: InvalidParityValue ( invalid_parity) ,
356
358
}
357
359
}
@@ -460,12 +462,15 @@ impl IOError {
460
462
io:: ErrorKind :: Interrupted => IOError :: Interrupted ,
461
463
io:: ErrorKind :: Other => IOError :: Other ,
462
464
io:: ErrorKind :: UnexpectedEof => IOError :: UnexpectedEof ,
463
- _ => IOError :: Other ,
464
465
}
465
466
}
466
- pub ( crate ) fn from_rust ( err : io:: Error ) -> Self {
467
+ pub ( crate ) fn from_bitcoin ( err : io:: Error ) -> Self {
467
468
Self :: from_rust_kind ( err. kind ( ) )
468
469
}
470
+ #[ cfg( feature = "std" ) ]
471
+ pub ( crate ) fn from_rust ( err : std:: io:: Error ) -> Self {
472
+ Self :: from_bitcoin ( err. into ( ) )
473
+ }
469
474
pub ( crate ) fn to_rust_kind ( & self ) -> io:: ErrorKind {
470
475
match self {
471
476
IOError :: NotFound => io:: ErrorKind :: NotFound ,
@@ -701,13 +706,13 @@ impl TxOut {
701
706
pub ( crate ) fn into_rust ( mut self ) -> :: bitcoin:: blockdata:: transaction:: TxOut {
702
707
:: bitcoin:: blockdata:: transaction:: TxOut {
703
708
script_pubkey : self . script_pubkey . into_rust ( ) . into ( ) ,
704
- value : self . value ,
709
+ value : bitcoin :: Amount :: from_sat ( self . value ) ,
705
710
}
706
711
}
707
712
pub ( crate ) fn from_rust ( txout : & :: bitcoin:: blockdata:: transaction:: TxOut ) -> Self {
708
713
Self {
709
714
script_pubkey : derived:: CVec_u8Z :: from ( txout. script_pubkey . clone ( ) . into_bytes ( ) ) ,
710
- value : txout. value
715
+ value : txout. value . to_sat ( )
711
716
}
712
717
}
713
718
}
@@ -764,7 +769,7 @@ impl u8slice {
764
769
}
765
770
pub ( crate ) fn reader_to_vec < R : Read > ( r : & mut R ) -> derived:: CVec_u8Z {
766
771
let mut res = Vec :: new ( ) ;
767
- r. read_to_end ( & mut res) . unwrap ( ) ;
772
+ r. read_to_limit ( & mut res, u64 :: MAX ) . unwrap ( ) ;
768
773
derived:: CVec_u8Z :: from ( res)
769
774
}
770
775
@@ -873,6 +878,12 @@ impl Str {
873
878
pub ( crate ) fn into_pathbuf ( mut self ) -> std:: path:: PathBuf {
874
879
std:: path:: PathBuf :: from ( self . into_string ( ) )
875
880
}
881
+ pub ( crate ) fn from_rust ( s : & str ) -> Self {
882
+ s. into ( )
883
+ }
884
+ pub ( crate ) fn is_empty ( & self ) -> bool {
885
+ self . len == 0
886
+ }
876
887
}
877
888
impl Into < Str > for String {
878
889
fn into ( self ) -> Str {
0 commit comments