use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
use chain::transaction::{OutPoint, TransactionData};
-use chain::keysinterface::{SpendableOutputDescriptor, StaticCounterpartyPaymentOutputDescriptor, DynamicP2WSHOutputDescriptor, ChannelKeys, KeysInterface};
+use chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, ChannelKeys, KeysInterface};
use util::logger::Logger;
use util::ser::{Readable, ReadableArgs, MaybeReadable, Writer, Writeable, U48};
use util::byte_utils;
break;
} else if let Some(ref broadcasted_holder_revokable_script) = self.broadcasted_holder_revokable_script {
if broadcasted_holder_revokable_script.0 == outp.script_pubkey {
- spendable_output = Some(SpendableOutputDescriptor::DynamicOutputP2WSH(DynamicP2WSHOutputDescriptor {
+ spendable_output = Some(SpendableOutputDescriptor::DelayedPaymentOutput(DelayedPaymentOutputDescriptor {
outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
per_commitment_point: broadcasted_holder_revokable_script.1,
to_self_delay: self.on_holder_tx_csv,
break;
}
} else if self.counterparty_payment_script == outp.script_pubkey {
- spendable_output = Some(SpendableOutputDescriptor::StaticOutputCounterpartyPayment(StaticCounterpartyPaymentOutputDescriptor {
+ spendable_output = Some(SpendableOutputDescriptor::StaticPaymentOutput(StaticPaymentOutputDescriptor {
outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
output: outp.clone(),
channel_keys_id: self.channel_keys_id,
use ln::msgs::{DecodeError, MAX_VALUE_MSAT};
/// Information about a spendable output to a P2WSH script. See
-/// SpendableOutputDescriptor::DynamicOutputP2WSH for more details on how to spend this.
+/// SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this.
#[derive(Clone, Debug, PartialEq)]
-pub struct DynamicP2WSHOutputDescriptor {
+pub struct DelayedPaymentOutputDescriptor {
/// The outpoint which is spendable
pub outpoint: OutPoint,
/// Per commitment point to derive delayed_payment_key by key holder
/// The value of the channel which this output originated from, possibly indirectly.
pub channel_value_satoshis: u64,
}
-impl DynamicP2WSHOutputDescriptor {
+impl DelayedPaymentOutputDescriptor {
/// The maximum length a well-formed witness spending one of these should have.
// Calculated as 1 byte length + 73 byte signature, 1 byte empty vec push, 1 byte length plus
// redeemscript push length.
}
/// Information about a spendable output to our "payment key". See
-/// SpendableOutputDescriptor::StaticOutputCounterpartyPayment for more details on how to spend this.
+/// SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this.
#[derive(Clone, Debug, PartialEq)]
-pub struct StaticCounterpartyPaymentOutputDescriptor {
+pub struct StaticPaymentOutputDescriptor {
/// The outpoint which is spendable
pub outpoint: OutPoint,
/// The output which is referenced by the given outpoint
/// The value of the channel which this transactions spends.
pub channel_value_satoshis: u64,
}
-impl StaticCounterpartyPaymentOutputDescriptor {
+impl StaticPaymentOutputDescriptor {
/// The maximum length a well-formed witness spending one of these should have.
// Calculated as 1 byte legnth + 73 byte signature, 1 byte empty vec push, 1 byte length plus
// redeemscript push length.
/// regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey
/// (derived as above), and the to_self_delay contained here to
/// chan_utils::get_revokeable_redeemscript.
- DynamicOutputP2WSH(DynamicP2WSHOutputDescriptor),
+ DelayedPaymentOutput(DelayedPaymentOutputDescriptor),
/// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
/// corresponds to the public key in ChannelKeys::pubkeys().payment_point).
/// The witness in the spending input, is, thus, simply:
///
/// These are generally the result of our counterparty having broadcast the current state,
/// allowing us to claim the non-HTLC-encumbered outputs immediately.
- StaticOutputCounterpartyPayment(StaticCounterpartyPaymentOutputDescriptor),
+ StaticPaymentOutput(StaticPaymentOutputDescriptor),
}
impl Writeable for SpendableOutputDescriptor {
outpoint.write(writer)?;
output.write(writer)?;
},
- &SpendableOutputDescriptor::DynamicOutputP2WSH(ref descriptor) => {
+ &SpendableOutputDescriptor::DelayedPaymentOutput(ref descriptor) => {
1u8.write(writer)?;
descriptor.outpoint.write(writer)?;
descriptor.per_commitment_point.write(writer)?;
descriptor.channel_keys_id.write(writer)?;
descriptor.channel_value_satoshis.write(writer)?;
},
- &SpendableOutputDescriptor::StaticOutputCounterpartyPayment(ref descriptor) => {
+ &SpendableOutputDescriptor::StaticPaymentOutput(ref descriptor) => {
2u8.write(writer)?;
descriptor.outpoint.write(writer)?;
descriptor.output.write(writer)?;
outpoint: Readable::read(reader)?,
output: Readable::read(reader)?,
}),
- 1u8 => Ok(SpendableOutputDescriptor::DynamicOutputP2WSH(DynamicP2WSHOutputDescriptor {
+ 1u8 => Ok(SpendableOutputDescriptor::DelayedPaymentOutput(DelayedPaymentOutputDescriptor {
outpoint: Readable::read(reader)?,
per_commitment_point: Readable::read(reader)?,
to_self_delay: Readable::read(reader)?,
channel_keys_id: Readable::read(reader)?,
channel_value_satoshis: Readable::read(reader)?,
})),
- 2u8 => Ok(SpendableOutputDescriptor::StaticOutputCounterpartyPayment(StaticCounterpartyPaymentOutputDescriptor {
+ 2u8 => Ok(SpendableOutputDescriptor::StaticPaymentOutput(StaticPaymentOutputDescriptor {
outpoint: Readable::read(reader)?,
output: Readable::read(reader)?,
channel_keys_id: Readable::read(reader)?,
///
/// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
/// or is not spending the outpoint described by `descriptor.outpoint`.
- pub fn sign_counterparty_payment_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &StaticCounterpartyPaymentOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Vec<Vec<u8>>, ()> {
+ pub fn sign_counterparty_payment_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &StaticPaymentOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Vec<Vec<u8>>, ()> {
// TODO: We really should be taking the SigHashCache as a parameter here instead of
// spend_tx, but ideally the SigHashCache would expose the transaction's inputs read-only
// so that we can check them. This requires upstream rust-bitcoin changes (as well as
/// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
/// is not spending the outpoint described by `descriptor.outpoint`, or does not have a
/// sequence set to `descriptor.to_self_delay`.
- pub fn sign_dynamic_p2wsh_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &DynamicP2WSHOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Vec<Vec<u8>>, ()> {
+ pub fn sign_dynamic_p2wsh_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &DelayedPaymentOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Vec<Vec<u8>>, ()> {
// TODO: We really should be taking the SigHashCache as a parameter here instead of
// spend_tx, but ideally the SigHashCache would expose the transaction's inputs read-only
// so that we can check them. This requires upstream rust-bitcoin changes (as well as
let mut output_set = HashSet::with_capacity(descriptors.len());
for outp in descriptors {
match outp {
- SpendableOutputDescriptor::StaticOutputCounterpartyPayment(descriptor) => {
+ SpendableOutputDescriptor::StaticPaymentOutput(descriptor) => {
input.push(TxIn {
previous_output: descriptor.outpoint.into_bitcoin_outpoint(),
script_sig: Script::new(),
sequence: 0,
witness: Vec::new(),
});
- witness_weight += StaticCounterpartyPaymentOutputDescriptor::MAX_WITNESS_LENGTH;
+ witness_weight += StaticPaymentOutputDescriptor::MAX_WITNESS_LENGTH;
input_value += descriptor.output.value;
if !output_set.insert(descriptor.outpoint) { return Err(()); }
},
- SpendableOutputDescriptor::DynamicOutputP2WSH(descriptor) => {
+ SpendableOutputDescriptor::DelayedPaymentOutput(descriptor) => {
input.push(TxIn {
previous_output: descriptor.outpoint.into_bitcoin_outpoint(),
script_sig: Script::new(),
sequence: descriptor.to_self_delay as u32,
witness: Vec::new(),
});
- witness_weight += DynamicP2WSHOutputDescriptor::MAX_WITNESS_LENGTH;
+ witness_weight += DelayedPaymentOutputDescriptor::MAX_WITNESS_LENGTH;
input_value += descriptor.output.value;
if !output_set.insert(descriptor.outpoint) { return Err(()); }
},
let mut input_idx = 0;
for outp in descriptors {
match outp {
- SpendableOutputDescriptor::StaticOutputCounterpartyPayment(descriptor) => {
+ SpendableOutputDescriptor::StaticPaymentOutput(descriptor) => {
if keys_cache.is_none() || keys_cache.as_ref().unwrap().1 != descriptor.channel_keys_id {
keys_cache = Some((
self.derive_channel_keys(descriptor.channel_value_satoshis, &descriptor.channel_keys_id),
}
spend_tx.input[input_idx].witness = keys_cache.as_ref().unwrap().0.sign_counterparty_payment_input(&spend_tx, input_idx, &descriptor, &secp_ctx).unwrap();
},
- SpendableOutputDescriptor::DynamicOutputP2WSH(descriptor) => {
+ SpendableOutputDescriptor::DelayedPaymentOutput(descriptor) => {
if keys_cache.is_none() || keys_cache.as_ref().unwrap().1 != descriptor.channel_keys_id {
keys_cache = Some((
self.derive_channel_keys(descriptor.channel_value_satoshis, &descriptor.channel_keys_id),