You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let log_ref = unsafe_block!("" => log_ptr.as_ref());
30
+
let logger_arc = Arc::new(FFILogger{ log_ptr:*log_ref });
31
+
32
+
let install_watch_tx_ref = unsafe_block!("function pointer lives as long as ChainWatchInterface and it points to valid data" => install_watch_tx_ptr.as_ref());
33
+
let install_watch_outpoint_ref = unsafe_block!("function pointer lives as long as ChainWatchInterface and it points to valid data" => install_watch_outpoint_ptr.as_ref());
34
+
let watch_all_txn_ref = unsafe_block!("function pointer lives as long as ChainWatchInterface and it points to valid data" => watch_all_txn_ptr.as_ref());
35
+
let get_chain_utxo_ref = unsafe_block!("function pointer lives as long as ChainWatchInterface and it points to valid data" => get_chain_utxo_ptr.as_ref());
36
+
let chain_watch_interface_arc =
37
+
Arc::new(FFIChainWatchInterface::new(
38
+
*install_watch_tx_ref,
39
+
*install_watch_outpoint_ref,
40
+
*watch_all_txn_ref,
41
+
*get_chain_utxo_ref,
42
+
network,
43
+
logger_arc.clone()
44
+
));
45
+
let block_notifier = FFIBlockNotifier::new(chain_watch_interface_arc);
46
+
unsafe_block!("We know handle is not null by wrapper macro. And we know `Out` is writable" => handle.init(HandleShared::alloc(block_notifier)));
47
+
FFIResult::ok()
48
+
}
49
+
50
+
fn register_channel_manager(
51
+
channel_manager:FFIArcChannelManagerHandle,
52
+
handle:FFIBlockNotifierHandle
53
+
) -> FFIResult{
54
+
let chan_man:Arc<FFIArcChannelManager> = unsafe_block!("We know the handle points to valid channel_manager" => channel_manager.as_arc());
55
+
let block_notifier:&FFIBlockNotifier = unsafe_block!("We know the handle pointers to valid block notifier" => handle.as_ref());
56
+
block_notifier.register_listener(chan_man);
57
+
FFIResult::ok()
58
+
}
59
+
60
+
fn unregister_channel_manager(
61
+
channel_manager:FFIArcChannelManagerHandle,
62
+
handle:FFIBlockNotifierHandle
63
+
) -> FFIResult{
64
+
let chan_man:Arc<FFIArcChannelManager> = unsafe_block!("We know the handle points to valid channel_manager" => channel_manager.as_arc());
65
+
let block_notifier:&FFIBlockNotifier = unsafe_block!("We know the handle pointers to valid block notifier" => handle.as_ref());
66
+
block_notifier.unregister_listener(chan_man);
67
+
FFIResult::ok()
68
+
}
69
+
70
+
fn block_connected(
71
+
block_ptr:Ref<u8>,
72
+
block_len:usize,
73
+
height:u32,
74
+
handle:FFIBlockNotifierHandle) -> FFIResult{
75
+
let block_notifier:&FFIBlockNotifier = unsafe_block!("We know the handle pointers to valid block notifier" => handle.as_ref());
76
+
let block_bytes = unsafe_block!("block_ptr points to valid buffer of block_len length" => block_ptr.as_bytes(block_len));
77
+
let block = bitcoin::consensus::deserialize(block_bytes)?;
78
+
block_notifier.block_connected(&block, height);
79
+
FFIResult::ok()
80
+
}
81
+
82
+
fn block_disconnected(
83
+
block_header_ptr:Ref<u8>,
84
+
block_header_len:usize,
85
+
height:u32,
86
+
handle:FFIBlockNotifierHandle
87
+
) -> FFIResult{
88
+
let block_notifier:&FFIBlockNotifier = unsafe_block!("We know the handle pointers to valid block notifier" => handle.as_ref());
89
+
90
+
let block_header_bytes:&[u8] = unsafe_block!("We know it points to valid buffer of specified length" => block_header_ptr.as_bytes(block_header_len));
91
+
let block_header:BlockHeader = bitcoin::consensus::encode::deserialize(block_header_bytes)?;
unsafe_block!("The upstream caller guarantees the handle will not be accessed after being freed" => FFIBlockNotifierHandle::dealloc(handle, |mut handle| {
98
+
// We keep reference to listeners from wrapper side (as a `SafeHandle`
99
+
// to a `ChannelManager`) so that we can call methods
0 commit comments