Skip to content

Commit

Permalink
Merge rust-bitcoin#3780: Use uniform capitalisation of SegWit in rust…
Browse files Browse the repository at this point in the history
…docs

e56f461 Make capitalization of SegWit uniform in strings (Jamil Lambert, PhD)
3520e83 Make capitalization of SegWit uniform in rustdocs (Jamil Lambert, PhD)

Pull request description:

  Fixes rust-bitcoin#3770

  - Searched and replaced all occurrences of `//` * `segwit` (case insensitive) with `//` * `SegWit`
  - Searched and replaced all occurrences of `"` * `segwit` (case insensitive) with `"` * `SegWit`

ACKs for top commit:
  apoelstra:
    ACK e56f461; successfully ran local tests

Tree-SHA512: c56704102d8e86f26378bb302d5fdc7ea21d41fd49f55606e589ec32ff896f1adfb1960d8fb29abccfbf298b90fc357ed609d80fd0163dcb4ff01573646b02c3
  • Loading branch information
apoelstra committed Dec 17, 2024
2 parents 1d3f42e + e56f461 commit f4069fc
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 92 deletions.
2 changes: 1 addition & 1 deletion bitcoin/examples/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() {
// This example derives root xprv from a 32-byte seed,
// derives the child xprv with path m/84h/0h/0h,
// prints out corresponding xpub,
// calculates and prints out the first receiving segwit address.
// calculates and prints out the first receiving SegWit address.
// Run this example with cargo and seed(hex-encoded) argument:
// cargo run --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd

Expand Down
8 changes: 4 additions & 4 deletions bitcoin/examples/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use hex_lit::hex;

//run with: cargo run --example sighash

/// Computes segwit sighash for a transaction input that spends a p2wpkh output with "witness_v0_keyhash" scriptPubKey.type
/// Computes SegWit sighash for a transaction input that spends a p2wpkh output with "witness_v0_keyhash" scriptPubKey.type
///
/// # Parameters
///
Expand Down Expand Up @@ -45,7 +45,7 @@ fn compute_sighash_p2wpkh(raw_tx: &[u8], inp_idx: usize, value: u64) {
let sighash = cache
.p2wpkh_signature_hash(inp_idx, &spk, Amount::from_sat(value), sig.sighash_type)
.expect("failed to compute sighash");
println!("Segwit p2wpkh sighash: {:x}", sighash);
println!("SegWit p2wpkh sighash: {:x}", sighash);
let msg = secp256k1::Message::from(sighash);
println!("Message is {:x}", msg);
let secp = secp256k1::Secp256k1::verification_only();
Expand Down Expand Up @@ -98,7 +98,7 @@ fn compute_sighash_legacy(raw_tx: &[u8], inp_idx: usize, script_pubkey_bytes_opt
}
}

/// Computes sighash for a segwit multisig transaction input that spends a p2wsh output with "witness_v0_scripthash" scriptPubKey.type
/// Computes sighash for a SegWit multisig transaction input that spends a p2wsh output with "witness_v0_scripthash" scriptPubKey.type
///
/// # Parameters
///
Expand Down Expand Up @@ -132,7 +132,7 @@ fn compute_sighash_p2wsh(raw_tx: &[u8], inp_idx: usize, value: u64) {
sig.sighash_type,
)
.expect("failed to compute sighash");
println!("Segwit p2wsh sighash: {:x} ({})", sighash, sig.sighash_type);
println!("SegWit p2wsh sighash: {:x} ({})", sighash, sig.sighash_type);
}
}

Expand Down
6 changes: 3 additions & 3 deletions bitcoin/src/address/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl std::error::Error for UnknownAddressTypeError {
pub enum ParseError {
/// Base58 legacy decoding error.
Base58(Base58Error),
/// Bech32 segwit decoding error.
/// Bech32 SegWit decoding error.
Bech32(Bech32Error),
/// Address's network differs from required one.
NetworkValidation(NetworkValidationError),
Expand Down Expand Up @@ -165,7 +165,7 @@ impl std::error::Error for NetworkValidationError {}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Bech32Error {
/// Parse segwit Bech32 error.
/// Parse SegWit Bech32 error.
ParseBech32(ParseBech32Error),
/// A witness version conversion/parsing error.
WitnessVersion(witness_version::TryFromError),
Expand All @@ -182,7 +182,7 @@ impl fmt::Display for Bech32Error {
use Bech32Error::*;

match *self {
ParseBech32(ref e) => write_err!(f, "segwit parsing error"; e),
ParseBech32(ref e) => write_err!(f, "SegWit parsing error"; e),
WitnessVersion(ref e) => write_err!(f, "witness version conversion/parsing error"; e),
WitnessProgram(ref e) => write_err!(f, "witness program error"; e),
UnknownHrp(ref e) => write_err!(f, "unknown hrp error"; e),
Expand Down
26 changes: 13 additions & 13 deletions bitcoin/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub enum AddressData {
/// The script hash used to encumber outputs to this address.
script_hash: ScriptHash,
},
/// Data encoded by a Segwit address.
/// Data encoded by a SegWit address.
Segwit {
/// The witness program used to encumber outputs to this address.
witness_program: WitnessProgram,
Expand Down Expand Up @@ -421,7 +421,7 @@ impl Address {

/// Constructs a new pay-to-witness-public-key-hash (P2WPKH) [`Address`] from a public key.
///
/// This is the native segwit address type for an output redeemable with a single signature.
/// This is the native SegWit address type for an output redeemable with a single signature.
pub fn p2wpkh(pk: CompressedPublicKey, hrp: impl Into<KnownHrp>) -> Self {
let program = WitnessProgram::p2wpkh(pk);
Address::from_witness_program(program, hrp)
Expand All @@ -430,7 +430,7 @@ impl Address {
/// Constructs a new pay-to-script-hash (P2SH) [`Address`] that embeds a
/// pay-to-witness-public-key-hash (P2WPKH).
///
/// This is a segwit address type that looks familiar (as p2sh) to legacy clients.
/// This is a SegWit address type that looks familiar (as p2sh) to legacy clients.
pub fn p2shwpkh(pk: CompressedPublicKey, network: impl Into<NetworkKind>) -> Address {
let builder = script::Builder::new().push_int_unchecked(0).push_slice(pk.wpubkey_hash());
let script_hash = builder.as_script().script_hash().expect("script is less than 520 bytes");
Expand All @@ -455,7 +455,7 @@ impl Address {
/// Constructs a new pay-to-script-hash (P2SH) [`Address`] that embeds a
/// pay-to-witness-script-hash (P2WSH).
///
/// This is a segwit address type that looks familiar (as p2sh) to legacy clients.
/// This is a SegWit address type that looks familiar (as p2sh) to legacy clients.
pub fn p2shwsh(
witness_script: &Script,
network: impl Into<NetworkKind>,
Expand Down Expand Up @@ -546,7 +546,7 @@ impl Address {
}
}

/// Gets the witness program for this address if this is a segwit address.
/// Gets the witness program for this address if this is a SegWit address.
pub fn witness_program(&self) -> Option<WitnessProgram> {
use AddressInner::*;

Expand Down Expand Up @@ -642,7 +642,7 @@ impl Address {
/// Returns true if the given pubkey is directly related to the address payload.
///
/// This is determined by directly comparing the address payload with either the
/// hash of the given public key or the segwit redeem hash generated from the
/// hash of the given public key or the SegWit redeem hash generated from the
/// given key. For Taproot addresses, the supplied key is assumed to be tweaked
pub fn is_related_to_pubkey(&self, pubkey: PublicKey) -> bool {
let pubkey_hash = pubkey.pubkey_hash();
Expand Down Expand Up @@ -684,7 +684,7 @@ impl Address {
///
/// - For p2sh, the payload is the script hash.
/// - For p2pkh, the payload is the pubkey hash.
/// - For segwit addresses, the payload is the witness program.
/// - For SegWit addresses, the payload is the witness program.
fn payload_as_bytes(&self) -> &[u8] {
use AddressInner::*;
match self.0 {
Expand Down Expand Up @@ -868,18 +868,18 @@ impl<V: NetworkValidation> fmt::Debug for Address<V> {

/// Address can be parsed only with `NetworkUnchecked`.
///
/// Only segwit bech32 addresses prefixed with `bc`, `bcrt` or `tb` and legacy base58 addresses
/// Only SegWit bech32 addresses prefixed with `bc`, `bcrt` or `tb` and legacy base58 addresses
/// prefixed with `1`, `2, `3`, `m` or `n` are supported.
///
/// # Errors
///
/// - [`ParseError::Bech32`] if the segwit address begins with a `bc`, `bcrt` or `tb` and is not a
/// - [`ParseError::Bech32`] if the SegWit address begins with a `bc`, `bcrt` or `tb` and is not a
/// valid bech32 address.
///
/// - [`ParseError::Base58`] if the legacy address begins with a `1`, `2`, `3`, `m` or `n` and is
/// not a valid base58 address.
///
/// - [`UnknownHrpError`] if the address does not begin with one of the above segwit or
/// - [`UnknownHrpError`] if the address does not begin with one of the above SegWit or
/// legacy prifixes.
impl FromStr for Address<NetworkUnchecked> {
type Err = ParseError;
Expand All @@ -899,7 +899,7 @@ impl FromStr for Address<NetworkUnchecked> {
}
}

/// Convert a byte array of a pubkey hash into a segwit redeem hash
/// Convert a byte array of a pubkey hash into a SegWit redeem hash
fn segwit_redeem_hash(pubkey_hash: PubkeyHash) -> hash160::Hash {
let mut sha_engine = hash160::Hash::engine();
sha_engine.input(&[0, 20]);
Expand Down Expand Up @@ -1099,9 +1099,9 @@ mod tests {
Some(AddressType::P2tr),
),
// Related to future extensions, addresses are valid but have no type
// segwit v1 and len != 32
// SegWit v1 and len != 32
("bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y", None),
// segwit v2
// SegWit v2
("bc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs", None),
];
for (address, expected_type) in &addresses {
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/address/script_pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub(super) fn new_witness_program_unchecked<T: AsRef<PushBytes>>(
) -> ScriptBuf {
let program = program.as_ref();
debug_assert!(program.len() >= 2 && program.len() <= 40);
// In segwit v0, the program must be 20 or 32 bytes long.
// In SegWit v0, the program must be 20 or 32 bytes long.
debug_assert!(version != WitnessVersion::V0 || program.len() == 20 || program.len() == 32);
Builder::new().push_opcode(version.into()).push_slice(program).into_script()
}
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/script/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ crate::internal_macros::define_extension_trait! {
instructions.next().is_none()
}

/// Checks whether a script pubkey is a Segregated Witness (segwit) program.
/// Checks whether a script pubkey is a Segregated Witness (SegWit) program.
#[inline]
fn is_witness_program(&self) -> bool { self.witness_version().is_some() }

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/script/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ fn script_ord() {
fn test_bitcoinconsensus() {
use crate::consensus_validation::ScriptExt as _;

// a random segwit transaction from the blockchain using native segwit
// a random SegWit transaction from the blockchain using native SegWit
let spent_bytes = hex!("0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d");
let spent = Script::from_bytes(&spent_bytes);
let spending = hex!("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000");
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/src/blockdata/script/witness_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub const MAX_SIZE: usize = 40;
/// number, therefore we carry the version number around along with the program bytes.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WitnessProgram {
/// The segwit version associated with this witness program.
/// The SegWit version associated with this witness program.
version: WitnessVersion,
/// The witness program (between 2 and 40 bytes).
program: ArrayVec<u8, MAX_SIZE>,
Expand All @@ -47,7 +47,7 @@ impl WitnessProgram {
return Err(InvalidLength(program_len));
}

// Specific segwit v0 check. These addresses can never spend funds sent to them.
// Specific SegWit v0 check. These addresses can never spend funds sent to them.
if version == WitnessVersion::V0 && (program_len != 20 && program_len != 32) {
return Err(InvalidSegwitV0Length(program_len));
}
Expand Down
Loading

0 comments on commit f4069fc

Please sign in to comment.