X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannel_id.rs;h=19003961ff1a52bced58e52622dd59add517bfed;hb=cf2c27800a1b30e72d4f7397c931cf6624594233;hp=621ebf0c460333446e22d2a28bd7bdc4b724dae8;hpb=61d896d5193bad813ce53cc823e9f2afa17e09a8;p=rust-lightning diff --git a/lightning/src/ln/channel_id.rs b/lightning/src/ln/channel_id.rs index 621ebf0c..19003961 100644 --- a/lightning/src/ln/channel_id.rs +++ b/lightning/src/ln/channel_id.rs @@ -9,19 +9,20 @@ //! ChannelId definition. +use crate::chain::transaction::OutPoint; +use crate::io; use crate::ln::msgs::DecodeError; use crate::sign::EntropySource; use crate::util::ser::{Readable, Writeable, Writer}; -use bitcoin::hashes::hex::ToHex; - -use crate::io; -use crate::prelude::*; +use bitcoin::hashes::Hash as _; use core::fmt; use core::ops::Deref; /// A unique 32-byte identifier for a channel. -/// Depending on how the ID is generated, several varieties are distinguished (but all are stored as 32 bytes): _v1_ and _temporary_. +/// Depending on how the ID is generated, several varieties are distinguished +/// (but all are stored as 32 bytes): +/// _v1_ and _temporary_. /// A _v1_ channel ID is generated based on funding tx outpoint (txid & index). /// A _temporary_ ID is generated randomly. /// (Later revocation-point-based _v2_ is a possibility.) @@ -41,6 +42,11 @@ impl ChannelId { Self(res) } + /// Create _v1_ channel ID from a funding tx outpoint + pub fn v1_from_funding_outpoint(outpoint: OutPoint) -> Self { + Self::v1_from_funding_txid(outpoint.txid.as_byte_array(), outpoint.index) + } + /// Create a _temporary_ channel ID randomly, based on an entropy source. pub fn temporary_from_entropy_source(entropy_source: &ES) -> Self where ES::Target: EntropySource { @@ -77,12 +83,6 @@ impl Readable for ChannelId { } } -impl ToHex for ChannelId { - fn to_hex(&self) -> String { - self.0.to_hex() - } -} - impl fmt::Display for ChannelId { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { crate::util::logger::DebugBytes(&self.0).fmt(f) @@ -91,17 +91,18 @@ impl fmt::Display for ChannelId { #[cfg(test)] mod tests { + use hex::DisplayHex; + use crate::ln::ChannelId; use crate::util::ser::{Readable, Writeable}; use crate::util::test_utils; - use bitcoin::hashes::hex::ToHex; use crate::prelude::*; use crate::io; #[test] fn test_channel_id_v1_from_funding_txid() { let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1); - assert_eq!(channel_id.to_hex(), "0202020202020202020202020202020202020202020202020202020202020203"); + assert_eq!(channel_id.0.as_hex().to_string(), "0202020202020202020202020202020202020202020202020202020202020203"); } #[test]