Skip to content

Commit 8f23cf4

Browse files
committed
Three small fixes to work around our bindings generator limitations
* Return Self instead of the fully-written types for constructors, * Place definitions before use (in this case for KeysInterface), * Don't import foo::bar::self, but import foo::bar
1 parent cec331f commit 8f23cf4

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,28 +142,6 @@ impl Readable for SpendableOutputDescriptor {
142142
}
143143
}
144144

145-
/// A trait to describe an object which can get user secrets and key material.
146-
pub trait KeysInterface: Send + Sync {
147-
/// A type which implements ChannelKeys which will be returned by get_channel_keys.
148-
type ChanKeySigner : ChannelKeys;
149-
150-
/// Get node secret key (aka node_id or network_key)
151-
fn get_node_secret(&self) -> SecretKey;
152-
/// Get destination redeemScript to encumber static protocol exit points.
153-
fn get_destination_script(&self) -> Script;
154-
/// Get shutdown_pubkey to use as PublicKey at channel closure
155-
fn get_shutdown_pubkey(&self) -> PublicKey;
156-
/// Get a new set of ChannelKeys for per-channel secrets. These MUST be unique even if you
157-
/// restarted with some stale data!
158-
fn get_channel_keys(&self, inbound: bool, channel_value_satoshis: u64) -> Self::ChanKeySigner;
159-
/// Get a secret and PRNG seed for construting an onion packet
160-
fn get_onion_rand(&self) -> (SecretKey, [u8; 32]);
161-
/// Get a unique temporary channel id. Channels will be referred to by this until the funding
162-
/// transaction is created, at which point they will use the outpoint in the funding
163-
/// transaction.
164-
fn get_channel_id(&self) -> [u8; 32];
165-
}
166-
167145
/// Set of lightning keys needed to operate a channel as described in BOLT 3.
168146
///
169147
/// Signing services could be implemented on a hardware wallet. In this case,
@@ -269,6 +247,29 @@ pub trait ChannelKeys : Send+Clone {
269247
fn set_remote_channel_pubkeys(&mut self, channel_points: &ChannelPublicKeys);
270248
}
271249

250+
251+
/// A trait to describe an object which can get user secrets and key material.
252+
pub trait KeysInterface: Send + Sync {
253+
/// A type which implements ChannelKeys which will be returned by get_channel_keys.
254+
type ChanKeySigner : ChannelKeys;
255+
256+
/// Get node secret key (aka node_id or network_key)
257+
fn get_node_secret(&self) -> SecretKey;
258+
/// Get destination redeemScript to encumber static protocol exit points.
259+
fn get_destination_script(&self) -> Script;
260+
/// Get shutdown_pubkey to use as PublicKey at channel closure
261+
fn get_shutdown_pubkey(&self) -> PublicKey;
262+
/// Get a new set of ChannelKeys for per-channel secrets. These MUST be unique even if you
263+
/// restarted with some stale data!
264+
fn get_channel_keys(&self, inbound: bool, channel_value_satoshis: u64) -> Self::ChanKeySigner;
265+
/// Get a secret and PRNG seed for construting an onion packet
266+
fn get_onion_rand(&self) -> (SecretKey, [u8; 32]);
267+
/// Get a unique temporary channel id. Channels will be referred to by this until the funding
268+
/// transaction is created, at which point they will use the outpoint in the funding
269+
/// transaction.
270+
fn get_channel_id(&self) -> [u8; 32];
271+
}
272+
272273
#[derive(Clone)]
273274
/// A simple implementation of ChannelKeys that just keeps the private keys in memory.
274275
pub struct InMemoryChannelKeys {
@@ -509,7 +510,7 @@ impl KeysManager {
509510
/// Note that until the 0.1 release there is no guarantee of backward compatibility between
510511
/// versions. Once the library is more fully supported, the docs will be updated to include a
511512
/// detailed description of the guarantee.
512-
pub fn new(seed: &[u8; 32], network: Network, logger: Arc<Logger>, starting_time_secs: u64, starting_time_nanos: u32) -> KeysManager {
513+
pub fn new(seed: &[u8; 32], network: Network, logger: Arc<Logger>, starting_time_secs: u64, starting_time_nanos: u32) -> Self {
513514
let secp_ctx = Secp256k1::signing_only();
514515
match ExtendedPrivKey::new_master(network.clone(), seed) {
515516
Ok(master_key) => {

lightning/src/ln/chan_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
use bitcoin::blockdata::script::{Script,Builder};
66
use bitcoin::blockdata::opcodes;
77
use bitcoin::blockdata::transaction::{TxIn,TxOut,OutPoint,Transaction, SigHashType};
8-
use bitcoin::consensus::encode::{self, Decodable, Encodable};
8+
use bitcoin::consensus::encode::{Decodable, Encodable};
9+
use bitcoin::consensus::encode;
910
use bitcoin::util::bip143;
1011

1112
use bitcoin::hashes::{Hash, HashEngine};

0 commit comments

Comments
 (0)