Skip to content

Commit c1640f4

Browse files
committed
cleanup: rename variables and remove unused deps
1 parent c77cd93 commit c1640f4

File tree

16 files changed

+45
-89
lines changed

16 files changed

+45
-89
lines changed

bindings/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,4 @@ secp256k1 = "0.15"
1818
bitcoin = "0.21"
1919
bitcoin_hashes = "0.7"
2020
hex = { version = "0.3", optional = true }
21-
libc = "0.2.68"
2221

23-
[build-dependencies]
24-
cbindgen = "0.13.1"

bindings/bindings.h

Lines changed: 0 additions & 4 deletions
This file was deleted.

bindings/build.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

bindings/hoge.rs

Whitespace-only changes.

bindings/src/adaptors/mod.rs

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
use std::sync::{Arc};
2-
use std::ffi::{CStr, CString, NulError};
3-
use std::convert::TryFrom;
4-
5-
use libc::c_char;
1+
use std::ffi::{CString};
62

73
use bitcoin_hashes::sha256d::Hash as Sha256dHash;
8-
use bitcoin::util::key::PrivateKey;
94
use bitcoin::blockdata::transaction::Transaction;
105
use bitcoin::blockdata::script::Script;
116
use bitcoin::blockdata::block::Block;
12-
use bitcoin::consensus::encode::serialize;
137

148
use lightning::util::logger::{Logger, Record, Level};
159

1610
use lightning::chain::chaininterface::{BroadcasterInterface,FeeEstimator,ConfirmationTarget, ChainWatchInterface, ChainError};
17-
use lightning::chain::keysinterface::{KeysManager, InMemoryChannelKeys};
11+
use lightning::chain::keysinterface::{InMemoryChannelKeys};
1812
use lightning::chain::transaction::{OutPoint};
1913

20-
use lightning::ln::chan_utils::ChannelPublicKeys;
2114
use lightning::ln::channelmonitor::{ManyChannelMonitor, ChannelMonitor, HTLCUpdate, ChannelMonitorUpdateErr, ChannelMonitorUpdate};
2215

23-
use crate::error::FFIResult;
24-
use crate::handle::{Out, Ref, RefMut,HandleShared};
25-
2616
pub mod primitives;
2717
use primitives::*;
2818

@@ -61,14 +51,14 @@ impl ManyChannelMonitor<InMemoryChannelKeys> for FFIManyChannelMonitor {
6151
}
6252
}
6353

64-
pub mod BroadcasterFn {
54+
pub mod broadcaster_fn {
6555
use crate::adaptors::primitives::FFITransaction;
66-
pub type broadcast_transaction_ptr = extern "cdecl" fn(tx: *const FFITransaction);
56+
pub type BroadcastTransactionPtr = extern "cdecl" fn(tx: *const FFITransaction);
6757
}
6858

6959
#[repr(C)]
7060
pub struct FFIBroadCaster {
71-
pub broadcast_transaction_ptr: BroadcasterFn::broadcast_transaction_ptr,
61+
pub broadcast_transaction_ptr: broadcaster_fn::BroadcastTransactionPtr,
7262
}
7363

7464
impl BroadcasterInterface for FFIBroadCaster {
@@ -97,14 +87,14 @@ impl From<ConfirmationTarget> for FFIConfirmationTarget {
9787
}
9888
}
9989

100-
pub mod FeeEstimatorFn {
90+
pub mod fee_estimator_fn {
10191
use super::{FFIConfirmationTarget, FFIFeeEstimator};
102-
pub type get_est_sat_per_1000_weight_ptr = extern "cdecl" fn (*const FFIFeeEstimator, FFIConfirmationTarget) -> u64;
92+
pub type GetEstSatPer1000WeightPtr = extern "cdecl" fn (*const FFIFeeEstimator, FFIConfirmationTarget) -> u64;
10393
}
10494

10595
#[repr(C)]
10696
pub struct FFIFeeEstimator {
107-
pub get_est_sat_per_1000_weight_ptr: FeeEstimatorFn::get_est_sat_per_1000_weight_ptr,
97+
pub get_est_sat_per_1000_weight_ptr: fee_estimator_fn::GetEstSatPer1000WeightPtr,
10898
}
10999

110100
impl FeeEstimator for FFIFeeEstimator {
@@ -182,9 +172,9 @@ impl<'a> From<Record<'a>> for FFILogRecord {
182172
let file = CString::new(rec.file).unwrap_or(CString::new("Record.file contains null char in the middle").unwrap());
183173
FFILogRecord {
184174
level: rec.level.into(),
185-
args: args,
186-
module_path: module_path,
187-
file: file,
175+
args,
176+
module_path,
177+
file,
188178
line: rec.line,
189179
}
190180
}
@@ -196,14 +186,14 @@ impl<'a, 'b> From<&'a Record<'b>> for FFILogRecord {
196186
}
197187
}
198188

199-
pub mod FFILoggerFn {
189+
pub mod ffilogger_fn {
200190
use super::{FFILogRecord, FFILogger};
201-
pub type log_extern = extern "cdecl" fn(logger: *const FFILogger, record: *const FFILogRecord);
191+
pub type LogExtern = extern "cdecl" fn(logger: *const FFILogger, record: *const FFILogRecord);
202192
}
203193

204194
#[repr(C)]
205195
pub struct FFILogger {
206-
pub log_ptr: FFILoggerFn::log_extern,
196+
pub log_ptr: ffilogger_fn::LogExtern,
207197
}
208198

209199
impl Logger for FFILogger {
@@ -213,30 +203,31 @@ impl Logger for FFILogger {
213203
}
214204
}
215205

216-
pub mod ChainWatchInterfaceFn {
206+
pub mod chain_watch_interface_fn {
217207
use super::*;
218-
pub type install_watch_tx_ptr = extern "cdecl" fn(*const FFIChainWatchInterface, *const FFISha256dHash, script_pub_key: *const FFIScript);
219-
pub type install_watch_outpoint_ptr = extern "cdecl" fn(*const FFIChainWatchInterface, outpoint: *const FFIOutPoint, out_script: *const FFIScript);
220-
pub type watch_all_txn_ptr = extern "cdecl" fn(*const FFIChainWatchInterface);
221-
pub type get_chain_utxo_ptr = extern "cdecl" fn(*const FFIChainWatchInterface, genesis_hash: *const FFISha256dHash, unspent_tx_output_identifier: u64, err: *mut ChainError, script: *mut FFITxOut);
222-
pub type filter_block_ptr = extern "cdecl" fn(*const FFIChainWatchInterface, *const FFIBlock);
208+
pub type InstallWatchTxPtr = extern "cdecl" fn(*const FFIChainWatchInterface, *const FFISha256dHash, script_pub_key: *const FFIScript);
209+
pub type InstallWatchOutpointPtr = extern "cdecl" fn(*const FFIChainWatchInterface, outpoint: *const FFIOutPoint, out_script: *const FFIScript);
210+
pub type WatchAllTxnPtr = extern "cdecl" fn(*const FFIChainWatchInterface);
211+
pub type GetChainUtxoPtr = extern "cdecl" fn(*const FFIChainWatchInterface, genesis_hash: *const FFISha256dHash, unspent_tx_output_identifier: u64, err: *mut ChainError, script: *mut FFITxOut);
212+
pub type FilterBlockPtr = extern "cdecl" fn(*const FFIChainWatchInterface, *const FFIBlock);
223213
}
224214

225215
#[repr(C)]
226216
pub struct FFIChainWatchInterface {
227-
pub install_watch_tx_ptr: ChainWatchInterfaceFn::install_watch_tx_ptr,
228-
pub install_watch_outpoint_ptr: ChainWatchInterfaceFn::install_watch_outpoint_ptr,
229-
pub watch_all_txn_ptr: ChainWatchInterfaceFn::watch_all_txn_ptr,
230-
pub get_chain_utxo_ptr: ChainWatchInterfaceFn::get_chain_utxo_ptr,
231-
pub filter_block_ptr: ChainWatchInterfaceFn::filter_block_ptr,
217+
pub install_watch_tx_ptr: chain_watch_interface_fn::InstallWatchTxPtr,
218+
pub install_watch_outpoint_ptr: chain_watch_interface_fn::InstallWatchOutpointPtr,
219+
pub watch_all_txn_ptr: chain_watch_interface_fn::WatchAllTxnPtr,
220+
pub get_chain_utxo_ptr: chain_watch_interface_fn::GetChainUtxoPtr,
221+
pub filter_block_ptr: chain_watch_interface_fn::FilterBlockPtr,
232222
}
233223

234224
impl ChainWatchInterface for FFIChainWatchInterface {
235225
fn install_watch_tx(&self, txid: &Sha256dHash, script_pub_key: &Script) {
236226
(self.install_watch_tx_ptr)(self, &txid.into() as *const _, &script_pub_key.into() as *const _)
237227
}
238228
fn install_watch_outpoint(&self, outpoint: (Sha256dHash, u32), out_script: &Script) {
239-
unimplemented!("TODO")
229+
let ffi_outpoint = FFIOutPoint { txid: outpoint.0.into(), index: outpoint.1 };
230+
(self.install_watch_outpoint_ptr)(self, &ffi_outpoint as *const _, &out_script.into() as *const _)
240231
}
241232
fn watch_all_txn(&self) {
242233
unimplemented!()

bindings/src/adaptors/primitives.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use bitcoin::consensus::serialize;
2-
use secp256k1::constants::{SECRET_KEY_SIZE, PUBLIC_KEY_SIZE};
32
use bitcoin::blockdata::script::Script;
4-
use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut};
5-
use bitcoin::blockdata::block::Block;
3+
use bitcoin::blockdata::transaction::{Transaction};
64
use bitcoin_hashes::sha256d::Hash as Sha256dHash;
75

86
macro_rules! array_struct{
9-
($name:ident, $ty:ty) => {
7+
(
8+
$(#[$outer:meta])*
9+
$name:ident, $ty:ty) => {
1010
#[repr(C)]
1111
pub struct $name<'a> {
1212
ptr: *const $ty,
@@ -21,10 +21,10 @@ macro_rules! array_struct{
2121
}
2222
}
2323

24-
/// The length must be `secp256k1::constants::SECRET_KEY_SIZE` ,
24+
#[doc="The length must be `secp256k1::constants::SECRET_KEY_SIZE`"]
2525
array_struct!(SecretKey, u8);
2626

27-
/// The length must be `secp256k1::constants::PUBLIC_KEY_SIZE` ,
27+
#[doc="The length must be `secp256k1::constants::PUBLIC_KEY_SIZE`"]
2828
array_struct!(PublicKey, u8);
2929

3030
array_struct!(FFISha256dHash, u8);
@@ -65,7 +65,7 @@ impl<'a> From<&Script> for FFIScript<'a> {
6565
#[repr(C)]
6666
pub struct FFIOutPoint<'a> {
6767
pub txid: FFISha256dHash<'a>,
68-
pub index: u16,
68+
pub index: u32,
6969
}
7070

7171
#[repr(C)]

bindings/src/broadcaster.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
/// ChannelMonitor or ChannelManager and hold a reference to it.
44
/// However, sometimes it is useful for testing.
55
6-
use std::sync::Arc;
76
use crate::adaptors::*;
8-
use bitcoin::Transaction;
97
use crate::handle::{Ref, Out, HandleShared};
108
use crate::error::FFIResult;
119

12-
use lightning::chain::chaininterface::{BroadcasterInterface};
13-
1410
type FFIBroadCasterHandle<'a> = HandleShared<'a, FFIBroadCaster>;
1511

1612
#[cfg(feature = "debug_assertions")]
@@ -31,7 +27,7 @@ type BroadcasterWrapperHandle<'a> = HandleShared<'a, BroadcasterWrapper>;
3127

3228

3329
ffi! {
34-
fn create_broadcaster(broadcast_transaction_ptr: Ref<BroadcasterFn::broadcast_transaction_ptr>, out: Out<FFIBroadCasterHandle>) -> FFIResult {
30+
fn create_broadcaster(broadcast_transaction_ptr: Ref<broadcaster_fn::BroadcastTransactionPtr>, out: Out<FFIBroadCasterHandle>) -> FFIResult {
3531
let broadcast_transaction = unsafe_block!("" => *broadcast_transaction_ptr.as_ref());
3632
let broadcaster = FFIBroadCaster{ broadcast_transaction_ptr: broadcast_transaction };
3733
unsafe_block!("" => out.init(HandleShared::alloc(broadcaster)));

bindings/src/chainwatcher.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ type ChainWatchInterfaceHandle<'a> = HandleShared<'a, FFIChainWatchInterface>;
66

77
ffi! {
88
fn create_chain_watch_interface(
9-
install_watch_tx_ref: Ref<ChainWatchInterfaceFn::install_watch_tx_ptr>,
10-
install_watch_outpoint_ref: Ref<ChainWatchInterfaceFn::install_watch_outpoint_ptr>,
11-
watch_all_txn_ref: Ref<ChainWatchInterfaceFn::watch_all_txn_ptr>,
12-
get_chain_utxo_ref: Ref<ChainWatchInterfaceFn::get_chain_utxo_ptr>,
13-
filter_block_ref: Ref<ChainWatchInterfaceFn::filter_block_ptr>,
9+
install_watch_tx_ref: Ref<chain_watch_interface_fn::InstallWatchTxPtr>,
10+
install_watch_outpoint_ref: Ref<chain_watch_interface_fn::InstallWatchOutpointPtr>,
11+
watch_all_txn_ref: Ref<chain_watch_interface_fn::WatchAllTxnPtr>,
12+
get_chain_utxo_ref: Ref<chain_watch_interface_fn::GetChainUtxoPtr>,
13+
filter_block_ref: Ref<chain_watch_interface_fn::FilterBlockPtr>,
1414
handle: Out<ChainWatchInterfaceHandle>
1515
) -> FFIResult {
1616
let install_watch_tx =

bindings/src/channelmanager.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
use bitcoin::blockdata::transaction::Transaction;
21
use std::sync::Arc;
32
use std::time::{SystemTime, UNIX_EPOCH};
43

54
use lightning::util::config::UserConfig;
65
use lightning::chain::keysinterface::{KeysManager, InMemoryChannelKeys};
76
use lightning::ln::channelmanager::{ChannelManager};
8-
use lightning::chain::chaininterface::{BroadcasterInterface};
97

10-
use crate::handle::{Out, Ref, RefMut,HandleShared};
8+
use crate::handle::{Out, Ref, HandleShared};
119
use crate::error::FFIResult;
1210
use crate::adaptors::*;
1311

1412
type FFIArcChannelManager = ChannelManager<InMemoryChannelKeys, Arc<FFIManyChannelMonitor>, Arc<FFIBroadCaster>, Arc<KeysManager>, Arc<FFIFeeEstimator>>;
1513
type FFIArcChannelManagerHandle<'a> = HandleShared<'a, FFIArcChannelManager>;
1614

17-
/// We wanted to use `ffi` macro here, but Arc<dyn Logger> does not support unwind safety.
15+
// We wanted to use `ffi` macro here, but Arc<dyn Logger> does not support unwind safety.
1816
ffi_no_catch!{
1917
fn create_ffi_channel_manager(
2018
seed_ptr: Ref<u8>,

bindings/src/channelmonitor.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
use std::sync::Arc;
22

3-
use bitcoin::blockdata::transaction::Transaction;
4-
5-
use lightning::chain::transaction::OutPoint;
63
use lightning::chain::keysinterface::{InMemoryChannelKeys};
74
use lightning::ln::channelmonitor::SimpleManyChannelMonitor;
85

96
use crate::adaptors::{FFIBroadCaster, FFIFeeEstimator, FFILogger, FFIChainWatchInterface};
10-
use crate::adaptors::primitives::{FFIScript, FFIOutPoint, FFIBlock, FFISha256dHash, FFITxOut, FFITransaction};
117
use crate::error::FFIResult;
128
use crate::handle::{Ref, HandleShared, Out};
139

bindings/src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
33
use std::error::Error;
44
use std::cell::RefCell;
5-
use std::slice;
6-
use std::ptr;
75
use std::ops::Try;
8-
use std::fmt;
96
use std::fmt::Write;
107
use std::panic::{catch_unwind, UnwindSafe};
118
use std::any::Any;

bindings/src/fee_estimator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::error::FFIResult;
55
type FeeEstimatorHandle<'a> = HandleShared<'a, FFIFeeEstimator>;
66

77
ffi! {
8-
fn create_fee_estimator(fn_ref: Ref<FeeEstimatorFn::get_est_sat_per_1000_weight_ptr>, out: Out<FeeEstimatorHandle>) -> FFIResult {
8+
fn create_fee_estimator(fn_ref: Ref<fee_estimator_fn::GetEstSatPer1000WeightPtr>, out: Out<FeeEstimatorHandle>) -> FFIResult {
99
let func = unsafe_block!("" => *fn_ref.as_ref());
1010
let fee_estimator = FFIFeeEstimator {get_est_sat_per_1000_weight_ptr: func};
1111
unsafe_block!("We know fee_estimator handle is not null by wrapper macro. And we know `Out` is writable" =>

bindings/src/handle/thread_bound.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::cell::UnsafeCell;
77
use std::collections::HashMap;
88
use std::ops::{Deref, DerefMut};
99

10-
use crate::utils::macros;
1110
use crate::lazy_static;
1211

1312
type ThreadId = usize;

bindings/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ mod handle;
3737
#[cfg(feature = "debug_assertions")]
3838
mod ffi_test_utils;
3939

40-
use std::sync::{Arc};
41-
4240
pub use handle::*;
4341
pub use error::*;
4442

bindings/src/logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::error::FFIResult;
55
type FFILoggerHandle<'a> = HandleShared<'a, FFILogger>;
66

77
ffi! {
8-
fn create_logger(log_ref: Ref<FFILoggerFn::log_extern>, out: Out<FFILoggerHandle>) -> FFIResult {
8+
fn create_logger(log_ref: Ref<ffilogger_fn::LogExtern>, out: Out<FFILoggerHandle>) -> FFIResult {
99
let log = unsafe_block!("" => *log_ref.as_ref());
1010
unsafe_block!("We know logger handle is not null by wrapper macro. And we know `Out` is writable" => out.init(FFILoggerHandle::alloc( FFILogger { log_ptr: log })));
1111
FFIResult::ok()

lightning/src/ln/channelmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl Writeable for InputMaterial {
474474
writer.write_all(&byte_utils::be64_to_array(*amount))?;
475475
}
476476
}
477-
Ok(())
477+
Ok(())
478478
}
479479
}
480480

0 commit comments

Comments
 (0)