@@ -196,7 +196,7 @@ pub mod chain_watch_interface_fn {
196196 pub type InstallWatchTxPtr = extern "cdecl" fn ( * const Bytes32 , script_pub_key : * const FFIScript ) ;
197197 pub type InstallWatchOutpointPtr = extern "cdecl" fn ( outpoint : * const FFIOutPoint , out_script : * const FFIScript ) ;
198198 pub type WatchAllTxnPtr = extern "cdecl" fn ( ) ;
199- pub type GetChainUtxoPtr = extern "cdecl" fn ( genesis_hash : * const Bytes32 , unspent_tx_output_identifier : u64 , err : * mut FFIChainError , script : * mut FFITxOut ) ;
199+ pub type GetChainUtxoPtr = extern "cdecl" fn ( genesis_hash : * const Bytes32 , unspent_tx_output_identifier : u64 , err : * mut FFIChainError , script_ptr : * mut u8 , script_len : * mut usize , amount_satoshis : * mut u64 ) ;
200200}
201201
202202#[ repr( C ) ]
@@ -247,14 +247,25 @@ impl ChainWatchInterface for FFIChainWatchInterface {
247247 ( self . watch_all_txn_ptr ) ( )
248248 }
249249 fn get_chain_utxo ( & self , genesis_hash : BlockHash , unspent_tx_output_identifier : u64 ) -> Result < ( Script , u64 ) , ChainError > {
250+ match self . util . get_chain_utxo ( genesis_hash, unspent_tx_output_identifier) {
251+ Err ( ChainError :: NotWatched ) => {
252+ return Err ( ChainError :: NotWatched ) ;
253+ } ,
254+ _ => { } ,
255+ }
250256 let err = std:: ptr:: null_mut ( ) ;
251- let tx_out = std:: ptr:: null_mut ( ) ;
252- ( self . get_chain_utxo_ptr ) ( & genesis_hash. into ( ) , unspent_tx_output_identifier, err, tx_out) ;
257+ // the length can be anything as long as it is enough to put the scriptPubKey.
258+ // probably this is a bit overkill but who cares.
259+ let mut script = [ 0u8 ; 128 ] ;
260+ let script_len = std:: ptr:: null_mut ( ) ;
261+ let amount_satoshis = std:: ptr:: null_mut ( ) ;
262+ ( self . get_chain_utxo_ptr ) ( & genesis_hash. into ( ) , unspent_tx_output_identifier, err, script. as_mut_ptr ( ) , script_len, amount_satoshis) ;
253263 if err. is_null ( ) {
254- let tx_out: FFITxOut = unsafe_block ! ( "We know the caller has set the value into the tx_out" => ( * tx_out) . clone( ) ) ;
255- Ok ( ( tx_out. script_pubkey . to_script ( ) , tx_out. value ) )
256- }
257- else {
264+ let script_bytes: & [ u8 ] = unsafe_block ! ( "We know the caller has set the value into the script_ptr, script_len" => & script[ ..( * script_len) ] ) ;
265+ let amount: u64 = unsafe_block ! ( "We know the caller has set the value into the amount_satoshis" => * amount_satoshis) ;
266+ let s = bitcoin:: consensus:: deserialize ( script_bytes) . expect ( "Failed to parse scriptpubkey" ) ;
267+ Ok ( ( s, amount) )
268+ } else {
258269 let e = unsafe_block ! ( "we know the error is not a null pointer" => ( * err) . clone( ) ) ;
259270 Err ( e. into ( ) )
260271 }
0 commit comments