11use crate :: error:: {
2- AddressParseError , FeeRateError , FromScriptError , PsbtError , PsbtParseError , TransactionError , ExtractTxError
2+ AddressParseError , ExtractTxError , FeeRateError , FromScriptError , PsbtError , PsbtParseError ,
3+ TransactionError ,
34} ;
45use crate :: error:: { ParseAmountError , PsbtFinalizeError } ;
56use crate :: { impl_from_core_type, impl_into_core_type} ;
@@ -321,28 +322,48 @@ impl From<&Transaction> for BdkTransaction {
321322 }
322323}
323324
325+ /// A Partially Signed Transaction.
324326#[ derive( uniffi:: Object ) ]
325327pub struct Psbt ( pub ( crate ) Mutex < BdkPsbt > ) ;
326328
327329#[ uniffi:: export]
328330impl Psbt {
331+ /// Creates a new `Psbt` instance from a base64-encoded string.
329332 #[ uniffi:: constructor]
330333 pub ( crate ) fn new ( psbt_base64 : String ) -> Result < Self , PsbtParseError > {
331334 let psbt: BdkPsbt = BdkPsbt :: from_str ( & psbt_base64) ?;
332335 Ok ( Psbt ( Mutex :: new ( psbt) ) )
333336 }
334337
338+ /// Serialize the PSBT into a writer.
335339 pub ( crate ) fn serialize ( & self ) -> String {
336340 let psbt = self . 0 . lock ( ) . unwrap ( ) . clone ( ) ;
337341 psbt. to_string ( )
338342 }
339343
344+ /// Extracts the `Transaction` from a `Psbt` by filling in the available signature information.
345+ ///
346+ /// #### Errors
347+ ///
348+ /// `ExtractTxError` variants will contain either the `Psbt` itself or the `Transaction`
349+ /// that was extracted. These can be extracted from the Errors in order to recover.
350+ /// See the error documentation for info on the variants. In general, it covers large fees.
340351 pub ( crate ) fn extract_tx ( & self ) -> Result < Arc < Transaction > , ExtractTxError > {
341352 let tx: BdkTransaction = self . 0 . lock ( ) . unwrap ( ) . clone ( ) . extract_tx ( ) ?;
342353 let transaction: Transaction = tx. into ( ) ;
343354 Ok ( Arc :: new ( transaction) )
344355 }
345356
357+ /// Calculates transaction fee.
358+ ///
359+ /// 'Fee' being the amount that will be paid for mining a transaction with the current inputs
360+ /// and outputs i.e., the difference in value of the total inputs and the total outputs.
361+ ///
362+ /// #### Errors
363+ ///
364+ /// - `MissingUtxo` when UTXO information for any input is not present or is invalid.
365+ /// - `NegativeFee` if calculated value is negative.
366+ /// - `FeeOverflow` if an integer overflow occurs.
346367 pub ( crate ) fn fee ( & self ) -> Result < u64 , PsbtError > {
347368 self . 0
348369 . lock ( )
@@ -352,13 +373,19 @@ impl Psbt {
352373 . map_err ( PsbtError :: from)
353374 }
354375
376+ /// Combines this `Psbt` with `other` PSBT as described by BIP 174.
377+ ///
378+ /// In accordance with BIP 174 this function is commutative i.e., `A.combine(B) == B.combine(A)`
355379 pub ( crate ) fn combine ( & self , other : Arc < Psbt > ) -> Result < Arc < Psbt > , PsbtError > {
356380 let mut original_psbt = self . 0 . lock ( ) . unwrap ( ) . clone ( ) ;
357381 let other_psbt = other. 0 . lock ( ) . unwrap ( ) . clone ( ) ;
358382 original_psbt. combine ( other_psbt) ?;
359383 Ok ( Arc :: new ( Psbt ( Mutex :: new ( original_psbt) ) ) )
360384 }
361385
386+ /// Finalizes the current PSBT (Partially Signed Bitcoin Transaction) and produces a result indicating
387+ ///
388+ /// whether the finalization was successful or not.
362389 pub ( crate ) fn finalize ( & self ) -> FinalizedPsbtResult {
363390 let curve = Secp256k1 :: verification_only ( ) ;
364391 let finalized = self . 0 . lock ( ) . unwrap ( ) . clone ( ) . finalize ( & curve) ;
@@ -379,6 +406,7 @@ impl Psbt {
379406 }
380407 }
381408
409+ /// Serializes the PSBT (Partially Signed Bitcoin Transaction) into a JSON string representation.
382410 pub ( crate ) fn json_serialize ( & self ) -> String {
383411 let psbt = self . 0 . lock ( ) . unwrap ( ) ;
384412 serde_json:: to_string ( psbt. deref ( ) ) . unwrap ( )
0 commit comments