Three small fixes to work around our bindings generator limitations
authorMatt Corallo <git@bluematt.me>
Tue, 12 May 2020 17:47:54 +0000 (13:47 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 22 May 2020 18:28:56 +0000 (14:28 -0400)
 * 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

 + a spelling fix in the KeysInterface docs for get_onion_rand.

lightning/src/chain/keysinterface.rs
lightning/src/ln/chan_utils.rs

index cf1f4f869f5c395169d09faeb26e418d0e812db7..47eafa35a89bdf242c765e9eea0be25ae56e292e 100644 (file)
@@ -140,28 +140,6 @@ impl Readable for SpendableOutputDescriptor {
        }
 }
 
-/// A trait to describe an object which can get user secrets and key material.
-pub trait KeysInterface: Send + Sync {
-       /// A type which implements ChannelKeys which will be returned by get_channel_keys.
-       type ChanKeySigner : ChannelKeys;
-
-       /// Get node secret key (aka node_id or network_key)
-       fn get_node_secret(&self) -> SecretKey;
-       /// Get destination redeemScript to encumber static protocol exit points.
-       fn get_destination_script(&self) -> Script;
-       /// Get shutdown_pubkey to use as PublicKey at channel closure
-       fn get_shutdown_pubkey(&self) -> PublicKey;
-       /// Get a new set of ChannelKeys for per-channel secrets. These MUST be unique even if you
-       /// restarted with some stale data!
-       fn get_channel_keys(&self, inbound: bool, channel_value_satoshis: u64) -> Self::ChanKeySigner;
-       /// Get a secret and PRNG seed for construting an onion packet
-       fn get_onion_rand(&self) -> (SecretKey, [u8; 32]);
-       /// Get a unique temporary channel id. Channels will be referred to by this until the funding
-       /// transaction is created, at which point they will use the outpoint in the funding
-       /// transaction.
-       fn get_channel_id(&self) -> [u8; 32];
-}
-
 /// Set of lightning keys needed to operate a channel as described in BOLT 3.
 ///
 /// Signing services could be implemented on a hardware wallet. In this case,
@@ -267,6 +245,28 @@ pub trait ChannelKeys : Send+Clone {
        fn set_remote_channel_pubkeys(&mut self, channel_points: &ChannelPublicKeys);
 }
 
+/// A trait to describe an object which can get user secrets and key material.
+pub trait KeysInterface: Send + Sync {
+       /// A type which implements ChannelKeys which will be returned by get_channel_keys.
+       type ChanKeySigner : ChannelKeys;
+
+       /// Get node secret key (aka node_id or network_key)
+       fn get_node_secret(&self) -> SecretKey;
+       /// Get destination redeemScript to encumber static protocol exit points.
+       fn get_destination_script(&self) -> Script;
+       /// Get shutdown_pubkey to use as PublicKey at channel closure
+       fn get_shutdown_pubkey(&self) -> PublicKey;
+       /// Get a new set of ChannelKeys for per-channel secrets. These MUST be unique even if you
+       /// restarted with some stale data!
+       fn get_channel_keys(&self, inbound: bool, channel_value_satoshis: u64) -> Self::ChanKeySigner;
+       /// Get a secret and PRNG seed for constructing an onion packet
+       fn get_onion_rand(&self) -> (SecretKey, [u8; 32]);
+       /// Get a unique temporary channel id. Channels will be referred to by this until the funding
+       /// transaction is created, at which point they will use the outpoint in the funding
+       /// transaction.
+       fn get_channel_id(&self) -> [u8; 32];
+}
+
 #[derive(Clone)]
 /// A simple implementation of ChannelKeys that just keeps the private keys in memory.
 pub struct InMemoryChannelKeys {
@@ -506,7 +506,7 @@ impl KeysManager {
        /// Note that until the 0.1 release there is no guarantee of backward compatibility between
        /// versions. Once the library is more fully supported, the docs will be updated to include a
        /// detailed description of the guarantee.
-       pub fn new(seed: &[u8; 32], network: Network, starting_time_secs: u64, starting_time_nanos: u32) -> KeysManager {
+       pub fn new(seed: &[u8; 32], network: Network, starting_time_secs: u64, starting_time_nanos: u32) -> Self {
                let secp_ctx = Secp256k1::signing_only();
                match ExtendedPrivKey::new_master(network.clone(), seed) {
                        Ok(master_key) => {
index c229819c3b64e6d3e875002c814190a1d40e153e..949d008c0d7d23ff69af82e8c80f568814875233 100644 (file)
@@ -5,7 +5,8 @@
 use bitcoin::blockdata::script::{Script,Builder};
 use bitcoin::blockdata::opcodes;
 use bitcoin::blockdata::transaction::{TxIn,TxOut,OutPoint,Transaction, SigHashType};
-use bitcoin::consensus::encode::{self, Decodable, Encodable};
+use bitcoin::consensus::encode::{Decodable, Encodable};
+use bitcoin::consensus::encode;
 use bitcoin::util::bip143;
 
 use bitcoin::hashes::{Hash, HashEngine};