Struct bitcoin::psbt::PartiallySignedTransaction
source · pub struct PartiallySignedTransaction {
pub unsigned_tx: Transaction,
pub version: u32,
pub xpub: BTreeMap<ExtendedPubKey, KeySource>,
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<ExtendedPubKey, KeySource>
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§
source§impl PartiallySignedTransaction
impl PartiallySignedTransaction
sourcepub 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.
sourcepub fn from_unsigned_tx(tx: Transaction) -> Result<Self, Error>
pub fn from_unsigned_tx(tx: Transaction) -> Result<Self, Error>
sourcepub fn extract_tx(self) -> Transaction
pub fn extract_tx(self) -> Transaction
Extracts the Transaction
from a PSBT by filling in the available signature information.
sourcepub fn combine(&mut self, other: Self) -> Result<(), Error>
pub fn combine(&mut self, other: Self) -> Result<(), Error>
Combines this PartiallySignedTransaction
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)
sourcepub fn sign<C, K>(
&mut self,
k: &K,
secp: &Secp256k1<C>
) -> Result<SigningKeys, (SigningKeys, SigningErrors)>where
C: Signing,
K: GetKey,
pub fn sign<C, K>( &mut self, k: &K, secp: &Secp256k1<C> ) -> Result<SigningKeys, (SigningKeys, SigningErrors)>where C: Signing, K: GetKey,
Attempts to create all the required signatures for this PSBT using k
.
NOTE: Taproot inputs are, as yet, not supported by this function. We currently only attempt to sign ECDSA inputs.
If you just want to sign an input with one specific key consider using sighash_ecdsa
. This
function does not support scripts that contain OP_CODESEPARATOR
.
Returns
Either Ok(SigningKeys) or Err((SigningKeys, SigningErrors)), where
- SigningKeys: A map of input index -> pubkey associated with secret key used to sign.
- SigningKeys: A map of input index -> the error encountered while attempting to sign.
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.
sourcepub fn sighash_ecdsa<T: Borrow<Transaction>>(
&self,
input_index: usize,
cache: &mut SighashCache<T>
) -> Result<(Message, EcdsaSighashType), SignError>
pub fn sighash_ecdsa<T: Borrow<Transaction>>( &self, input_index: usize, cache: &mut SighashCache<T> ) -> Result<(Message, EcdsaSighashType), SignError>
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
.
sourcepub 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
.
sourcepub 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§
source§impl Clone for PartiallySignedTransaction
impl Clone for PartiallySignedTransaction
source§fn clone(&self) -> PartiallySignedTransaction
fn clone(&self) -> PartiallySignedTransaction
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PartiallySignedTransaction
impl Debug for PartiallySignedTransaction
source§impl<'de> Deserialize<'de> for PartiallySignedTransaction
impl<'de> Deserialize<'de> for PartiallySignedTransaction
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl Display for PartiallySignedTransaction
Available on crate feature base64
only.
impl Display for PartiallySignedTransaction
base64
only.source§impl FromStr for PartiallySignedTransaction
Available on crate feature base64
only.
impl FromStr for PartiallySignedTransaction
base64
only.source§impl Hash for PartiallySignedTransaction
impl Hash for PartiallySignedTransaction
source§impl PartialEq for PartiallySignedTransaction
impl PartialEq for PartiallySignedTransaction
source§fn eq(&self, other: &PartiallySignedTransaction) -> bool
fn eq(&self, other: &PartiallySignedTransaction) -> bool
self
and other
values to be equal, and is used
by ==
.