@@ -126,41 +126,20 @@ impl From<Level> for FFILogLevel {
126
126
}
127
127
128
128
#[ repr( C ) ]
129
+ #[ derive( Debug ) ]
129
130
pub struct FFILogRecord {
130
131
/// The verbosity level of the message.
131
132
pub level : FFILogLevel ,
132
133
/// The message body.
133
- pub args : CString ,
134
+ pub args : * const i8 ,
134
135
/// The module path of the message.
135
- pub module_path : CString ,
136
+ pub module_path : * const i8 ,
136
137
/// The source file containing the message.
137
- pub file : CString ,
138
+ pub file : * const i8 ,
138
139
/// The line containing the message.
139
140
pub line : u32 ,
140
141
}
141
142
142
-
143
- impl < ' a > From < Record < ' a > > for FFILogRecord {
144
- fn from ( rec : Record < ' a > ) -> Self {
145
- let args = CString :: new ( std:: fmt:: format ( rec. args ) ) . unwrap_or ( CString :: new ( "Record.args contains null char in the middle" ) . unwrap ( ) ) ;
146
- let module_path = CString :: new ( rec. module_path ) . unwrap_or ( CString :: new ( "Record.module_path contains null char in the middle" ) . unwrap ( ) ) ;
147
- let file = CString :: new ( rec. file ) . unwrap_or ( CString :: new ( "Record.file contains null char in the middle" ) . unwrap ( ) ) ;
148
- FFILogRecord {
149
- level : rec. level . into ( ) ,
150
- args,
151
- module_path,
152
- file,
153
- line : rec. line ,
154
- }
155
- }
156
- }
157
-
158
- impl < ' a , ' b > From < & ' a Record < ' b > > for FFILogRecord {
159
- fn from ( rec : & ' a Record ) -> Self {
160
- rec. into ( )
161
- }
162
- }
163
-
164
143
pub mod ffilogger_fn {
165
144
use super :: { FFILogRecord , FFILogger } ;
166
145
pub type LogExtern = extern "cdecl" fn ( record : * const FFILogRecord ) ;
@@ -172,9 +151,21 @@ pub struct FFILogger {
172
151
}
173
152
174
153
impl Logger for FFILogger {
175
- fn log ( & self , record : & Record ) {
176
- let ffi_record: FFILogRecord = record. into ( ) ;
154
+ fn log ( & self , rec : & Record ) {
155
+ let args = CString :: new ( std:: fmt:: format ( rec. args ) ) . unwrap_or ( CString :: new ( "Record.args contains null char in the middle" ) . unwrap ( ) ) ;
156
+ let module_path = CString :: new ( rec. module_path ) . unwrap_or ( CString :: new ( "Record.module_path contains null char in the middle" ) . unwrap ( ) ) ;
157
+ let file = CString :: new ( rec. file ) . unwrap_or ( CString :: new ( "Record.file contains null char in the middle" ) . unwrap ( ) ) ;
158
+ let ffi_record =
159
+ FFILogRecord {
160
+ level : rec. level . into ( ) ,
161
+ args : args. as_ptr ( ) ,
162
+ module_path : module_path. as_ptr ( ) ,
163
+ file : file. as_ptr ( ) ,
164
+ line : rec. line ,
165
+ } ;
166
+ println ! ( "Going to call log callback with {:?}" , ffi_record) ;
177
167
( self . log_ptr ) ( & ffi_record as * const _ ) ;
168
+ println ! ( "rust: finished calling logger" ) ;
178
169
}
179
170
}
180
171
@@ -183,7 +174,7 @@ pub mod chain_watch_interface_fn {
183
174
pub type InstallWatchTxPtr = extern "cdecl" fn ( * const FFISha256dHash , script_pub_key : * const FFIScript ) ;
184
175
pub type InstallWatchOutpointPtr = extern "cdecl" fn ( outpoint : * const FFIOutPoint , out_script : * const FFIScript ) ;
185
176
pub type WatchAllTxnPtr = extern "cdecl" fn ( ) ;
186
- pub type GetChainUtxoPtr = extern "cdecl" fn ( genesis_hash : * const FFISha256dHash , unspent_tx_output_identifier : u64 , err : * mut ChainError , script : * mut FFITxOut ) ;
177
+ pub type GetChainUtxoPtr = extern "cdecl" fn ( genesis_hash : * const FFISha256dHash , unspent_tx_output_identifier : u64 , err : * mut FFIChainError , script : * mut FFITxOut ) ;
187
178
pub type FilterBlockPtr = extern "cdecl" fn ( * const FFIBlock ) ;
188
179
}
189
180
@@ -210,10 +201,20 @@ impl ChainWatchInterface for FFIChainWatchInterface {
210
201
( self . install_watch_outpoint_ptr ) ( & ffi_outpoint as * const _ , & ffi_outscript as * const _ )
211
202
}
212
203
fn watch_all_txn ( & self ) {
213
- unimplemented ! ( )
204
+ ( self . watch_all_txn_ptr ) ( )
214
205
}
215
206
fn get_chain_utxo ( & self , genesis_hash : Sha256dHash , unspent_tx_output_identifier : u64 ) -> Result < ( Script , u64 ) , ChainError > {
216
- unimplemented ! ( )
207
+ let err = std:: ptr:: null_mut ( ) ;
208
+ let tx_out = std:: ptr:: null_mut ( ) ;
209
+ ( self . get_chain_utxo_ptr ) ( & genesis_hash. into ( ) , unspent_tx_output_identifier, err, tx_out) ;
210
+ if err. is_null ( ) {
211
+ let tx_out: FFITxOut = unsafe_block ! ( "We know the caller has set the value into the tx_out" => ( * tx_out) . clone( ) ) ;
212
+ Ok ( ( tx_out. script_pubkey . to_script ( ) , tx_out. value ) )
213
+ }
214
+ else {
215
+ let e = unsafe_block ! ( "we know the error is not a null pointer" => ( * err) . clone( ) ) ;
216
+ Err ( e. into ( ) )
217
+ }
217
218
}
218
219
fn filter_block < ' a > ( & self , block : & ' a Block ) -> ( Vec < & ' a Transaction > , Vec < u32 > ) {
219
220
unimplemented ! ( )
0 commit comments