Struct bdk_chain::bitcoin::Psbt

pub struct Psbt {
    pub unsigned_tx: Transaction,
    pub version: u32,
    pub xpub: BTreeMap<Xpub, (Fingerprint, DerivationPath)>,
    pub proprietary: BTreeMap<ProprietaryKey, Vec<u8>>,
    pub unknown: BTreeMap<Key, Vec<u8>>,
    pub inputs: Vec<Input>,
    pub outputs: Vec<Output>,
}
Expand description

A Partially Signed Transaction.

Fields§

§unsigned_tx: Transaction

The unsigned transaction, scriptSigs and witnesses for each input must be empty.

§version: u32

The version number of this PSBT. If omitted, the version number is 0.

§xpub: BTreeMap<Xpub, (Fingerprint, DerivationPath)>

A global map from extended public keys to the used key fingerprint and derivation path as defined by BIP 32.

§proprietary: BTreeMap<ProprietaryKey, Vec<u8>>

Global proprietary key-value pairs.

§unknown: BTreeMap<Key, Vec<u8>>

Unknown global key-value pairs.

§inputs: Vec<Input>

The corresponding key-value map for each input in the unsigned transaction.

§outputs: Vec<Output>

The corresponding key-value map for each output in the unsigned transaction.

Implementations§

§

impl Psbt

pub fn serialize_hex(&self) -> String

Serialize a value as bytes in hex.

pub fn serialize(&self) -> Vec<u8>

Serialize as raw binary data

pub fn deserialize(bytes: &[u8]) -> Result<Psbt, Error>

Deserialize a value from raw binary data.

§

impl Psbt

pub fn iter_funding_utxos(&self) -> impl Iterator<Item = Result<&TxOut, Error>>

Returns an iterator for the funding UTXOs of the psbt

For each PSBT input that contains UTXO information Ok is returned containing that information. The order of returned items is same as the order of inputs.

§Errors

The function returns error when UTXO information is not present or is invalid.

§Panics

The function panics if the length of transaction inputs is not equal to the length of PSBT inputs.

pub fn from_unsigned_tx(tx: Transaction) -> Result<Psbt, Error>

Creates a PSBT from an unsigned transaction.

§Errors

If transactions is not unsigned.

pub const DEFAULT_MAX_FEE_RATE: FeeRate = _

The default max_fee_rate value used for extracting transactions with extract_tx

As of 2023, even the biggest overpayers during the highest fee markets only paid around 1000 sats/vByte. 25k sats/vByte is obviously a mistake at this point.

pub fn extract_tx(self) -> Result<Transaction, ExtractTxError>

pub fn extract_tx_fee_rate_limit(self) -> Result<Transaction, ExtractTxError>

Extracts the Transaction from a Psbt by filling in the available signature information.

§Errors

ExtractTxError variants will contain either the Psbt itself or the Transaction that was extracted. These can be extracted from the Errors in order to recover. See the error documentation for info on the variants. In general, it covers large fees.

pub fn extract_tx_with_fee_rate_limit( self, max_fee_rate: FeeRate ) -> Result<Transaction, ExtractTxError>

Extracts the Transaction from a Psbt by filling in the available signature information.

§Errors

See extract_tx.

pub fn extract_tx_unchecked_fee_rate(self) -> Transaction

Perform extract_tx_fee_rate_limit without the fee rate check.

This can result in a transaction with absurdly high fees. Use with caution.

pub fn combine(&mut self, other: Psbt) -> Result<(), Error>

Combines this Psbt with other PSBT as described by BIP 174.

In accordance with BIP 174 this function is commutative i.e., A.combine(B) == B.combine(A)

pub fn sign<C, K>( &mut self, k: &K, secp: &Secp256k1<C> ) -> Result<BTreeMap<usize, SigningKeys>, (BTreeMap<usize, SigningKeys>, BTreeMap<usize, SignError>)>
where C: Signing + Verification, K: GetKey,

Attempts to create all the required signatures for this PSBT using k.

If you just want to sign an input with one specific key consider using sighash_ecdsa or sighash_taproot. This function does not support scripts that contain OP_CODESEPARATOR.

§Returns

A map of input index -> keys used to sign, for Taproot specifics please see SigningKeys.

If an error is returned some signatures may already have been added to the PSBT. Since partial_sigs is a BTreeMap it is safe to retry, previous sigs will be overwritten.

pub fn sighash_ecdsa<T>( &self, input_index: usize, cache: &mut SighashCache<T> ) -> Result<(Message, EcdsaSighashType), SignError>
where T: Borrow<Transaction>,

Returns the sighash message to sign an ECDSA input along with the sighash type.

Uses the EcdsaSighashType from this input if one is specified. If no sighash type is specified uses EcdsaSighashType::All. This function does not support scripts that contain OP_CODESEPARATOR.

pub fn spend_utxo(&self, input_index: usize) -> Result<&TxOut, SignError>

Returns the spending utxo for this PSBT’s input at input_index.

pub fn fee(&self) -> Result<Amount, Error>

Calculates transaction fee.

‘Fee’ being the amount that will be paid for mining a transaction with the current inputs and outputs i.e., the difference in value of the total inputs and the total outputs.

§Errors

Trait Implementations§

§

impl Clone for Psbt

§

fn clone(&self) -> Psbt

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Psbt

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for Psbt

§

fn deserialize<__D>( __deserializer: __D ) -> Result<Psbt, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for Psbt

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl FromStr for Psbt

§

type Err = PsbtParseError

The associated error which can be returned from parsing.
§

fn from_str(s: &str) -> Result<Psbt, <Psbt as FromStr>::Err>

Parses a string s to return a value of this type. Read more
§

impl Hash for Psbt

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for Psbt

§

fn eq(&self, other: &Psbt) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PsbtExt for Psbt

§

fn finalize_mut<C>(&mut self, secp: &Secp256k1<C>) -> Result<(), Vec<Error>>
where C: Verification,

Finalize the psbt. This function takes in a mutable reference to psbt and populates the final_witness and final_scriptsig for all miniscript inputs. Read more
§

fn finalize<C>(self, secp: &Secp256k1<C>) -> Result<Psbt, (Psbt, Vec<Error>)>
where C: Verification,

Same as [PsbtExt::finalize_mut], but does not mutate the input psbt and returns a new psbt Read more
§

fn finalize_mall_mut<C>( &mut self, secp: &Secp256k1<C> ) -> Result<(), Vec<Error>>
where C: Verification,

Same as [PsbtExt::finalize_mut], but allows for malleable satisfactions
§

fn finalize_mall<C>( self, secp: &Secp256k1<C> ) -> Result<Psbt, (Psbt, Vec<Error>)>
where C: Verification,

Same as [PsbtExt::finalize], but allows for malleable satisfactions
§

fn finalize_inp_mut<C>( &mut self, secp: &Secp256k1<C>, index: usize ) -> Result<(), Error>
where C: Verification,

Same as [PsbtExt::finalize_mut], but only tries to finalize a single input leaving other inputs as is. Use this when not all of inputs that you are trying to satisfy are miniscripts Read more
§

fn finalize_inp<C>( self, secp: &Secp256k1<C>, index: usize ) -> Result<Psbt, (Psbt, Error)>
where C: Verification,

Same as [PsbtExt::finalize_inp_mut], but does not mutate the psbt and returns a new one Read more
§

fn finalize_inp_mall_mut<C>( &mut self, secp: &Secp256k1<C>, index: usize ) -> Result<(), Error>
where C: Verification,

Same as [PsbtExt::finalize_inp_mut], but allows for malleable satisfactions
§

fn finalize_inp_mall<C>( self, secp: &Secp256k1<C>, index: usize ) -> Result<Psbt, (Psbt, Error)>
where C: Verification,

Same as [PsbtExt::finalize_inp], but allows for malleable satisfactions
§

fn extract<C>(&self, secp: &Secp256k1<C>) -> Result<Transaction, Error>
where C: Verification,

Psbt extractor as defined in BIP174 that takes in a psbt reference and outputs a extracted bitcoin::Transaction Also does the interpreter sanity check Will error if the final ScriptSig or final Witness are missing or the interpreter check fails.
§

fn update_input_with_descriptor( &mut self, input_index: usize, desc: &Descriptor<DefiniteDescriptorKey> ) -> Result<(), UtxoUpdateError>

Update PSBT input with a descriptor and check consistency of *_utxo fields. Read more
§

fn update_output_with_descriptor( &mut self, output_index: usize, desc: &Descriptor<DefiniteDescriptorKey> ) -> Result<(), OutputUpdateError>

Update PSBT output with a descriptor and check consistency of the output’s script_pubkey Read more
§

fn sighash_msg<T>( &self, idx: usize, cache: &mut SighashCache<T>, tapleaf_hash: Option<TapLeafHash> ) -> Result<PsbtSighashMsg, SighashError>
where T: Borrow<Transaction>,

Get the sighash message(data to sign) at input index idx. Read more
§

impl Serialize for Psbt

§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Eq for Psbt

§

impl StructuralPartialEq for Psbt

Auto Trait Implementations§

§

impl Freeze for Psbt

§

impl RefUnwindSafe for Psbt

§

impl Send for Psbt

§

impl Sync for Psbt

§

impl Unpin for Psbt

§

impl UnwindSafe for Psbt

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,