[][src]Enum lnpbp::bp::scripts::Strategy

#[non_exhaustive]pub enum Strategy {
    Exposed,
    LegacyHashed,
    WitnessScriptHash,
    WitnessV0,
    WitnessV1Taproot,
}

Defines strategy for converting some source Bitcoin script (i.e. LockScript) into both scriptPubkey and sigScript/witness fields

Variants (Non-exhaustive)

Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Exposed

The script or public key gets right into scriptPubkey, i.e. as P2PK (for a public key) or as custom script (mostly used for OP_RETURN)

LegacyHashed

We hash public key or script and use non-SegWit scriptPubkey encoding, i.e. P2PKH or P2SH with corresponding non-segwit transaction input sigScript containing copy of LockScript in redeemScript field

WitnessScriptHash

Compatibility variant for SegWit outputs when the SegWit version and program are encoded as RedeemScript in sigScript transaction input field, while the original public key or WitnessScript are stored in witness. scriptPubkey contains a normal P2SH composed agains the redeemScript from sigScript (P2SH-P2WPKH and P2SH-P2WSH variants). This type works with any witness version, including taproot.

WitnessV0

We produce either P2WPKH or P2WSH output and use witness field in transaction input to store the original LockScript or the public key

WitnessV1Taproot

Will be used for Taproot

Implementations

impl Strategy[src]

pub fn deduce(
    pubkey_script: &PubkeyScript,
    has_witness: Option<bool>
) -> Result<Strategy, StrategyError>
[src]

Deduction of [ConversionStrategy] from a scriptPubkey data and, optionally, information about the presence of the witness for P2SH scriptPubkey's.

Arguments

  • pubkey_script - script from transaction output scriptPubkey
  • has_witness - an optional bool with the following meaning:
    • None: witness presence must be determined from the pubkey_script value; don't use it for P2SH scriptPubkeys, otherwise the method will return [ConversionStrategyError::IncompleteInformation] error.
    • Some(true): presence of a witness structure will be required in transaction input to spend the given pubkey_script, i.e. it was composed with P2SH-P2W*H scheme
    • Some(false): if scriptPubkey is P2SH, it is a "normal" P2SH and was not created with P2SH-P2W*H scheme. The spending transaction input would not have witness structure.

Errors

The function may [ConversionStrategyError] in the following cases

  • IncompleteInformation: the provided pubkey script (pubkey_script argument) is P2SH script, and has_witness argument was set to None (see explanation about the argument usage above).
  • UnsupportedWitnessVersion(WitnessVersion): the provided pubkey script has a witness version above 1.

Trait Implementations

impl Clone for Strategy[src]

impl Copy for Strategy[src]

impl Debug for Strategy[src]

impl Display for Strategy[src]

impl Eq for Strategy[src]

impl Hash for Strategy[src]

impl PartialEq<Strategy> for Strategy[src]

impl StructuralEq for Strategy[src]

impl StructuralPartialEq for Strategy[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,