X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmsgs.rs;h=4fccba37212ce8584af1ce83e8bddc697a68f5ae;hb=4395b92cc8bfe0cc803e70bba11f4db58d5d0dbf;hp=9698798c22ee0ae79ec24e002ef47220e616e2c4;hpb=d3b6083ea283d865af7236c600ad3df1ab0b19df;p=rust-lightning diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 9698798c..4fccba37 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1,3 +1,12 @@ +// This file is Copyright its original authors, visible in version control +// history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. + //! Wire messages, traits representing wire message handlers, and a few error types live here. //! //! For a normal node you probably don't need to use anything here, however, if you wish to split a @@ -15,18 +24,16 @@ //! raw socket events into your non-internet-facing system and then send routing events back to //! track the network on the less-secure system. -use secp256k1::key::PublicKey; -use secp256k1::Signature; -use secp256k1; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +use bitcoin::secp256k1::key::PublicKey; +use bitcoin::secp256k1::Signature; +use bitcoin::secp256k1; use bitcoin::blockdata::script::Script; +use bitcoin::hash_types::{Txid, BlockHash}; use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; -use std::error::Error; use std::{cmp, fmt}; use std::io::Read; -use std::result::Result; use util::events; use util::ser::{Readable, Writeable, Writer, FixedLengthReader, HighZeroBytesDroppedVarInt}; @@ -85,7 +92,7 @@ pub struct Pong { /// An open_channel message to be sent or received from a peer #[derive(Clone)] pub struct OpenChannel { - pub(crate) chain_hash: Sha256dHash, + pub(crate) chain_hash: BlockHash, pub(crate) temporary_channel_id: [u8; 32], pub(crate) funding_satoshis: u64, pub(crate) push_msat: u64, @@ -98,7 +105,7 @@ pub struct OpenChannel { pub(crate) max_accepted_htlcs: u16, pub(crate) funding_pubkey: PublicKey, pub(crate) revocation_basepoint: PublicKey, - pub(crate) payment_basepoint: PublicKey, + pub(crate) payment_point: PublicKey, pub(crate) delayed_payment_basepoint: PublicKey, pub(crate) htlc_basepoint: PublicKey, pub(crate) first_per_commitment_point: PublicKey, @@ -119,7 +126,7 @@ pub struct AcceptChannel { pub(crate) max_accepted_htlcs: u16, pub(crate) funding_pubkey: PublicKey, pub(crate) revocation_basepoint: PublicKey, - pub(crate) payment_basepoint: PublicKey, + pub(crate) payment_point: PublicKey, pub(crate) delayed_payment_basepoint: PublicKey, pub(crate) htlc_basepoint: PublicKey, pub(crate) first_per_commitment_point: PublicKey, @@ -130,7 +137,7 @@ pub struct AcceptChannel { #[derive(Clone)] pub struct FundingCreated { pub(crate) temporary_channel_id: [u8; 32], - pub(crate) funding_txid: Sha256dHash, + pub(crate) funding_txid: Txid, pub(crate) funding_output_index: u16, pub(crate) signature: Signature, } @@ -392,7 +399,7 @@ pub struct UnsignedNodeAnnouncement { pub(crate) excess_address_data: Vec, pub(crate) excess_data: Vec, } -#[derive(PartialEq, Clone)] +#[derive(PartialEq, Clone, Debug)] /// A node_announcement message to be sent or received from a peer pub struct NodeAnnouncement { pub(crate) signature: Signature, @@ -404,7 +411,7 @@ pub struct NodeAnnouncement { #[derive(PartialEq, Clone, Debug)] pub struct UnsignedChannelAnnouncement { pub(crate) features: ChannelFeatures, - pub(crate) chain_hash: Sha256dHash, + pub(crate) chain_hash: BlockHash, pub(crate) short_channel_id: u64, /// One of the two node_ids which are endpoints of this channel pub node_id_1: PublicKey, @@ -426,12 +433,13 @@ pub struct ChannelAnnouncement { #[derive(PartialEq, Clone, Debug)] pub(crate) struct UnsignedChannelUpdate { - pub(crate) chain_hash: Sha256dHash, + pub(crate) chain_hash: BlockHash, pub(crate) short_channel_id: u64, pub(crate) timestamp: u32, - pub(crate) flags: u16, + pub(crate) flags: u8, pub(crate) cltv_expiry_delta: u16, pub(crate) htlc_minimum_msat: u64, + pub(crate) htlc_maximum_msat: OptionalField, pub(crate) fee_base_msat: u32, pub(crate) fee_proportional_millionths: u32, pub(crate) excess_data: Vec, @@ -463,7 +471,7 @@ pub enum ErrorAction { /// An Err type for failure to process messages. pub struct LightningError { /// A human-readable message describing the error - pub err: &'static str, + pub err: String, /// The action which should be taken against the offending peer. pub action: ErrorAction, } @@ -519,7 +527,7 @@ pub enum HTLCFailChannelUpdate { /// As we wish to serialize these differently from Options (Options get a tag byte, but /// OptionalFeild simply gets Present if there are enough bytes to read into it), we have a /// separate enum type for them. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Debug)] pub enum OptionalField { /// Optional field is included in message Present(T), @@ -688,27 +696,22 @@ pub(crate) struct OnionErrorPacket { pub(crate) data: Vec, } -impl Error for DecodeError { - fn description(&self) -> &str { - match *self { - DecodeError::UnknownVersion => "Unknown realm byte in Onion packet", - DecodeError::UnknownRequiredFeature => "Unknown required feature preventing decode", - DecodeError::InvalidValue => "Nonsense bytes didn't map to the type they were interpreted as", - DecodeError::ShortRead => "Packet extended beyond the provided bytes", - DecodeError::BadLengthDescriptor => "A length descriptor in the packet didn't describe the later data correctly", - DecodeError::Io(ref e) => e.description(), - } - } -} impl fmt::Display for DecodeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(self.description()) + match *self { + DecodeError::UnknownVersion => f.write_str("Unknown realm byte in Onion packet"), + DecodeError::UnknownRequiredFeature => f.write_str("Unknown required feature preventing decode"), + DecodeError::InvalidValue => f.write_str("Nonsense bytes didn't map to the type they were interpreted as"), + DecodeError::ShortRead => f.write_str("Packet extended beyond the provided bytes"), + DecodeError::BadLengthDescriptor => f.write_str("A length descriptor in the packet didn't describe the later data correctly"), + DecodeError::Io(ref e) => e.fmt(f), + } } } impl fmt::Debug for LightningError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(self.err) + f.write_str(self.err.as_str()) } } @@ -749,6 +752,26 @@ impl Readable for OptionalField