Struct 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
impl Psbt
pub fn serialize_hex(&self) -> String
pub fn serialize_hex(&self) -> String
Serialize a value as bytes in hex.
pub fn serialize_to_writer(&self, w: &mut impl Write) -> Result<usize, Error>
pub fn serialize_to_writer(&self, w: &mut impl Write) -> Result<usize, Error>
Serialize the PSBT into a writer.
pub fn deserialize(bytes: &[u8]) -> Result<Psbt, Error>
pub fn deserialize(bytes: &[u8]) -> Result<Psbt, Error>
Deserialize a value from raw binary data.
§impl Psbt
impl Psbt
pub const DEFAULT_MAX_FEE_RATE: FeeRate = _
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 iter_funding_utxos(&self) -> impl Iterator<Item = Result<&TxOut, Error>>
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>
pub fn from_unsigned_tx(tx: Transaction) -> Result<Psbt, Error>
pub fn extract_tx(self) -> Result<Transaction, ExtractTxError>
pub fn extract_tx(self) -> Result<Transaction, ExtractTxError>
An alias for extract_tx_fee_rate_limit
.
pub fn extract_tx_fee_rate_limit(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>
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
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>
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>)>
pub fn sign<C, K>( &mut self, k: &K, secp: &Secp256k1<C>, ) -> Result<BTreeMap<usize, SigningKeys>, (BTreeMap<usize, SigningKeys>, BTreeMap<usize, SignError>)>
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>,
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>
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>
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
Error::MissingUtxo
when UTXO information for any input is not present or is invalid.Error::NegativeFee
if calculated value is negative.Error::FeeOverflow
if an integer overflow occurs.
Trait Implementations§
§impl<'de> Deserialize<'de> for Psbt
impl<'de> Deserialize<'de> for Psbt
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Psbt, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Psbt, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl PsbtExt for Psbt
impl PsbtExt for Psbt
§fn finalize_mut<C>(&mut self, secp: &Secp256k1<C>) -> Result<(), Vec<Error>>where
C: Verification,
fn finalize_mut<C>(&mut self, secp: &Secp256k1<C>) -> Result<(), Vec<Error>>where
C: Verification,
§fn finalize<C>(self, secp: &Secp256k1<C>) -> Result<Psbt, (Psbt, Vec<Error>)>where
C: Verification,
fn finalize<C>(self, secp: &Secp256k1<C>) -> Result<Psbt, (Psbt, Vec<Error>)>where
C: Verification,
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,
fn finalize_mall_mut<C>(
&mut self,
secp: &Secp256k1<C>,
) -> Result<(), Vec<Error>>where
C: Verification,
§fn finalize_mall<C>(
self,
secp: &Secp256k1<C>,
) -> Result<Psbt, (Psbt, Vec<Error>)>where
C: Verification,
fn finalize_mall<C>(
self,
secp: &Secp256k1<C>,
) -> Result<Psbt, (Psbt, Vec<Error>)>where
C: Verification,
§fn finalize_inp_mut<C>(
&mut self,
secp: &Secp256k1<C>,
index: usize,
) -> Result<(), Error>where
C: Verification,
fn finalize_inp_mut<C>(
&mut self,
secp: &Secp256k1<C>,
index: usize,
) -> Result<(), Error>where
C: Verification,
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,
fn finalize_inp<C>(
self,
secp: &Secp256k1<C>,
index: usize,
) -> Result<Psbt, (Psbt, Error)>where
C: Verification,
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,
fn finalize_inp_mall_mut<C>(
&mut self,
secp: &Secp256k1<C>,
index: usize,
) -> Result<(), Error>where
C: Verification,
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,
fn finalize_inp_mall<C>(
self,
secp: &Secp256k1<C>,
index: usize,
) -> Result<Psbt, (Psbt, Error)>where
C: Verification,
PsbtExt::finalize_inp
], but allows for malleable satisfactions§fn extract<C>(&self, secp: &Secp256k1<C>) -> Result<Transaction, Error>where
C: Verification,
fn extract<C>(&self, secp: &Secp256k1<C>) -> Result<Transaction, Error>where
C: Verification,
§fn update_input_with_descriptor(
&mut self,
input_index: usize,
desc: &Descriptor<DefiniteDescriptorKey>,
) -> Result<(), UtxoUpdateError>
fn update_input_with_descriptor( &mut self, input_index: usize, desc: &Descriptor<DefiniteDescriptorKey>, ) -> Result<(), UtxoUpdateError>
*_utxo
fields. Read more§fn update_output_with_descriptor(
&mut self,
output_index: usize,
desc: &Descriptor<DefiniteDescriptorKey>,
) -> Result<(), OutputUpdateError>
fn update_output_with_descriptor( &mut self, output_index: usize, desc: &Descriptor<DefiniteDescriptorKey>, ) -> Result<(), OutputUpdateError>
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>,
fn sighash_msg<T>(
&self,
idx: usize,
cache: &mut SighashCache<T>,
tapleaf_hash: Option<TapLeafHash>,
) -> Result<PsbtSighashMsg, SighashError>where
T: Borrow<Transaction>,
idx
. Read more