Skip to content

Commit 1faea44

Browse files
committed
psbt: Improve documentation
Improve documentation in `psbt/mod.rs` by doing: - Use full sentences (full stops and capitalisation) - Use 100 line column width - Use back ticks and links as appropriate - Use `Errors` section - Use third person tense to describe functions
1 parent 6817e1f commit 1faea44

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/util/psbt/mod.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ pub type Psbt = PartiallySignedTransaction;
5353
#[derive(Debug, Clone, PartialEq, Eq)]
5454
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5555
pub struct PartiallySignedTransaction {
56-
/// The unsigned transaction, scriptSigs and witnesses for each input must be
57-
/// empty.
56+
/// The unsigned transaction, scriptSigs and witnesses for each input must be empty.
5857
pub unsigned_tx: Transaction,
5958
/// The version number of this PSBT. If omitted, the version number is 0.
6059
pub version: u32,
6160
/// A global map from extended public keys to the used key fingerprint and
62-
/// derivation path as defined by BIP 32
61+
/// derivation path as defined by BIP 32.
6362
pub xpub: BTreeMap<ExtendedPubKey, KeySource>,
6463
/// Global proprietary key-value pairs.
6564
#[cfg_attr(feature = "serde", serde(with = "crate::serde_utils::btreemap_as_seq_byte_values"))]
@@ -68,11 +67,9 @@ pub struct PartiallySignedTransaction {
6867
#[cfg_attr(feature = "serde", serde(with = "crate::serde_utils::btreemap_as_seq_byte_values"))]
6968
pub unknown: BTreeMap<raw::Key, Vec<u8>>,
7069

71-
/// The corresponding key-value map for each input in the unsigned
72-
/// transaction.
70+
/// The corresponding key-value map for each input in the unsigned transaction.
7371
pub inputs: Vec<Input>,
74-
/// The corresponding key-value map for each output in the unsigned
75-
/// transaction.
72+
/// The corresponding key-value map for each output in the unsigned transaction.
7673
pub outputs: Vec<Output>,
7774
}
7875

@@ -103,8 +100,7 @@ impl PartiallySignedTransaction {
103100
})
104101
}
105102

106-
/// Checks that unsigned transaction does not have scriptSig's or witness
107-
/// data
103+
/// Checks that unsigned transaction does not have scriptSig's or witness data.
108104
fn unsigned_tx_checks(&self) -> Result<(), Error> {
109105
for txin in &self.unsigned_tx.input {
110106
if !txin.script_sig.is_empty() {
@@ -119,8 +115,11 @@ impl PartiallySignedTransaction {
119115
Ok(())
120116
}
121117

122-
/// Create a PartiallySignedTransaction from an unsigned transaction, error
123-
/// if not unsigned
118+
/// Creates a PSBT from an unsigned transaction.
119+
///
120+
/// # Errors
121+
///
122+
/// If transactions is not unsigned.
124123
pub fn from_unsigned_tx(tx: Transaction) -> Result<Self, Error> {
125124
let psbt = PartiallySignedTransaction {
126125
inputs: vec![Default::default(); tx.input.len()],
@@ -136,8 +135,7 @@ impl PartiallySignedTransaction {
136135
Ok(psbt)
137136
}
138137

139-
/// Extract the Transaction from a PartiallySignedTransaction by filling in
140-
/// the available signature information in place.
138+
/// Extracts the `Transaction` from a PSBT by filling in the available signature information.
141139
pub fn extract_tx(self) -> Transaction {
142140
let mut tx: Transaction = self.unsigned_tx;
143141

@@ -222,13 +220,13 @@ mod display_from_str {
222220
use crate::consensus::encode::{Error, self};
223221
use base64::display::Base64Display;
224222

225-
/// Error happening during PSBT decoding from Base64 string
223+
/// Error encountered during PSBT decoding from Base64 string.
226224
#[derive(Debug)]
227225
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
228226
pub enum PsbtParseError {
229-
/// Error in internal PSBT data structure
227+
/// Error in internal PSBT data structure.
230228
PsbtEncoding(Error),
231-
/// Error in PSBT Base64 encoding
229+
/// Error in PSBT Base64 encoding.
232230
Base64Encoding(::base64::DecodeError)
233231
}
234232

src/util/sighash.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct SighashCache<T: Deref<Target=Transaction>> {
4747
/// Common cache for taproot and segwit inputs, `None` for legacy inputs.
4848
common_cache: Option<CommonCache>,
4949

50-
/// Cache for segwit v0 inputs.
50+
/// Cache for segwit v0 inputs (the result of another round of sha256 on `common_cache`).
5151
segwit_cache: Option<SegwitCache>,
5252

5353
/// Cache for taproot v1 inputs.
@@ -104,8 +104,8 @@ pub struct ScriptPath<'s> {
104104
leaf_version: LeafVersion,
105105
}
106106

107-
/// Hashtype of an input's signature, encoded in the last byte of the signature. Fixed values so
108-
/// they can be cast as integer types for encoding.
107+
/// Hashtype of an input's signature, encoded in the last byte of the signature.
108+
/// Fixed values so they can be cast as integer types for encoding.
109109
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
110110
pub enum SchnorrSighashType {
111111
/// 0x0: Used when not explicitly specified, defaults to [`SchnorrSighashType::All`]
@@ -349,7 +349,7 @@ impl<R: Deref<Target = Transaction>> SighashCache<R> {
349349
}
350350

351351
/// Encodes the BIP341 signing data for any flag type into a given object implementing a
352-
/// `io::Write` trait.
352+
/// [`io::Write`] trait.
353353
pub fn taproot_encode_signing_data_to<Write: io::Write, T: Borrow<TxOut>>(
354354
&mut self,
355355
mut writer: Write,

0 commit comments

Comments
 (0)