X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmsgs.rs;h=39cb9454db89a541ac5f039e8aa11d9d09ab8854;hb=17a74fcfc74936b48923bba5a416be73a01d2367;hp=2124d905558f684dc9e33c1ce49ec257a925e7a5;hpb=adc1b55a6fa064852d838ceb91b11e6b228d169e;p=rust-lightning diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 2124d905..39cb9454 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -26,7 +26,7 @@ use bitcoin::secp256k1::PublicKey; use bitcoin::secp256k1::ecdsa::Signature; -use bitcoin::{secp256k1, Witness, Transaction}; +use bitcoin::{secp256k1, Witness}; use bitcoin::blockdata::script::Script; use bitcoin::hash_types::{Txid, BlockHash}; @@ -42,7 +42,7 @@ use crate::io_extras::read_to_end; use crate::events::{MessageSendEventsProvider, OnionMessageProvider}; use crate::util::logger; -use crate::util::ser::{LengthReadable, Readable, ReadableArgs, Writeable, Writer, WithoutLength, FixedLengthReader, HighZeroBytesDroppedBigSize, Hostname}; +use crate::util::ser::{LengthReadable, Readable, ReadableArgs, Writeable, Writer, WithoutLength, FixedLengthReader, HighZeroBytesDroppedBigSize, Hostname, TransactionU16LenLimited}; use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret}; @@ -425,45 +425,6 @@ pub struct ChannelReady { pub short_channel_id_alias: Option, } -/// A wrapper for a `Transaction` which can only be constructed with [`TransactionU16LenLimited::new`] -/// if the `Transaction`'s consensus-serialized length is <= u16::MAX. -/// -/// Use [`TransactionU16LenLimited::into_transaction`] to convert into the contained `Transaction`. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct TransactionU16LenLimited(Transaction); - -impl TransactionU16LenLimited { - /// Constructs a new `TransactionU16LenLimited` from a `Transaction` only if it's consensus- - /// serialized length is <= u16::MAX. - pub fn new(transaction: Transaction) -> Result { - if transaction.serialized_length() > (u16::MAX as usize) { - Err(()) - } else { - Ok(Self(transaction)) - } - } - - /// Consumes this `TransactionU16LenLimited` and returns its contained `Transaction`. - pub fn into_transaction(self) -> Transaction { - self.0 - } -} - -impl Writeable for TransactionU16LenLimited { - fn write(&self, w: &mut W) -> Result<(), io::Error> { - (self.0.serialized_length() as u16).write(w)?; - self.0.write(w) - } -} - -impl Readable for TransactionU16LenLimited { - fn read(r: &mut R) -> Result { - let len = ::read(r)?; - let mut tx_reader = FixedLengthReader::new(r, len as u64); - Ok(Self(Readable::read(&mut tx_reader)?)) - } -} - /// A tx_add_input message for adding an input during interactive transaction construction /// // TODO(dual_funding): Add spec link for `tx_add_input`. @@ -850,7 +811,7 @@ impl NetAddress { } impl Writeable for NetAddress { -fn write(&self, writer: &mut W) -> Result<(), io::Error> { + fn write(&self, writer: &mut W) -> Result<(), io::Error> { match self { &NetAddress::IPv4 { ref addr, ref port } => { 1u8.write(writer)?; @@ -1237,8 +1198,12 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider { // Channel init: /// Handle an incoming `open_channel` message from the given peer. fn handle_open_channel(&self, their_node_id: &PublicKey, msg: &OpenChannel); + /// Handle an incoming `open_channel2` message from the given peer. + fn handle_open_channel_v2(&self, their_node_id: &PublicKey, msg: &OpenChannelV2); /// Handle an incoming `accept_channel` message from the given peer. fn handle_accept_channel(&self, their_node_id: &PublicKey, msg: &AcceptChannel); + /// Handle an incoming `accept_channel2` message from the given peer. + fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, msg: &AcceptChannelV2); /// Handle an incoming `funding_created` message from the given peer. fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &FundingCreated); /// Handle an incoming `funding_signed` message from the given peer. @@ -1252,6 +1217,26 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider { /// Handle an incoming `closing_signed` message from the given peer. fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &ClosingSigned); + // Interactive channel construction + /// Handle an incoming `tx_add_input message` from the given peer. + fn handle_tx_add_input(&self, their_node_id: &PublicKey, msg: &TxAddInput); + /// Handle an incoming `tx_add_output` message from the given peer. + fn handle_tx_add_output(&self, their_node_id: &PublicKey, msg: &TxAddOutput); + /// Handle an incoming `tx_remove_input` message from the given peer. + fn handle_tx_remove_input(&self, their_node_id: &PublicKey, msg: &TxRemoveInput); + /// Handle an incoming `tx_remove_output` message from the given peer. + fn handle_tx_remove_output(&self, their_node_id: &PublicKey, msg: &TxRemoveOutput); + /// Handle an incoming `tx_complete message` from the given peer. + fn handle_tx_complete(&self, their_node_id: &PublicKey, msg: &TxComplete); + /// Handle an incoming `tx_signatures` message from the given peer. + fn handle_tx_signatures(&self, their_node_id: &PublicKey, msg: &TxSignatures); + /// Handle an incoming `tx_init_rbf` message from the given peer. + fn handle_tx_init_rbf(&self, their_node_id: &PublicKey, msg: &TxInitRbf); + /// Handle an incoming `tx_ack_rbf` message from the given peer. + fn handle_tx_ack_rbf(&self, their_node_id: &PublicKey, msg: &TxAckRbf); + /// Handle an incoming `tx_abort message` from the given peer. + fn handle_tx_abort(&self, their_node_id: &PublicKey, msg: &TxAbort); + // HTLC handling: /// Handle an incoming `update_add_htlc` message from the given peer. fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &UpdateAddHTLC); @@ -2430,10 +2415,9 @@ mod tests { use hex; use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret}; use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures}; - use crate::ln::msgs::{self, TransactionU16LenLimited}; - use crate::ln::msgs::{FinalOnionHopData, OnionErrorPacket, OnionHopDataFormat}; + use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket, OnionHopDataFormat}; use crate::routing::gossip::{NodeAlias, NodeId}; - use crate::util::ser::{Writeable, Readable, Hostname}; + use crate::util::ser::{Writeable, Readable, Hostname, TransactionU16LenLimited}; use bitcoin::hashes::hex::FromHex; use bitcoin::util::address::Address;