|
1 |
| -use std::sync::{Arc}; |
| 1 | +use std::sync::Arc; |
2 | 2 | use std::time::{SystemTime, UNIX_EPOCH};
|
3 | 3 |
|
4 |
| -use bitcoin::blockdata::transaction::{Transaction}; |
5 |
| - |
6 | 4 | use lightning::util::config::UserConfig;
|
7 |
| -use lightning::util::logger::{Logger, Record}; |
8 |
| - |
9 |
| -use lightning::chain::chaininterface::{BroadcasterInterface,FeeEstimator,ConfirmationTarget}; |
10 | 5 | use lightning::chain::keysinterface::{KeysManager, InMemoryChannelKeys};
|
11 |
| -use lightning::chain::transaction::{OutPoint}; |
12 |
| - |
13 |
| -use lightning::ln::channelmonitor::{ManyChannelMonitor, ChannelMonitor, HTLCUpdate, ChannelMonitorUpdateErr, ChannelMonitorUpdate}; |
14 | 6 | use lightning::ln::channelmanager::{ChannelManager};
|
15 | 7 |
|
16 |
| -use crate::error::FFIResult; |
17 | 8 | use crate::handle::{Out, Ref, RefMut,HandleShared};
|
18 |
| - |
19 |
| -#[repr(C)] |
20 |
| -pub struct FFIManyChannelMonitor { |
21 |
| - add_monitor_ptr: extern "C" fn(&Self, funding_txo: OutPoint, monitor: ChannelMonitor<InMemoryChannelKeys>) -> i32, |
22 |
| - update_monitor_ptr: extern "C" fn(&Self, funding_txo: OutPoint, monitor: ChannelMonitorUpdate) -> i32, |
23 |
| - get_and_clear_pending_htlcs_updated_ptr: extern "C" fn(&Self) -> Vec<HTLCUpdate>, |
24 |
| -} |
25 |
| -impl FFIManyChannelMonitor { |
26 |
| - fn errorcode_to_result(errorcode: i32) -> Result<(), ChannelMonitorUpdateErr> { |
27 |
| - if errorcode == 0 { |
28 |
| - return Ok(()); |
29 |
| - } |
30 |
| - if errorcode == 1 { |
31 |
| - return Err(ChannelMonitorUpdateErr::PermanentFailure); |
32 |
| - } |
33 |
| - if errorcode == 2 { |
34 |
| - return Err(ChannelMonitorUpdateErr::TemporaryFailure); |
35 |
| - } |
36 |
| - unreachable!("Unknown error code from ffi {}", errorcode); |
37 |
| - } |
38 |
| -} |
39 |
| - |
40 |
| -impl ManyChannelMonitor<InMemoryChannelKeys> for FFIManyChannelMonitor { |
41 |
| - fn add_monitor(&self, funding_txo: OutPoint, monitor: ChannelMonitor<InMemoryChannelKeys>) -> Result<(), ChannelMonitorUpdateErr> { |
42 |
| - let errorcode = (self.add_monitor_ptr)(self, funding_txo, monitor); |
43 |
| - FFIManyChannelMonitor::errorcode_to_result(errorcode) |
44 |
| - } |
45 |
| - fn update_monitor(&self, funding_txo: OutPoint, monitor: ChannelMonitorUpdate) -> Result<(), ChannelMonitorUpdateErr> { |
46 |
| - let errorcode = (self.update_monitor_ptr)(self, funding_txo, monitor); |
47 |
| - FFIManyChannelMonitor::errorcode_to_result(errorcode) |
48 |
| - } |
49 |
| - fn get_and_clear_pending_htlcs_updated(&self) -> Vec<HTLCUpdate> { |
50 |
| - (self.get_and_clear_pending_htlcs_updated_ptr)(self) |
51 |
| - } |
52 |
| -} |
53 |
| - |
54 |
| -#[repr(C)] |
55 |
| -pub struct FFIBroadCaster { |
56 |
| - broadcast_transaction_ptr: extern "C" fn(&Self, tx: &Transaction), |
57 |
| -} |
58 |
| - |
59 |
| -impl BroadcasterInterface for FFIBroadCaster { |
60 |
| - fn broadcast_transaction(&self, tx: &Transaction) { |
61 |
| - (self.broadcast_transaction_ptr)(self, tx) |
62 |
| - } |
63 |
| -} |
64 |
| - |
65 |
| -#[repr(C)] |
66 |
| -pub struct FFIFeeEstimator { |
67 |
| - get_est_sat_per_1000_weight_ptr: extern "C" fn (&Self, ConfirmationTarget) -> u64, |
68 |
| -} |
69 |
| - |
70 |
| -impl FeeEstimator for FFIFeeEstimator { |
71 |
| - fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u64 { |
72 |
| - (self.get_est_sat_per_1000_weight_ptr)(self, confirmation_target) |
73 |
| - } |
74 |
| -} |
75 |
| - |
76 |
| -#[repr(C)] |
77 |
| -pub enum FFINetwork { |
78 |
| - MainNet = 0, |
79 |
| - TestNet = 1, |
80 |
| - RegTest = 2, |
81 |
| -} |
82 |
| - |
83 |
| -impl FFINetwork { |
84 |
| - pub fn to_network(&self) -> bitcoin::network::constants::Network { |
85 |
| - match self { |
86 |
| - FFINetwork::MainNet => { bitcoin::network::constants::Network::Bitcoin }, |
87 |
| - FFINetwork::TestNet => { bitcoin::network::constants::Network::Testnet }, |
88 |
| - FFINetwork::RegTest => { bitcoin::network::constants::Network::Regtest }, |
89 |
| - } |
90 |
| - } |
91 |
| -} |
92 |
| - |
93 |
| -#[repr(C)] |
94 |
| -pub struct FFILogger { |
95 |
| - log_ptr: fn(&Self, &Record), |
96 |
| -} |
97 |
| - |
98 |
| -impl Logger for FFILogger { |
99 |
| - fn log(&self, record: &Record) { |
100 |
| - (self.log_ptr)(self, record); |
101 |
| - } |
102 |
| -} |
| 9 | +use crate::error::FFIResult; |
| 10 | +use crate::adaptors::*; |
103 | 11 |
|
104 | 12 | type FFIArcChannelManager = ChannelManager<InMemoryChannelKeys, Arc<FFIManyChannelMonitor>, Arc<FFIBroadCaster>, Arc<KeysManager>, Arc<FFIFeeEstimator>>;
|
105 | 13 | type FFIArcChannelManagerHandle<'a> = HandleShared<'a, FFIArcChannelManager>;
|
|
0 commit comments