@@ -25,8 +25,9 @@ use bitcoin::blockdata::locktime::absolute::LockTime;
2525use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
2626use bitcoin:: secp256k1:: ecdsa:: { RecoverableSignature , Signature } ;
2727use bitcoin:: secp256k1:: { PublicKey , Scalar , Secp256k1 , SecretKey , Signing } ;
28- use bitcoin:: { ScriptBuf , Transaction , TxOut , Txid } ;
28+ use bitcoin:: { bitcoinconsensus , ScriptBuf , Transaction , TxOut , Txid } ;
2929
30+ use std:: collections:: HashMap ;
3031use std:: ops:: Deref ;
3132use std:: sync:: { Arc , Condvar , Mutex } ;
3233use std:: time:: Duration ;
@@ -116,6 +117,29 @@ where
116117 Ok ( self . inner . lock ( ) . unwrap ( ) . is_mine ( script) ?)
117118 }
118119
120+ pub async fn verify_tx ( & self , tx : Transaction ) -> Result < ( ) , Error > {
121+ let serialized_tx = bitcoin:: consensus:: serialize ( & tx) ;
122+ for ( index, input) in tx. input . iter ( ) . enumerate ( ) {
123+ let input = input. clone ( ) ;
124+ let txid = input. previous_output . txid ;
125+ let prev_tx = if let Ok ( prev_tx) = self . blockchain . get_tx ( & txid) . await {
126+ prev_tx. unwrap ( )
127+ } else {
128+ dbg ! ( "maybe conibase?" ) ;
129+ continue ;
130+ } ;
131+ let spent_output = prev_tx. output . get ( input. previous_output . vout as usize ) . unwrap ( ) ;
132+ bitcoinconsensus:: verify (
133+ & spent_output. script_pubkey . to_bytes ( ) ,
134+ spent_output. value ,
135+ & serialized_tx,
136+ index,
137+ )
138+ . unwrap ( ) ;
139+ }
140+ Ok ( ( ) )
141+ }
142+
119143 pub ( crate ) fn sign_tx ( & self , psbt : & Psbt , options : Option < SignOptions > ) -> Result < Psbt , Error > {
120144 let wallet = self . inner . lock ( ) . unwrap ( ) ;
121145 let mut psbt = psbt. clone ( ) ;
0 commit comments