Enum SpendableOutputDescriptor
pub enum SpendableOutputDescriptor {
StaticOutput {
outpoint: OutPoint,
output: TxOut,
channel_keys_id: Option<[u8; 32]>,
},
DelayedPaymentOutput(DelayedPaymentOutputDescriptor),
StaticPaymentOutput(StaticPaymentOutputDescriptor),
}
Expand description
Describes the necessary information to spend a spendable output.
When on-chain outputs are created by LDK (which our counterparty is not able to claim at any
point in the future) a SpendableOutputs
event is generated which you must track and be able
to spend on-chain. The information needed to do this is provided in this enum, including the
outpoint describing which txid
and output index
is available, the full output which exists
at that txid
/index
, and any keys or other information required to sign.
Variants§
StaticOutput
An output to a script which was provided via SignerProvider
directly, either from
get_destination_script
or get_shutdown_scriptpubkey
, thus you should already
know how to spend it. No secret keys are provided as LDK was never given any key.
These may include outputs from a transaction punishing our counterparty or claiming an HTLC
on-chain using the payment preimage or after it has timed out.
Fields
channel_keys_id: Option<[u8; 32]>
The channel_keys_id
for the channel which this output came from.
For channels which were generated on LDK 0.0.119 or later, this is the value which was
passed to the SignerProvider::get_destination_script
call which provided this
output script.
For channels which were generated prior to LDK 0.0.119, no such argument existed, however this field may still be filled in if such data is available.
DelayedPaymentOutput(DelayedPaymentOutputDescriptor)
An output to a P2WSH script which can be spent with a single signature after an OP_CSV
delay.
The witness in the spending input should be:
<BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
Note that the nSequence
field in the spending input must be set to
DelayedPaymentOutputDescriptor::to_self_delay
(which means the transaction is not
broadcastable until at least DelayedPaymentOutputDescriptor::to_self_delay
blocks after
the outpoint confirms, see BIP
68). Also note that LDK
won’t generate a SpendableOutputDescriptor
until the corresponding block height
is reached.
These are generally the result of a “revocable” output to us, spendable only by us unless it is an output from an old state which we broadcast (which should never happen).
To derive the delayed payment key which is used to sign this input, you must pass the
holder InMemorySigner::delayed_payment_base_key
(i.e., the private key which corresponds to the
ChannelPublicKeys::delayed_payment_basepoint
in ChannelSigner::pubkeys
) and the provided
DelayedPaymentOutputDescriptor::per_commitment_point
to chan_utils::derive_private_key
. The DelayedPaymentKey can be
generated without the secret key using DelayedPaymentKey::from_basepoint
and only the
ChannelPublicKeys::delayed_payment_basepoint
which appears in ChannelSigner::pubkeys
.
To derive the DelayedPaymentOutputDescriptor::revocation_pubkey
provided here (which is
used in the witness script generation), you must pass the counterparty
ChannelPublicKeys::revocation_basepoint
(which appears in the call to
ChannelSigner::provide_channel_parameters
) and the provided
DelayedPaymentOutputDescriptor::per_commitment_point
to
RevocationKey
.
The witness script which is hashed and included in the output script_pubkey
may be
regenerated by passing the DelayedPaymentOutputDescriptor::revocation_pubkey
(derived
as explained above), our delayed payment pubkey (derived as explained above), and the
DelayedPaymentOutputDescriptor::to_self_delay
contained here to
chan_utils::get_revokeable_redeemscript
.
StaticPaymentOutput(StaticPaymentOutputDescriptor)
An output spendable exclusively by our payment key (i.e., the private key that corresponds
to the payment_point
in ChannelSigner::pubkeys
). The output type depends on the
channel type negotiated.
On an anchor outputs channel, the witness in the spending input is:
<BIP 143 signature> <witness script>
Otherwise, it is:
<BIP 143 signature> <payment key>
These are generally the result of our counterparty having broadcast the current state, allowing us to claim the non-HTLC-encumbered outputs immediately, or after one confirmation in the case of anchor outputs channels.
Implementations§
§impl SpendableOutputDescriptor
impl SpendableOutputDescriptor
pub fn to_psbt_input<T>(&self, secp_ctx: &Secp256k1<T>) -> Inputwhere
T: Signing,
pub fn to_psbt_input<T>(&self, secp_ctx: &Secp256k1<T>) -> Inputwhere
T: Signing,
Turns this into a bitcoin::psbt::Input
which can be used to create a
Psbt
which spends the given descriptor.
Note that this does not include any signatures, just the information required to construct the transaction and sign it.
This is not exported to bindings users as there is no standard serialization for an input.
See Self::create_spendable_outputs_psbt
instead.
The proprietary field is used to store add tweak for the signing key of this transaction.
See the DelayedPaymentBasepoint::derive_add_tweak
docs for more info on add tweak and how to use it.
To get the proprietary field use:
use bitcoin::psbt::{Psbt};
use bitcoin::hex::FromHex;
let key = bitcoin::psbt::raw::ProprietaryKey {
prefix: "LDK_spendable_output".as_bytes().to_vec(),
subtype: 0,
key: "add_tweak".as_bytes().to_vec(),
};
let value = psbt
.inputs
.first()
.expect("Unable to get add tweak as there are no inputs")
.proprietary
.get(&key)
.map(|x| x.to_owned());
pub fn create_spendable_outputs_psbt<T>(
secp_ctx: &Secp256k1<T>,
descriptors: &[&SpendableOutputDescriptor],
outputs: Vec<TxOut>,
change_destination_script: ScriptBuf,
feerate_sat_per_1000_weight: u32,
locktime: Option<LockTime>,
) -> Result<(Psbt, u64), ()>where
T: Signing,
pub fn create_spendable_outputs_psbt<T>(
secp_ctx: &Secp256k1<T>,
descriptors: &[&SpendableOutputDescriptor],
outputs: Vec<TxOut>,
change_destination_script: ScriptBuf,
feerate_sat_per_1000_weight: u32,
locktime: Option<LockTime>,
) -> Result<(Psbt, u64), ()>where
T: Signing,
Creates an unsigned Psbt
which spends the given descriptors to
the given outputs, plus an output to the given change destination (if sufficient
change value remains). The PSBT will have a feerate, at least, of the given value.
The locktime
argument is used to set the transaction’s locktime. If None
, the
transaction will have a locktime of 0. It it recommended to set this to the current block
height to avoid fee sniping, unless you have some specific reason to use a different
locktime.
Returns the PSBT and expected max transaction weight.
Returns Err(())
if the output value is greater than the input value minus required fee,
if a descriptor was duplicated, or if an output descriptor script_pubkey
does not match the one we can spend.
We do not enforce that outputs meet the dust limit or that any output scripts are standard.
Trait Implementations§
§impl Clone for SpendableOutputDescriptor
impl Clone for SpendableOutputDescriptor
§fn clone(&self) -> SpendableOutputDescriptor
fn clone(&self) -> SpendableOutputDescriptor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for SpendableOutputDescriptor
impl Debug for SpendableOutputDescriptor
§impl Hash for SpendableOutputDescriptor
impl Hash for SpendableOutputDescriptor
§impl PartialEq for SpendableOutputDescriptor
impl PartialEq for SpendableOutputDescriptor
§impl Readable for SpendableOutputDescriptor
impl Readable for SpendableOutputDescriptor
§fn read<R>(reader: &mut R) -> Result<SpendableOutputDescriptor, DecodeError>where
R: Read,
fn read<R>(reader: &mut R) -> Result<SpendableOutputDescriptor, DecodeError>where
R: Read,
Self
in from the given Read
.§impl Writeable for SpendableOutputDescriptor
impl Writeable for SpendableOutputDescriptor
impl Eq for SpendableOutputDescriptor
impl StructuralPartialEq for SpendableOutputDescriptor
Auto Trait Implementations§
impl Freeze for SpendableOutputDescriptor
impl RefUnwindSafe for SpendableOutputDescriptor
impl Send for SpendableOutputDescriptor
impl Sync for SpendableOutputDescriptor
impl Unpin for SpendableOutputDescriptor
impl UnwindSafe for SpendableOutputDescriptor
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request