From: Matt Corallo Date: Tue, 12 May 2020 17:17:49 +0000 (-0400) Subject: Drop OutPoint::new since the struct is all pub X-Git-Tag: v0.0.12~61^2~5 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=8ade071d568f8668e3f820e43c894b9e574fd569;p=rust-lightning Drop OutPoint::new since the struct is all pub This makes it easier for our automated bindings generator to function as it tries to automatically create a ::new if the struct contains only pub elements who's type is convertible. --- diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index e9f56a3e4..e0fa7d3ed 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -267,7 +267,7 @@ pub fn do_test(data: &[u8], out: Out) { let tx = Transaction { version: $chan_id, lock_time: 0, input: Vec::new(), output: vec![TxOut { value: *channel_value_satoshis, script_pubkey: output_script.clone(), }]}; - funding_output = OutPoint::new(tx.txid(), 0); + funding_output = OutPoint { txid: tx.txid(), index: 0 }; $source.funding_transaction_generated(&temporary_channel_id, funding_output); channel_txn.push(tx); } else { panic!("Wrong event type"); } diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 2af173cfc..81cf6a248 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -476,7 +476,7 @@ pub fn do_test(data: &[u8], logger: &Arc) { let funding_output = 'search_loop: loop { let funding_txid = tx.txid(); if let None = loss_detector.txids_confirmed.get(&funding_txid) { - let outpoint = OutPoint::new(funding_txid, 0); + let outpoint = OutPoint { txid: funding_txid, index: 0 }; for chan in channelmanager.list_channels() { if chan.channel_id == outpoint.to_channel_id() { tx.version += 1; diff --git a/lightning/src/chain/transaction.rs b/lightning/src/chain/transaction.rs index 33b9c7244..d490797bc 100644 --- a/lightning/src/chain/transaction.rs +++ b/lightning/src/chain/transaction.rs @@ -16,11 +16,6 @@ pub struct OutPoint { } impl OutPoint { - /// Creates a new `OutPoint` from the txid and the index. - pub fn new(txid: Txid, index: u16) -> OutPoint { - OutPoint { txid, index } - } - /// Convert an `OutPoint` to a lightning channel id. pub fn to_channel_id(&self) -> [u8; 32] { let mut res = [0; 32]; diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index c9eebf41e..6ddaa8fd8 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1486,7 +1486,7 @@ impl Channel { panic!("Should not have advanced channel commitment tx numbers prior to funding_created"); } - let funding_txo = OutPoint::new(msg.funding_txid, msg.funding_output_index); + let funding_txo = OutPoint{ txid: msg.funding_txid, index: msg.funding_output_index }; self.funding_txo = Some(funding_txo.clone()); let (remote_initial_commitment_tx, local_initial_commitment_tx, our_signature) = match self.funding_created_signature(&msg.signature, logger) { @@ -4387,7 +4387,7 @@ mod tests { let tx = Transaction { version: 1, lock_time: 0, input: Vec::new(), output: vec![TxOut { value: 10000000, script_pubkey: output_script.clone(), }]}; - let funding_outpoint = OutPoint::new(tx.txid(), 0); + let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 }; let funding_created_msg = node_a_chan.get_outbound_funding_created(funding_outpoint, &&logger).unwrap(); let (funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, &&logger).unwrap(); @@ -4452,7 +4452,7 @@ mod tests { chan.their_to_self_delay = 144; chan.our_dust_limit_satoshis = 546; - let funding_info = OutPoint::new(Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), 0); + let funding_info = OutPoint{ txid: Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), index: 0 }; chan.funding_txo = Some(funding_info); let their_pubkeys = ChannelPublicKeys { diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index a8c4d2797..68268316f 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -320,7 +320,7 @@ pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_ let tx = Transaction { version: chan_id as u32, lock_time: 0, input: Vec::new(), output: vec![TxOut { value: *channel_value_satoshis, script_pubkey: output_script.clone(), }]}; - let funding_outpoint = OutPoint::new(tx.txid(), 0); + let funding_outpoint = OutPoint { txid: tx.txid(), index: 0 }; (*temporary_channel_id, tx, funding_outpoint) }, _ => panic!("Unexpected event"), diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 2311a03fc..da4755696 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -822,7 +822,7 @@ fn pre_funding_lock_shutdown_test() { nodes[0].block_notifier.block_connected(&Block { header, txdata: vec![tx.clone()]}, 1); nodes[1].block_notifier.block_connected(&Block { header, txdata: vec![tx.clone()]}, 1); - nodes[0].node.close_channel(&OutPoint::new(tx.txid(), 0).to_channel_id()).unwrap(); + nodes[0].node.close_channel(&OutPoint { txid: tx.txid(), index: 0 }.to_channel_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); @@ -3111,7 +3111,7 @@ fn test_force_close_fail_back() { // Now check that if we add the preimage to ChannelMonitor it broadcasts our HTLC-Success.. { let mut monitors = nodes[2].chan_monitor.simple_monitor.monitors.lock().unwrap(); - monitors.get_mut(&OutPoint::new(Txid::from_slice(&payment_event.commitment_msg.channel_id[..]).unwrap(), 0)).unwrap() + monitors.get_mut(&OutPoint{ txid: Txid::from_slice(&payment_event.commitment_msg.channel_id[..]).unwrap(), index: 0 }).unwrap() .provide_payment_preimage(&our_payment_hash, &our_payment_preimage); } nodes[2].block_notifier.block_connected_checked(&header, 1, &[&tx], &[1]); @@ -6900,7 +6900,7 @@ fn test_upfront_shutdown_script() { // We test that in case of peer committing upfront to a script, if it changes at closing, we refuse to sign let flags = InitFeatures::known(); let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 1000000, 1000000, flags.clone(), flags.clone()); - nodes[0].node.close_channel(&OutPoint::new(chan.3.txid(), 0).to_channel_id()).unwrap(); + nodes[0].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap(); let mut node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id()); node_0_shutdown.scriptpubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script().to_p2sh(); // Test we enforce upfront_scriptpbukey if by providing a diffrent one at closing that we disconnect peer @@ -6910,7 +6910,7 @@ fn test_upfront_shutdown_script() { // We test that in case of peer committing upfront to a script, if it doesn't change at closing, we sign let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 1000000, 1000000, flags.clone(), flags.clone()); - nodes[0].node.close_channel(&OutPoint::new(chan.3.txid(), 0).to_channel_id()).unwrap(); + nodes[0].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id()); // We test that in case of peer committing upfront to a script, if it oesn't change at closing, we sign nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); @@ -6924,7 +6924,7 @@ fn test_upfront_shutdown_script() { // We test that if case of peer non-signaling we don't enforce committed script at channel opening let flags_no = InitFeatures::known().clear_upfront_shutdown_script(); let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, flags_no, flags.clone()); - nodes[0].node.close_channel(&OutPoint::new(chan.3.txid(), 0).to_channel_id()).unwrap(); + nodes[0].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap(); let mut node_1_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); node_1_shutdown.scriptpubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script().to_p2sh(); nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_1_shutdown); @@ -6938,7 +6938,7 @@ fn test_upfront_shutdown_script() { // We test that if user opt-out, we provide a zero-length script at channel opening and we are able to close // channel smoothly, opt-out is from channel initiator here let chan = create_announced_chan_between_nodes_with_value(&nodes, 1, 0, 1000000, 1000000, flags.clone(), flags.clone()); - nodes[1].node.close_channel(&OutPoint::new(chan.3.txid(), 0).to_channel_id()).unwrap(); + nodes[1].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap(); let mut node_0_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); node_0_shutdown.scriptpubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script().to_p2sh(); nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_0_shutdown); @@ -6952,7 +6952,7 @@ fn test_upfront_shutdown_script() { //// We test that if user opt-out, we provide a zero-length script at channel opening and we are able to close //// channel smoothly let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, flags.clone(), flags.clone()); - nodes[1].node.close_channel(&OutPoint::new(chan.3.txid(), 0).to_channel_id()).unwrap(); + nodes[1].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap(); let mut node_0_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); node_0_shutdown.scriptpubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script().to_p2sh(); nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_0_shutdown); @@ -7759,7 +7759,7 @@ fn test_bump_txn_sanitize_tracking_maps() { connect_blocks(&nodes[0].block_notifier, 5, 130, false, header_130.bitcoin_hash()); { let monitors = nodes[0].chan_monitor.simple_monitor.monitors.lock().unwrap(); - if let Some(monitor) = monitors.get(&OutPoint::new(chan.3.txid(), 0)) { + if let Some(monitor) = monitors.get(&OutPoint { txid: chan.3.txid(), index: 0 }) { assert!(monitor.onchain_tx_handler.pending_claim_requests.is_empty()); assert!(monitor.onchain_tx_handler.claimable_outpoints.is_empty()); } diff --git a/lightning/src/util/macro_logger.rs b/lightning/src/util/macro_logger.rs index 5a6002d85..7594041de 100644 --- a/lightning/src/util/macro_logger.rs +++ b/lightning/src/util/macro_logger.rs @@ -43,7 +43,7 @@ macro_rules! log_bytes { pub(crate) struct DebugFundingChannelId<'a>(pub &'a Txid, pub u16); impl<'a> std::fmt::Display for DebugFundingChannelId<'a> { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - for i in OutPoint::new(self.0.clone(), self.1).to_channel_id().iter() { + for i in (OutPoint { txid: self.0.clone(), index: self.1 }).to_channel_id().iter() { write!(f, "{:02x}", i)?; } Ok(())