Standardize wording to `constructs a new`

There is a range of different wordings used in the docs of constructor
type functions.

Change all to start with `Constructs a new` or `Constructs an empty`.
This commit is contained in:
Jamil Lambert, PhD 2024-11-05 12:45:06 +00:00
parent 27f94d5540
commit 1649b68589
No known key found for this signature in database
GPG Key ID: 54DC29234AB5D2C0
57 changed files with 173 additions and 173 deletions

View File

@ -108,7 +108,7 @@ fn receivers_address() -> Address {
.expect("valid address for mainnet")
}
/// Constructs a p2wpkh output locked to the key associated with `wpkh`.
/// Constructs a new p2wpkh output locked to the key associated with `wpkh`.
///
/// An utxo is described by the `OutPoint` (txid and index within the transaction that it was
/// created). Using the out point one can get the transaction by `txid` and using the `vout` get the

View File

@ -105,7 +105,7 @@ fn receivers_address() -> Address {
.expect("valid address for mainnet")
}
/// Constructs a p2wpkh output locked to the key associated with `wpkh`.
/// Constructs a new p2wpkh output locked to the key associated with `wpkh`.
///
/// An utxo is described by the `OutPoint` (txid and index within the transaction that it was
/// created). Using the out point one can get the transaction by `txid` and using the `vout` get the

View File

@ -202,7 +202,7 @@ pub enum KnownHrp {
}
impl KnownHrp {
/// Constructs a `KnownHrp` from `network`.
/// Constructs a new `KnownHrp` from `network`.
fn from_network(network: Network) -> Self {
use Network::*;
@ -213,7 +213,7 @@ impl KnownHrp {
}
}
/// Constructs a `KnownHrp` from a [`bech32::Hrp`].
/// Constructs a new `KnownHrp` from a [`bech32::Hrp`].
fn from_hrp(hrp: Hrp) -> Result<Self, UnknownHrpError> {
if hrp == bech32::hrp::BC {
Ok(Self::Mainnet)
@ -387,7 +387,7 @@ impl<V: NetworkValidation> Address<V> {
/// Methods and functions that can be called only on `Address<NetworkChecked>`.
impl Address {
/// Constructs a pay to (compressed) public key hash address from a public key.
/// Constructs a new pay to (compressed) public key hash address from a public key.
///
/// This is the preferred non-witness type address.
#[inline]
@ -396,7 +396,7 @@ impl Address {
Self(AddressInner::P2pkh { hash, network: network.into() }, PhantomData)
}
/// Constructs a pay to script hash P2SH address from a script.
/// Constructs a new pay to script hash P2SH address from a script.
///
/// This address type was introduced with BIP16 and is the popular type to implement multi-sig
/// these days.
@ -409,7 +409,7 @@ impl Address {
Ok(Address::p2sh_from_hash(hash, network))
}
/// Constructs a pay to script hash P2SH address from a script hash.
/// Constructs a new pay to script hash P2SH address from a script hash.
///
/// # Warning
///
@ -419,7 +419,7 @@ impl Address {
Self(AddressInner::P2sh { hash, network: network.into() }, PhantomData)
}
/// Constructs a witness pay to public key address from a public key.
/// Constructs a new witness pay to public key address from a public key.
///
/// 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 {
@ -427,7 +427,7 @@ impl Address {
Address::from_witness_program(program, hrp)
}
/// Constructs a pay to script address that embeds a witness pay to public key.
/// Constructs a new pay to script address that embeds a witness pay to public key.
///
/// This is a segwit address type that looks familiar (as p2sh) to legacy clients.
pub fn p2shwpkh(pk: CompressedPublicKey, network: impl Into<NetworkKind>) -> Address {
@ -436,7 +436,7 @@ impl Address {
Address::p2sh_from_hash(script_hash, network)
}
/// Constructs a witness pay to script hash address.
/// Constructs a new witness pay to script hash address.
pub fn p2wsh(
witness_script: &Script,
hrp: impl Into<KnownHrp>,
@ -445,13 +445,13 @@ impl Address {
Ok(Address::from_witness_program(program, hrp))
}
/// Constructs a witness pay to script hash address.
/// Constructs a new witness pay to script hash address.
pub fn p2wsh_from_hash(hash: WScriptHash, hrp: impl Into<KnownHrp>) -> Address {
let program = WitnessProgram::p2wsh_from_hash(hash);
Address::from_witness_program(program, hrp)
}
/// Constructs a pay to script address that embeds a witness pay to script hash address.
/// Constructs a new pay to script address that embeds a witness pay to script hash address.
///
/// This is a segwit address type that looks familiar (as p2sh) to legacy clients.
pub fn p2shwsh(
@ -464,7 +464,7 @@ impl Address {
Ok(Address::p2sh_from_hash(script_hash, network))
}
/// Constructs a pay to Taproot address from an untweaked key.
/// Constructs a new pay to Taproot address from an untweaked key.
pub fn p2tr<C: Verification>(
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
@ -475,13 +475,13 @@ impl Address {
Address::from_witness_program(program, hrp)
}
/// Constructs a pay to Taproot address from a pre-tweaked output key.
/// Constructs a new pay to Taproot address from a pre-tweaked output key.
pub fn p2tr_tweaked(output_key: TweakedPublicKey, hrp: impl Into<KnownHrp>) -> Address {
let program = WitnessProgram::p2tr_tweaked(output_key);
Address::from_witness_program(program, hrp)
}
/// Constructs an address from an arbitrary witness program.
/// Constructs a new address from an arbitrary witness program.
///
/// This only exists to support future witness versions. If you are doing normal mainnet things
/// then you likely do not need this constructor.
@ -569,7 +569,7 @@ impl Address {
///
pub fn is_spend_standard(&self) -> bool { self.address_type().is_some() }
/// Constructs an [`Address`] from an output script (`scriptPubkey`).
/// Constructs a new [`Address`] from an output script (`scriptPubkey`).
pub fn from_script(
script: &Script,
params: impl AsRef<Params>,
@ -608,7 +608,7 @@ impl Address {
}
}
/// Constructs a URI string *bitcoin:address* optimized to be encoded in QR codes.
/// Constructs a new URI string *bitcoin:address* optimized to be encoded in QR codes.
///
/// If the address is bech32, the address becomes uppercase.
/// If the address is base58, the address is left mixed case.

View File

@ -378,7 +378,7 @@ pub struct BlockTransactions {
impl_consensus_encoding!(BlockTransactions, block_hash, transactions);
impl BlockTransactions {
/// Constructs a [`BlockTransactions`] from a [`BlockTransactionsRequest`] and
/// Constructs a new [`BlockTransactions`] from a [`BlockTransactionsRequest`] and
/// the corresponding full [`Block`] by providing all requested transactions.
pub fn from_request(
request: &BlockTransactionsRequest,

View File

@ -138,7 +138,7 @@ impl ChildNumber {
/// Hardened child number with index 1.
pub const ONE_HARDENED: Self = ChildNumber::Hardened { index: 1 };
/// Construct a [`Normal`] from an index, returns an error if the index is not within
/// Constructs a new [`Normal`] from an index, returns an error if the index is not within
/// [0, 2^31 - 1].
///
/// [`Normal`]: #variant.Normal
@ -150,7 +150,7 @@ impl ChildNumber {
}
}
/// Construct a [`Hardened`] from an index, returns an error if the index is not within
/// Constructs a new [`Hardened`] from an index, returns an error if the index is not within
/// [0, 2^31 - 1].
///
/// [`Hardened`]: #variant.Hardened
@ -387,7 +387,7 @@ impl DerivationPath {
/// is empty). True for `m` path.
pub fn is_master(&self) -> bool { self.0.is_empty() }
/// Construct a new [DerivationPath] that is a child of this one.
/// Constructs a new [DerivationPath] that is a child of this one.
pub fn child(&self, cn: ChildNumber) -> DerivationPath {
let mut path = self.0.clone();
path.push(cn);
@ -451,7 +451,7 @@ impl DerivationPath {
/// ```
pub fn to_u32_vec(&self) -> Vec<u32> { self.into_iter().map(|&el| el.into()).collect() }
/// Constructs a derivation path from a slice of u32s.
/// Constructs a new derivation path from a slice of u32s.
/// ```
/// use bitcoin::bip32::DerivationPath;
///
@ -575,7 +575,7 @@ impl From<InvalidBase58PayloadLengthError> for Error {
}
impl Xpriv {
/// Construct a new master key from a seed value
/// Constructs a new master key from a seed value
pub fn new_master(network: impl Into<NetworkKind>, seed: &[u8]) -> Result<Xpriv, Error> {
let mut hmac_engine: HmacEngine<sha512::Hash> = HmacEngine::new(b"Bitcoin seed");
hmac_engine.input(seed);
@ -591,21 +591,21 @@ impl Xpriv {
})
}
/// Constructs ECDSA compressed private key matching internal secret key representation.
/// Constructs a new ECDSA compressed private key matching internal secret key representation.
#[deprecated(since = "TBD", note = "use `to_private_key()` instead")]
pub fn to_priv(self) -> PrivateKey { self.to_private_key() }
/// Constructs ECDSA compressed private key matching internal secret key representation.
/// Constructs a new ECDSA compressed private key matching internal secret key representation.
pub fn to_private_key(self) -> PrivateKey {
PrivateKey { compressed: true, network: self.network, inner: self.private_key }
}
/// Constructs new extended public key from this extended private key.
/// Constructs a new extended public key from this extended private key.
pub fn to_xpub<C: secp256k1::Signing>(&self, secp: &Secp256k1<C>) -> Xpub {
Xpub::from_xpriv(secp, self)
}
/// Constructs BIP340 keypair for Schnorr signatures and Taproot use matching the internal
/// Constructs a new BIP340 keypair for Schnorr signatures and Taproot use matching the internal
/// secret key representation.
pub fn to_keypair<C: secp256k1::Signing>(self, secp: &Secp256k1<C>) -> Keypair {
Keypair::from_seckey_slice(secp, &self.private_key[..])
@ -730,13 +730,13 @@ impl Xpriv {
}
impl Xpub {
/// Constructs extended public key from an extended private key.
/// Constructs a new extended public key from an extended private key.
#[deprecated(since = "TBD", note = "use `from_xpriv()` instead")]
pub fn from_priv<C: secp256k1::Signing>(secp: &Secp256k1<C>, sk: &Xpriv) -> Xpub {
Self::from_xpriv(secp, sk)
}
/// Constructs extended public key from an extended private key.
/// Constructs a new extended public key from an extended private key.
pub fn from_xpriv<C: secp256k1::Signing>(secp: &Secp256k1<C>, xpriv: &Xpriv) -> Xpub {
Xpub {
network: xpriv.network,
@ -748,19 +748,19 @@ impl Xpub {
}
}
/// Constructs ECDSA compressed public key matching internal public key representation.
/// Constructs a new ECDSA compressed public key matching internal public key representation.
#[deprecated(since = "TBD", note = "use `to_public_key()` instead")]
pub fn to_pub(self) -> CompressedPublicKey { self.to_public_key() }
/// Constructs ECDSA compressed public key matching internal public key representation.
/// Constructs a new ECDSA compressed public key matching internal public key representation.
pub fn to_public_key(self) -> CompressedPublicKey { CompressedPublicKey(self.public_key) }
/// Constructs BIP340 x-only public key for BIP-340 signatures and Taproot use matching
/// Constructs a new BIP340 x-only public key for BIP-340 signatures and Taproot use matching
/// the internal public key representation.
#[deprecated(since = "TBD", note = "use `to_x_only_public_key()` instead")]
pub fn to_x_only_pub(self) -> XOnlyPublicKey { self.to_x_only_public_key() }
/// Constructs BIP340 x-only public key for BIP-340 signatures and Taproot use matching
/// Constructs a new BIP340 x-only public key for BIP-340 signatures and Taproot use matching
/// the internal public key representation.
pub fn to_x_only_public_key(self) -> XOnlyPublicKey { XOnlyPublicKey::from(self.public_key) }

View File

@ -220,7 +220,7 @@ impl<'a> InstructionIndices<'a> {
#[inline]
pub fn as_script(&self) -> &'a Script { self.instructions.as_script() }
/// Constructs `Self` setting `pos` to 0.
/// Constructs a new `Self` setting `pos` to 0.
pub(super) fn from_instructions(instructions: Instructions<'a>) -> Self {
InstructionIndices { instructions, pos: 0 }
}

View File

@ -95,7 +95,7 @@ hashes::hash_newtype! {
impl_asref_push_bytes!(ScriptHash, WScriptHash);
impl ScriptHash {
/// Constructs a `ScriptHash` after first checking the script size.
/// Constructs a new `ScriptHash` after first checking the script size.
///
/// # 520-byte limitation on serialized script size
///
@ -113,7 +113,7 @@ impl ScriptHash {
Ok(ScriptHash(hash160::Hash::hash(redeem_script.as_bytes())))
}
/// Constructs a `ScriptHash` from any script irrespective of script size.
/// Constructs a new `ScriptHash` from any script irrespective of script size.
///
/// If you hash a script that exceeds 520 bytes in size and use it to create a P2SH output
/// then the output will be unspendable (see [BIP-16]).
@ -125,7 +125,7 @@ impl ScriptHash {
}
impl WScriptHash {
/// Constructs a `WScriptHash` after first checking the script size.
/// Constructs a new `WScriptHash` after first checking the script size.
///
/// # 10,000-byte limit on the witness script
///
@ -141,7 +141,7 @@ impl WScriptHash {
Ok(WScriptHash(sha256::Hash::hash(witness_script.as_bytes())))
}
/// Constructs a `WScriptHash` from any script irrespective of script size.
/// Constructs a new `WScriptHash` from any script irrespective of script size.
///
/// If you hash a script that exceeds 10,000 bytes in size and use it to create a Segwit
/// output then the output will be unspendable (see [BIP-141]).
@ -200,7 +200,7 @@ impl TryFrom<&Script> for WScriptHash {
}
}
/// Constructs the script code used for spending a P2WPKH output.
/// Constructs a new [`ScriptBuf`] containing the script code used for spending a P2WPKH output.
///
/// The `scriptCode` is described in [BIP143].
///

View File

@ -26,7 +26,7 @@ crate::internal_macros::define_extension_trait! {
Builder::new().push_opcode(OP_RETURN).push_slice(data).into_script()
}
/// Constructs a [`ScriptBuf`] from a hex string.
/// Constructs a new [`ScriptBuf`] from a hex string.
fn from_hex(s: &str) -> Result<ScriptBuf, hex::HexToBytesError> {
let v = Vec::from_hex(s)?;
Ok(ScriptBuf::from_bytes(v))

View File

@ -45,7 +45,7 @@ mod primitive {
pub struct PushBytes([u8]);
impl PushBytes {
/// Constructs `&PushBytes` without checking the length.
/// Constructs a new `&PushBytes` without checking the length.
///
/// The caller is responsible for checking that the length is less than the 2^32.
fn from_slice_unchecked(bytes: &[u8]) -> &Self {
@ -54,7 +54,7 @@ mod primitive {
unsafe { &*(bytes as *const [u8] as *const PushBytes) }
}
/// Constructs `&mut PushBytes` without checking the length.
/// Constructs a new `&mut PushBytes` without checking the length.
///
/// The caller is responsible for checking that the length is less than the 2^32.
fn from_mut_slice_unchecked(bytes: &mut [u8]) -> &mut Self {
@ -200,11 +200,11 @@ mod primitive {
pub struct PushBytesBuf(Vec<u8>);
impl PushBytesBuf {
/// Constructs a new empty `PushBytesBuf`.
/// Constructs an empty `PushBytesBuf`.
#[inline]
pub const fn new() -> Self { PushBytesBuf(Vec::new()) }
/// Constructs a new empty `PushBytesBuf` with reserved capacity.
/// Constructs an empty `PushBytesBuf` with reserved capacity.
pub fn with_capacity(capacity: usize) -> Self { PushBytesBuf(Vec::with_capacity(capacity)) }
/// Reserve capacity for `additional_capacity` bytes.

View File

@ -56,38 +56,38 @@ impl WitnessProgram {
Ok(WitnessProgram { version, program })
}
/// Constructs a [`WitnessProgram`] from a 20 byte pubkey hash.
/// Constructs a new [`WitnessProgram`] from a 20 byte pubkey hash.
fn new_p2wpkh(program: [u8; 20]) -> Self {
WitnessProgram { version: WitnessVersion::V0, program: ArrayVec::from_slice(&program) }
}
/// Constructs a [`WitnessProgram`] from a 32 byte script hash.
/// Constructs a new [`WitnessProgram`] from a 32 byte script hash.
fn new_p2wsh(program: [u8; 32]) -> Self {
WitnessProgram { version: WitnessVersion::V0, program: ArrayVec::from_slice(&program) }
}
/// Constructs a [`WitnessProgram`] from a 32 byte serialize Taproot xonly pubkey.
/// Constructs a new [`WitnessProgram`] from a 32 byte serialize Taproot xonly pubkey.
fn new_p2tr(program: [u8; 32]) -> Self {
WitnessProgram { version: WitnessVersion::V1, program: ArrayVec::from_slice(&program) }
}
/// Constructs a [`WitnessProgram`] from `pk` for a P2WPKH output.
/// Constructs a new [`WitnessProgram`] from `pk` for a P2WPKH output.
pub fn p2wpkh(pk: CompressedPublicKey) -> Self {
let hash = pk.wpubkey_hash();
WitnessProgram::new_p2wpkh(hash.to_byte_array())
}
/// Constructs a [`WitnessProgram`] from `script` for a P2WSH output.
/// Constructs a new [`WitnessProgram`] from `script` for a P2WSH output.
pub fn p2wsh(script: &Script) -> Result<Self, WitnessScriptSizeError> {
script.wscript_hash().map(Self::p2wsh_from_hash)
}
/// Constructs a [`WitnessProgram`] from `script` for a P2WSH output.
/// Constructs a new [`WitnessProgram`] from `script` for a P2WSH output.
pub fn p2wsh_from_hash(hash: WScriptHash) -> Self {
WitnessProgram::new_p2wsh(hash.to_byte_array())
}
/// Constructs a pay to Taproot address from an untweaked key.
/// Constructs a new pay to Taproot address from an untweaked key.
pub fn p2tr<C: Verification>(
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
@ -98,7 +98,7 @@ impl WitnessProgram {
WitnessProgram::new_p2tr(pubkey)
}
/// Constructs a pay to Taproot address from a pre-tweaked output key.
/// Constructs a new pay to Taproot address from a pre-tweaked output key.
pub fn p2tr_tweaked(output_key: TweakedPublicKey) -> Self {
let pubkey = output_key.to_inner().serialize();
WitnessProgram::new_p2tr(pubkey)

View File

@ -174,7 +174,7 @@ crate::internal_macros::define_extension_trait! {
/// There is no difference between base size vs total size for outputs.
fn size(&self) -> usize { size_from_script_pubkey(&self.script_pubkey) }
/// Constructs a `TxOut` with given script and the smallest possible `value` that is **not** dust
/// Constructs a new `TxOut` with given script and the smallest possible `value` that is **not** dust
/// per current Core policy.
///
/// Dust depends on the -dustrelayfee value of the Bitcoin Core node you are broadcasting to.
@ -187,7 +187,7 @@ crate::internal_macros::define_extension_trait! {
TxOut { value: script_pubkey.minimal_non_dust(), script_pubkey }
}
/// Constructs a `TxOut` with given script and the smallest possible `value` that is **not** dust
/// Constructs a new `TxOut` with given script and the smallest possible `value` that is **not** dust
/// per current Core policy.
///
/// Dust depends on the -dustrelayfee value of the Bitcoin Core node you are broadcasting to.
@ -639,7 +639,7 @@ impl std::error::Error for IndexOutOfBoundsError {
crate::internal_macros::define_extension_trait! {
/// Extension functionality for the [`Version`] type.
pub trait VersionExt impl for Version {
/// Constructs a non-standard transaction version.
/// Constructs a new non-standard transaction version.
fn non_standard(version: i32) -> Version { Self(version) }
/// Returns true if this transaction version number is considered standard.

View File

@ -112,7 +112,7 @@ impl Encodable for Witness {
crate::internal_macros::define_extension_trait! {
/// Extension functionality for the [`Witness`] type.
pub trait WitnessExt impl for Witness {
/// Constructs a witness required to spend a P2WPKH output.
/// Constructs a new witness required to spend a P2WPKH output.
///
/// The witness will be made up of the DER encoded signature + sighash_type followed by the
/// serialized public key. Also useful for spending a P2SH-P2WPKH output.
@ -125,7 +125,7 @@ crate::internal_macros::define_extension_trait! {
witness
}
/// Constructs a witness required to do a key path spend of a P2TR output.
/// Constructs a new witness required to do a key path spend of a P2TR output.
fn p2tr_key_spend(signature: &taproot::Signature) -> Witness {
let mut witness = Witness::new();
witness.push(signature.serialize());

View File

@ -243,7 +243,7 @@ impl From<OddLengthStringError> for FromHexError {
fn from(e: OddLengthStringError) -> Self { Self::OddLengthString(e) }
}
/// Constructs a `Error::ParseFailed` error.
/// Constructs a new `Error::ParseFailed` error.
// This whole variant should go away because of the inner string.
pub(crate) fn parse_failed_error(msg: &'static str) -> Error {
Error::Parse(ParseError::ParseFailed(msg))

View File

@ -319,7 +319,7 @@ pub trait ByteDecoder<'a> {
/// The decoder state.
type Decoder: Iterator<Item = Result<u8, Self::DecodeError>>;
/// Constructs the decoder from string.
/// Constructs a new decoder from string.
fn from_str(s: &'a str) -> Result<Self::Decoder, Self::InitError>;
}

View File

@ -32,7 +32,7 @@ pub struct Signature {
}
impl Signature {
/// Constructs an ECDSA Bitcoin signature for [`EcdsaSighashType::All`].
/// Constructs a new ECDSA Bitcoin signature for [`EcdsaSighashType::All`].
pub fn sighash_all(signature: secp256k1::ecdsa::Signature) -> Signature {
Signature { signature, sighash_type: EcdsaSighashType::All }
}

View File

@ -38,12 +38,12 @@ pub struct PublicKey {
}
impl PublicKey {
/// Constructs compressed ECDSA public key from the provided generic Secp256k1 public key.
/// Constructs a new compressed ECDSA public key from the provided generic Secp256k1 public key.
pub fn new(key: impl Into<secp256k1::PublicKey>) -> PublicKey {
PublicKey { compressed: true, inner: key.into() }
}
/// Constructs uncompressed (legacy) ECDSA public key from the provided generic Secp256k1
/// Constructs a new uncompressed (legacy) ECDSA public key from the provided generic Secp256k1
/// public key.
pub fn new_uncompressed(key: impl Into<secp256k1::PublicKey>) -> PublicKey {
PublicKey { compressed: false, inner: key.into() }
@ -416,20 +416,20 @@ pub struct PrivateKey {
}
impl PrivateKey {
/// Constructs new compressed ECDSA private key using the secp256k1 algorithm and
/// Constructs a new compressed ECDSA private key using the secp256k1 algorithm and
/// a secure random number generator.
#[cfg(feature = "rand-std")]
pub fn generate(network: impl Into<NetworkKind>) -> PrivateKey {
let secret_key = secp256k1::SecretKey::new(&mut rand::thread_rng());
PrivateKey::new(secret_key, network.into())
}
/// Constructs compressed ECDSA private key from the provided generic Secp256k1 private key
/// Constructs a new compressed ECDSA private key from the provided generic Secp256k1 private key
/// and the specified network.
pub fn new(key: secp256k1::SecretKey, network: impl Into<NetworkKind>) -> PrivateKey {
PrivateKey { compressed: true, network: network.into(), inner: key }
}
/// Constructs uncompressed (legacy) ECDSA private key from the provided generic Secp256k1
/// Constructs a new uncompressed (legacy) ECDSA private key from the provided generic Secp256k1
/// private key and the specified network.
pub fn new_uncompressed(
key: secp256k1::SecretKey,
@ -438,7 +438,7 @@ impl PrivateKey {
PrivateKey { compressed: false, network: network.into(), inner: key }
}
/// Constructs a public key from this private key.
/// Constructs a new public key from this private key.
pub fn public_key<C: secp256k1::Signing>(&self, secp: &Secp256k1<C>) -> PublicKey {
PublicKey {
compressed: self.compressed,

View File

@ -418,7 +418,7 @@ impl EcdsaSighashType {
}
}
/// Constructs a [`EcdsaSighashType`] from a raw `u32`.
/// Constructs a new [`EcdsaSighashType`] from a raw `u32`.
///
/// **Note**: this replicates consensus behaviour, for current standardness rules correctness
/// you probably want [`Self::from_standard`].
@ -449,7 +449,7 @@ impl EcdsaSighashType {
}
}
/// Constructs a [`EcdsaSighashType`] from a raw `u32`.
/// Constructs a new [`EcdsaSighashType`] from a raw `u32`.
///
/// # Errors
///
@ -506,7 +506,7 @@ impl TapSighashType {
}
}
/// Constructs a [`TapSighashType`] from a raw `u8`.
/// Constructs a new [`TapSighashType`] from a raw `u8`.
pub fn from_consensus_u8(sighash_type: u8) -> Result<Self, InvalidSighashTypeError> {
use TapSighashType::*;

View File

@ -54,7 +54,7 @@ pub(crate) use impl_consensus_encoding;
macro_rules! impl_array_newtype_stringify {
($t:ident, $len:literal) => {
impl $t {
/// Constructs `Self` from a hex string.
/// Constructs a new `Self` from a hex string.
pub fn from_hex(s: &str) -> Result<Self, hex::HexToArrayError> {
Ok($t($crate::hex::FromHex::from_hex(s)?))
}
@ -282,7 +282,7 @@ pub(crate) use define_extension_trait;
macro_rules! impl_array_newtype {
($thing:ident, $ty:ty, $len:literal) => {
impl $thing {
/// Constructs `Self` by wrapping `bytes`.
/// Constructs a new `Self` by wrapping `bytes`.
#[inline]
pub fn from_byte_array(bytes: [u8; $len]) -> Self { Self(bytes) }

View File

@ -35,7 +35,7 @@ pub struct MerkleBlock {
}
impl MerkleBlock {
/// Construct a MerkleBlock from a block, that contains proofs for specific txids.
/// Constructs a new MerkleBlock from a block, that contains proofs for specific txids.
///
/// The `block` is a full block containing the header and transactions and `match_txids` is a
/// function that returns true for the ids that should be included in the partial Merkle tree.
@ -60,7 +60,7 @@ impl MerkleBlock {
/// 5d35549d88ac00000000").unwrap();
/// let block: Block = bitcoin::consensus::deserialize(&block_bytes).unwrap();
///
/// // Construct a Merkle block containing a single transaction
/// // Constructs a new Merkle block containing a single transaction
/// let txid = "5a4ebf66822b0b2d56bd9dc64ece0bc38ee7844a23ff1d7320a88c5fdb2ad3e2".parse::<Txid>().unwrap();
/// let match_txids: Vec<Txid> = vec![txid].into_iter().collect();
/// let mb = MerkleBlock::from_block_with_predicate(&block, |t| match_txids.contains(t));
@ -79,7 +79,7 @@ impl MerkleBlock {
Self::from_header_txids_with_predicate(&block.header, &block_txids, match_txids)
}
/// Construct a MerkleBlock from the block's header and txids, that contain proofs for specific txids.
/// Constructs a new MerkleBlock from the block's header and txids, that contain proofs for specific txids.
///
/// The `header` is the block header, `block_txids` is the full list of txids included in the block and
/// `match_txids` is a function that returns true for the ids that should be included in the partial Merkle tree.
@ -185,7 +185,7 @@ impl PartialMerkleTree {
/// Returns the transaction ids and internal hashes of the partial Merkle tree.
pub fn hashes(&self) -> &Vec<TxMerkleNode> { &self.hashes }
/// Construct a partial Merkle tree
/// Constructs a new partial Merkle tree
/// The `txids` are the transaction hashes of the block and the `matches` is the contains flags
/// wherever a tx hash should be included in the proof.
///
@ -653,7 +653,7 @@ mod tests {
assert_eq!(mb_hex, encode::serialize(&mb).to_lower_hex_string().as_str());
}
/// Construct a CMerkleBlock using a list of txids which will be found in the
/// Constructs a new CMerkleBlock using a list of txids which will be found in the
/// given block.
#[test]
fn merkleblock_construct_from_txids_found() {
@ -692,7 +692,7 @@ mod tests {
assert_eq!(index[1], 8);
}
/// Construct a CMerkleBlock using a list of txids which will not be found in the given block
/// Constructs a new CMerkleBlock using a list of txids which will not be found in the given block
#[test]
fn merkleblock_construct_from_txids_not_found() {
let block = get_block_13b8a();

View File

@ -124,7 +124,7 @@ impl<'de> Deserialize<'de> for Network {
}
impl Network {
/// Constructs a `Network` from the magic bytes.
/// Constructs a new `Network` from the magic bytes.
///
/// # Examples
///
@ -207,7 +207,7 @@ impl Network {
/// ```
pub fn chain_hash(self) -> ChainHash { ChainHash::using_genesis_block_const(self) }
/// Constructs a `Network` from the chain hash (genesis block hash).
/// Constructs a new `Network` from the chain hash (genesis block hash).
///
/// # Examples
///

View File

@ -28,7 +28,7 @@ pub struct Address {
const ONION: [u16; 3] = [0xFD87, 0xD87E, 0xEB43];
impl Address {
/// Construct an address message for a socket
/// Construct a new address message for a socket
pub fn new(socket: &SocketAddr, services: ServiceFlags) -> Address {
let (address, port) = match *socket {
SocketAddr::V4(addr) => (addr.ip().to_ipv6_mapped().segments(), addr.port()),

View File

@ -301,7 +301,7 @@ impl NetworkMessage {
}
impl RawNetworkMessage {
/// Constructs a [RawNetworkMessage]
/// Constructs a new [RawNetworkMessage]
pub fn new(magic: Magic, payload: NetworkMessage) -> Self {
let mut engine = sha256d::Hash::engine();
let payload_len = payload.consensus_encode(&mut engine).expect("engine doesn't error");

View File

@ -228,7 +228,7 @@ impl Magic {
/// Bitcoin regtest network magic bytes.
pub const REGTEST: Self = Self([0xFA, 0xBF, 0xB5, 0xDA]);
/// Construct network magic from bytes.
/// Construct a new network magic from bytes.
pub const fn from_bytes(bytes: [u8; 4]) -> Magic { Magic(bytes) }
/// Get network magic bytes.

View File

@ -340,13 +340,13 @@ impl_to_hex_from_lower_hex!(Target, |_| 64);
define_extension_trait! {
/// Extension functionality for the [`CompactTarget`] type.
pub trait CompactTargetExt impl for CompactTarget {
/// Constructs a `CompactTarget` from a prefixed hex string.
/// Constructs a new `CompactTarget` from a prefixed hex string.
fn from_hex(s: &str) -> Result<CompactTarget, PrefixedHexError> {
let target = parse::hex_u32_prefixed(s)?;
Ok(Self::from_consensus(target))
}
/// Constructs a `CompactTarget` from an unprefixed hex string.
/// Constructs a new `CompactTarget` from an unprefixed hex string.
fn from_unprefixed_hex(s: &str) -> Result<CompactTarget, UnprefixedHexError> {
let target = parse::hex_u32_unprefixed(s)?;
Ok(Self::from_consensus(target))
@ -466,13 +466,13 @@ impl U256 {
const ONE: U256 = U256(0, 1);
/// Constructs a `U256` from a prefixed hex string.
/// Constructs a new `U256` from a prefixed hex string.
fn from_hex(s: &str) -> Result<Self, PrefixedHexError> {
let checked = parse::hex_remove_prefix(s)?;
Ok(U256::from_hex_internal(checked)?)
}
/// Constructs a `U256` from an unprefixed hex string.
/// Constructs a new `U256` from an unprefixed hex string.
fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError> {
let checked = parse::hex_check_unprefixed(s)?;
Ok(U256::from_hex_internal(checked)?)
@ -496,7 +496,7 @@ impl U256 {
Ok(U256(high, low))
}
/// Constructs `U256` from a big-endian array of `u8`s.
/// Constructs a new `U256` from a big-endian array of `u8`s.
#[cfg_attr(all(test, mutate), mutate)]
fn from_be_bytes(a: [u8; 32]) -> U256 {
let (high, low) = split_in_half(a);
@ -505,7 +505,7 @@ impl U256 {
U256(big, little)
}
/// Constructs a `U256` from a little-endian array of `u8`s.
/// Constructs a new `U256` from a little-endian array of `u8`s.
#[cfg_attr(all(test, mutate), mutate)]
fn from_le_bytes(a: [u8; 32]) -> U256 {
let (high, low) = split_in_half(a);
@ -1105,7 +1105,7 @@ mod tests {
}
impl U256 {
/// Constructs a U256 from a big-endian array of u64's
/// Constructs a new U256 from a big-endian array of u64's
fn from_array(a: [u64; 4]) -> Self {
let mut ret = U256::ZERO;
ret.0 = (a[0] as u128) << 64 ^ (a[1] as u128);

View File

@ -229,7 +229,7 @@ impl PsbtSighashType {
}
}
/// Constructs a [`PsbtSighashType`] from a raw `u32`.
/// Constructs a new [`PsbtSighashType`] from a raw `u32`.
///
/// Allows construction of a non-standard or non-valid sighash flag
/// ([`EcdsaSighashType`], [`TapSighashType`] respectively).

View File

@ -103,7 +103,7 @@ impl Psbt {
Ok(())
}
/// Constructs a PSBT from an unsigned transaction.
/// Constructs a new PSBT from an unsigned transaction.
///
/// # Errors
///

View File

@ -172,7 +172,7 @@ impl<Subtype> ProprietaryKey<Subtype>
where
Subtype: Copy + From<u64> + Into<u64>,
{
/// Constructs full [Key] corresponding to this proprietary key type
/// Constructs a new full [Key] corresponding to this proprietary key type
pub fn to_key(&self) -> Key { Key { type_value: 0xFC, key_data: serialize(self) } }
}
@ -182,7 +182,7 @@ where
{
type Error = Error;
/// Constructs a [`ProprietaryKey`] from a [`Key`].
/// Constructs a new [`ProprietaryKey`] from a [`Key`].
///
/// # Errors
///

View File

@ -92,7 +92,7 @@ mod message_signing {
}
impl MessageSignature {
/// Construct a new [MessageSignature].
/// Constructs a new [MessageSignature].
pub fn new(signature: RecoverableSignature, compressed: bool) -> MessageSignature {
MessageSignature { signature, compressed }
}
@ -106,7 +106,7 @@ mod message_signing {
serialized
}
/// Constructs a `MessageSignature` from a fixed-length array.
/// Constructs a new `MessageSignature` from a fixed-length array.
pub fn from_byte_array(bytes: &[u8; 65]) -> Result<MessageSignature, secp256k1::Error> {
// We just check this here so we can safely subtract further.
if bytes[0] < 27 {
@ -119,7 +119,7 @@ mod message_signing {
})
}
/// Construct a `MessageSignature` from a byte slice.
/// Constructs a new `MessageSignature` from a byte slice.
#[deprecated(since = "TBD", note = "use `from_byte_array` instead")]
pub fn from_slice(bytes: &[u8]) -> Result<MessageSignature, MessageSignatureError> {
let byte_array: [u8; 65] =

View File

@ -63,7 +63,7 @@ impl TaprootMerkleBranch {
}
}
/// Constructs a Merkle proof from list of hashes.
/// Constructs a new Merkle proof from list of hashes.
///
/// # Errors
///
@ -121,7 +121,7 @@ macro_rules! impl_try_from {
impl TryFrom<$from> for TaprootMerkleBranch {
type Error = InvalidMerkleTreeDepthError;
/// Constructs a Merkle proof from list of hashes.
/// Constructs a new Merkle proof from list of hashes.
///
/// # Errors
///

View File

@ -282,7 +282,7 @@ impl TaprootSpendInfo {
info
}
/// Constructs a [`ControlBlock`] for particular script with the given version.
/// Constructs a new [`ControlBlock`] for particular script with the given version.
///
/// # Returns
///
@ -501,7 +501,7 @@ impl TaprootBuilder {
self.branch.iter().flatten().any(|node| node.has_hidden_nodes)
}
/// Constructs a [`TaprootSpendInfo`] with the given internal key.
/// Constructs a new [`TaprootSpendInfo`] with the given internal key.
///
/// Returns the unmodified builder as Err if the builder is not finalizable.
/// See also [`TaprootBuilder::is_finalizable`]
@ -702,7 +702,7 @@ impl TapTree {
impl TryFrom<TaprootBuilder> for TapTree {
type Error = IncompleteBuilderError;
/// Constructs [`TapTree`] from a [`TaprootBuilder`] if it is complete binary tree.
/// Constructs a new [`TapTree`] from a [`TaprootBuilder`] if it is complete binary tree.
///
/// # Returns
///
@ -714,7 +714,7 @@ impl TryFrom<TaprootBuilder> for TapTree {
impl TryFrom<NodeInfo> for TapTree {
type Error = HiddenNodesError;
/// Constructs [`TapTree`] from a [`NodeInfo`] if it is complete binary tree.
/// Constructs a new [`TapTree`] from a [`NodeInfo`] if it is complete binary tree.
///
/// # Returns
///
@ -971,12 +971,12 @@ pub struct LeafNode {
}
impl LeafNode {
/// Constructs an new [`ScriptLeaf`] from `script` and `ver` and no Merkle branch.
/// Constructs a new [`ScriptLeaf`] from `script` and `ver` and no Merkle branch.
pub fn new_script(script: ScriptBuf, ver: LeafVersion) -> Self {
Self { leaf: TapLeaf::Script(script, ver), merkle_branch: Default::default() }
}
/// Constructs an new [`ScriptLeaf`] from `hash` and no Merkle branch.
/// Constructs a new [`ScriptLeaf`] from `hash` and no Merkle branch.
pub fn new_hidden(hash: TapNodeHash) -> Self {
Self { leaf: TapLeaf::Hidden(hash), merkle_branch: Default::default() }
}
@ -1213,7 +1213,7 @@ pub enum LeafVersion {
}
impl LeafVersion {
/// Constructs a [`LeafVersion`] from consensus byte representation.
/// Constructs a new [`LeafVersion`] from consensus byte representation.
///
/// # Errors
///

View File

@ -131,7 +131,7 @@ impl<'a> TryFrom<&'a SerializedSignature> for Signature {
}
impl SerializedSignature {
/// Constructs `SerializedSignature` from data and length.
/// Constructs new `SerializedSignature` from data and length.
///
/// # Panics
///
@ -159,7 +159,7 @@ impl SerializedSignature {
Signature::from_slice(self)
}
/// Construct a SerializedSignature from a Signature.
/// Constructs a new SerializedSignature from a Signature.
/// (this serializes it)
#[inline]
pub fn from_signature(sig: Signature) -> SerializedSignature { sig.serialize() }

View File

@ -18,7 +18,7 @@ const CHACHA_BLOCKSIZE: usize = 64;
pub struct Key([u8; 32]);
impl Key {
/// Construct a new key.
/// Constructs a new key.
pub const fn new(key: [u8; 32]) -> Self { Key(key) }
}
@ -27,7 +27,7 @@ impl Key {
pub struct Nonce([u8; 12]);
impl Nonce {
/// Construct a new nonce.
/// Constructs a new nonce.
pub const fn new(nonce: [u8; 12]) -> Self { Nonce(nonce) }
}

View File

@ -105,7 +105,7 @@ macro_rules! hash_type_no_default {
impl Hash {
const fn internal_new(arr: [u8; $bits / 8]) -> Self { Hash(arr) }
/// Constructs a hash from the underlying byte array.
/// Constructs a new hash from the underlying byte array.
pub const fn from_byte_array(bytes: [u8; $bits / 8]) -> Self {
Self::internal_new(bytes)
}

View File

@ -279,7 +279,7 @@ pub trait Hash:
/// For some reason Satoshi decided this should be true for `Sha256dHash`, so here we are.
const DISPLAY_BACKWARD: bool = false;
/// Constructs a hash from the underlying byte array.
/// Constructs a new hash from the underlying byte array.
fn from_byte_array(bytes: Self::Bytes) -> Self;
/// Copies a byte slice into a hash object.

View File

@ -137,7 +137,7 @@ macro_rules! hash_newtype {
#[allow(unused)] // Private wrapper types may not need all functions.
impl $newtype {
/// Constructs a hash from the underlying byte array.
/// Constructs a new hash from the underlying byte array.
pub const fn from_byte_array(bytes: <$hash as $crate::Hash>::Bytes) -> Self {
$newtype(<$hash>::from_byte_array(bytes))
}

View File

@ -198,7 +198,7 @@ impl Midstate {
/// Deconstructs the [`Midstate`], returning the underlying byte array and number of bytes hashed.
pub const fn to_parts(self) -> ([u8; 32], u64) { (self.bytes, self.bytes_hashed) }
/// Constructs midstate for tagged hashes.
/// Constructs a new midstate for tagged hashes.
///
/// Warning: this function is inefficient. It should be only used in `const` context.
///

View File

@ -25,7 +25,7 @@ where
{
const fn internal_new(arr: [u8; 32]) -> Self { Hash(arr, PhantomData) }
/// Constructs a hash from the underlying byte array.
/// Constructs a new hash from the underlying byte array.
pub const fn from_byte_array(bytes: [u8; 32]) -> Self { Self::internal_new(bytes) }
/// Zero cost conversion between a fixed length byte array shared reference and

View File

@ -86,7 +86,7 @@ impl HashEngine {
ret
}
/// Constructs a hash engine suitable for use constructing a `sha512_256::HashEngine`.
/// Constructs a new hash engine suitable for use constructing a `sha512_256::HashEngine`.
#[rustfmt::skip]
pub(crate) const fn sha512_256() -> Self {
HashEngine {
@ -99,7 +99,7 @@ impl HashEngine {
}
}
/// Constructs a hash engine suitable for constructing `sha384::HashEngine`.
/// Constructs a new hash engine suitable for constructing a `sha384::HashEngine`.
#[rustfmt::skip]
pub(crate) const fn sha384() -> Self {
HashEngine {

View File

@ -209,7 +209,7 @@ impl Hash {
/// Returns the (little endian) 64-bit integer representation of the hash value.
pub fn to_u64(self) -> u64 { u64::from_le_bytes(self.0) }
/// Constructs a hash from its (little endian) 64-bit integer representation.
/// Constructs a new hash from its (little endian) 64-bit integer representation.
pub fn from_u64(hash: u64) -> Hash { Hash(hash.to_le_bytes()) }
}

View File

@ -25,7 +25,7 @@ mod safety_boundary {
/// Constructs an empty `ArrayVec`.
pub const fn new() -> Self { Self { len: 0, data: [MaybeUninit::uninit(); CAP] } }
/// Constructs an `ArrayVec` initialized with the contets of `slice`.
/// Constructs a new `ArrayVec` initialized with the contets of `slice`.
///
/// # Panics
///

View File

@ -25,7 +25,7 @@ macro_rules! parse_error_type {
}
impl $name {
/// Constructs `Self`.
/// Constructs a new `Self`.
fn new<T: Into<$crate::error::InputString>>(input: T, source: $source) -> Self {
$name {
input: input.into(),

View File

@ -58,7 +58,7 @@ pub trait Read {
Ok(())
}
/// Constructs an adapter which will read at most `limit` bytes.
/// Constructs a new adapter which will read at most `limit` bytes.
#[inline]
fn take(&mut self, limit: u64) -> Take<Self> { Take { reader: self, remaining: limit } }
@ -195,7 +195,7 @@ pub struct Cursor<T> {
}
impl<T: AsRef<[u8]>> Cursor<T> {
/// Constructs a `Cursor` by wrapping `inner`.
/// Constructs a new `Cursor` by wrapping `inner`.
#[inline]
pub fn new(inner: T) -> Self { Cursor { inner, pos: 0 } }

View File

@ -120,7 +120,7 @@ impl Version {
/// The value has the top three bits `001` which enables the use of version bits to signal for soft forks.
const USE_VERSION_BITS: u32 = 0x2000_0000;
/// Constructs a [`Version`] from a signed 32 bit integer value.
/// Constructs a new [`Version`] from a signed 32 bit integer value.
///
/// This is the data type used in consensus code in Bitcoin Core.
#[inline]

View File

@ -92,19 +92,19 @@ impl LockTime {
/// The number of bytes that the locktime contributes to the size of a transaction.
pub const SIZE: usize = 4; // Serialized length of a u32.
/// Constructs a `LockTime` from a prefixed hex string.
/// Constructs a new `LockTime` from a prefixed hex string.
pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError> {
let lock_time = parse::hex_u32_prefixed(s)?;
Ok(Self::from_consensus(lock_time))
}
/// Constructs a `LockTime` from an unprefixed hex string.
/// Constructs a new `LockTime` from an unprefixed hex string.
pub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError> {
let lock_time = parse::hex_u32_unprefixed(s)?;
Ok(Self::from_consensus(lock_time))
}
/// Constructs a `LockTime` from an nLockTime value or the argument to OP_CHEKCLOCKTIMEVERIFY.
/// Constructs a new `LockTime` from an nLockTime value or the argument to OP_CHEKCLOCKTIMEVERIFY.
///
/// # Examples
///
@ -124,7 +124,7 @@ impl LockTime {
}
}
/// Constructs a `LockTime` from `n`, expecting `n` to be a valid block height.
/// Constructs a new `LockTime` from `n`, expecting `n` to be a valid block height.
///
/// # Note
///
@ -147,7 +147,7 @@ impl LockTime {
Ok(LockTime::Blocks(height))
}
/// Constructs a `LockTime` from `n`, expecting `n` to be a valid block time.
/// Constructs a new `LockTime` from `n`, expecting `n` to be a valid block time.
///
/// # Note
///

View File

@ -52,7 +52,7 @@ impl LockTime {
/// The number of bytes that the locktime contributes to the size of a transaction.
pub const SIZE: usize = 4; // Serialized length of a u32.
/// Constructs a `LockTime` from an nSequence value or the argument to OP_CHECKSEQUENCEVERIFY.
/// Constructs a new `LockTime` from an nSequence value or the argument to OP_CHECKSEQUENCEVERIFY.
///
/// This method will **not** round-trip with [`Self::to_consensus_u32`], because relative
/// locktimes only use some bits of the underlying `u32` value and discard the rest. If
@ -88,7 +88,7 @@ impl LockTime {
}
}
/// Constructs a `LockTime` from the sequence number of a Bitcoin input.
/// Constructs a new `LockTime` from the sequence number of a Bitcoin input.
///
/// This method will **not** round-trip with [`Self::to_sequence`]. See the
/// docs for [`Self::from_consensus`] for more information.
@ -101,11 +101,11 @@ impl LockTime {
#[inline]
pub fn to_sequence(&self) -> Sequence { Sequence::from_consensus(self.to_consensus_u32()) }
/// Constructs a `LockTime` from `n`, expecting `n` to be a 16-bit count of blocks.
/// Constructs a new `LockTime` from `n`, expecting `n` to be a 16-bit count of blocks.
#[inline]
pub const fn from_height(n: u16) -> Self { LockTime::Blocks(Height::from_height(n)) }
/// Constructs a `LockTime` from `n`, expecting `n` to be a count of 512-second intervals.
/// Constructs a new `LockTime` from `n`, expecting `n` to be a count of 512-second intervals.
///
/// This function is a little awkward to use, and users may wish to instead use
/// [`Self::from_seconds_floor`] or [`Self::from_seconds_ceil`].
@ -114,7 +114,7 @@ impl LockTime {
LockTime::Time(Time::from_512_second_intervals(intervals))
}
/// Construct a [`LockTime`] from seconds, converting the seconds into 512 second interval
/// Construct a new [`LockTime`] from seconds, converting the seconds into 512 second interval
/// with truncating division.
///
/// # Errors
@ -128,7 +128,7 @@ impl LockTime {
}
}
/// Construct a [`LockTime`] from seconds, converting the seconds into 512 second interval
/// Construct a new [`LockTime`] from seconds, converting the seconds into 512 second interval
/// with ceiling division.
///
/// # Errors

View File

@ -495,7 +495,7 @@ macro_rules! ordinary_opcode {
}
}
/// Try to construct a [`Ordinary`] from an [`Opcode`].
/// Constructs a new [`Ordinary`] from an [`Opcode`].
pub fn from_opcode(b: Opcode) -> Option<Self> {
match b {
$( $op => { Some(Ordinary::$op) } ),*

View File

@ -23,7 +23,7 @@ use core::fmt;
pub struct CompactTarget(u32);
impl CompactTarget {
/// Constructs a [`CompactTarget`] from a consensus encoded `u32`.
/// Constructs a new [`CompactTarget`] from a consensus encoded `u32`.
pub fn from_consensus(bits: u32) -> Self { Self(bits) }
/// Returns the consensus encoded `u32` representation of this [`CompactTarget`].

View File

@ -126,25 +126,25 @@ impl Sequence {
self.is_relative_lock_time() & (self.0 & Sequence::LOCK_TYPE_MASK > 0)
}
/// Constructs a `Sequence` from a prefixed hex string.
/// Constructs a new `Sequence` from a prefixed hex string.
#[cfg(feature = "alloc")]
pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError> {
let lock_time = parse::hex_u32_prefixed(s)?;
Ok(Self::from_consensus(lock_time))
}
/// Constructs a `Sequence` from an unprefixed hex string.
/// Constructs a new `Sequence` from an unprefixed hex string.
#[cfg(feature = "alloc")]
pub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError> {
let lock_time = parse::hex_u32_unprefixed(s)?;
Ok(Self::from_consensus(lock_time))
}
/// Constructs a relative lock-time using block height.
/// Constructs a new relative lock-time using block height.
#[inline]
pub fn from_height(height: u16) -> Self { Sequence(u32::from(height)) }
/// Constructs a relative lock-time using time intervals where each interval is equivalent
/// Constructs a new relative lock-time using time intervals where each interval is equivalent
/// to 512 seconds.
///
/// Encoding finer granularity of time for relative lock-times is not supported in Bitcoin
@ -153,7 +153,7 @@ impl Sequence {
Sequence(u32::from(intervals) | Sequence::LOCK_TYPE_MASK)
}
/// Constructs a relative lock-time from seconds, converting the seconds into 512 second
/// Constructs a new relative lock-time from seconds, converting the seconds into 512 second
/// interval with floor division.
///
/// Will return an error if the input cannot be encoded in 16 bits.
@ -167,7 +167,7 @@ impl Sequence {
}
}
/// Constructs a relative lock-time from seconds, converting the seconds into 512 second
/// Constructs a new relative lock-time from seconds, converting the seconds into 512 second
/// interval with ceiling division.
///
/// Will return an error if the input cannot be encoded in 16 bits.
@ -181,7 +181,7 @@ impl Sequence {
}
}
/// Constructs a sequence from a u32 value.
/// Constructs a new sequence from a u32 value.
#[inline]
pub fn from_consensus(n: u32) -> Self { Sequence(n) }
@ -189,7 +189,7 @@ impl Sequence {
#[inline]
pub fn to_consensus_u32(self) -> u32 { self.0 }
/// Constructs a [`relative::LockTime`] from this [`Sequence`] number.
/// Constructs a new [`relative::LockTime`] from this [`Sequence`] number.
#[inline]
#[cfg(feature = "alloc")]
pub fn to_relative_lock_time(&self) -> Option<relative::LockTime> {

View File

@ -72,7 +72,7 @@ impl Witness {
Witness { content, witness_elements, indices_start }
}
/// Constructs a [`Witness`] object from a slice of bytes slices where each slice is a witness item.
/// Constructs a new [`Witness`] object from a slice of bytes slices where each slice is a witness item.
pub fn from_slice<T: AsRef<[u8]>>(slice: &[T]) -> Self {
let witness_elements = slice.len();
let index_size = witness_elements * 4;

View File

@ -46,7 +46,7 @@ impl SignedAmount {
/// The maximum value of an amount.
pub const MAX: SignedAmount = SignedAmount(i64::MAX);
/// Constructs a [`SignedAmount`] with satoshi precision and the given number of satoshis.
/// Constructs a new [`SignedAmount`] with satoshi precision and the given number of satoshis.
pub const fn from_sat(satoshi: i64) -> SignedAmount { SignedAmount(satoshi) }
/// Gets the number of satoshis in this [`SignedAmount`].
@ -154,7 +154,7 @@ impl SignedAmount {
SignedAmount::from_str_in(&value.to_string(), denom)
}
/// Constructs an object that implements [`fmt::Display`] using specified denomination.
/// Constructs a new object that implements [`fmt::Display`] using specified denomination.
pub fn display_in(self, denomination: Denomination) -> Display {
Display {
sats_abs: self.unsigned_abs().to_sat(),
@ -163,7 +163,7 @@ impl SignedAmount {
}
}
/// Constructs an object that implements [`fmt::Display`] dynamically selecting denomination.
/// Constructs a new object that implements [`fmt::Display`] dynamically selecting denomination.
///
/// This will use BTC for values greater than or equal to 1 BTC and satoshis otherwise. To
/// avoid confusion the denomination is always shown.

View File

@ -56,7 +56,7 @@ impl Amount {
/// The number of bytes that an amount contributes to the size of a transaction.
pub const SIZE: usize = 8; // Serialized length of a u64.
/// Constructs an [`Amount`] with satoshi precision and the given number of satoshis.
/// Constructs a new [`Amount`] with satoshi precision and the given number of satoshis.
pub const fn from_sat(satoshi: u64) -> Amount { Amount(satoshi) }
/// Gets the number of satoshis in this [`Amount`].
@ -160,7 +160,7 @@ impl Amount {
Amount::from_str_in(&value.to_string(), denom)
}
/// Constructs an object that implements [`fmt::Display`] using specified denomination.
/// Constructs a new object that implements [`fmt::Display`] using specified denomination.
pub fn display_in(self, denomination: Denomination) -> Display {
Display {
sats_abs: self.to_sat(),
@ -169,7 +169,7 @@ impl Amount {
}
}
/// Constructs an object that implements [`fmt::Display`] dynamically selecting denomination.
/// Constructs a new object that implements [`fmt::Display`] dynamically selecting denomination.
///
/// This will use BTC for values greater than or equal to 1 BTC and satoshis otherwise. To
/// avoid confusion the denomination is always shown.

View File

@ -41,7 +41,7 @@ impl BlockHeight {
/// The maximum block height.
pub const MAX: Self = BlockHeight(u32::MAX);
/// Constructs a block height from a `u32`.
/// Constructs a new block height from a `u32`.
// Because From<u32> is not const.
pub const fn from_u32(inner: u32) -> Self { Self(inner) }
@ -108,7 +108,7 @@ impl BlockInterval {
/// The maximum block interval.
pub const MAX: Self = BlockInterval(u32::MAX);
/// Constructs a block interval from a `u32`.
/// Constructs a new block interval from a `u32`.
// Because From<u32> is not const.
pub const fn from_u32(inner: u32) -> Self { Self(inner) }

View File

@ -44,10 +44,10 @@ impl FeeRate {
/// Fee rate used to compute dust amount.
pub const DUST: FeeRate = FeeRate::from_sat_per_vb_unchecked(3);
/// Constructs [`FeeRate`] from satoshis per 1000 weight units.
/// Constructs a new [`FeeRate`] from satoshis per 1000 weight units.
pub const fn from_sat_per_kwu(sat_kwu: u64) -> Self { FeeRate(sat_kwu) }
/// Constructs [`FeeRate`] from satoshis per virtual bytes.
/// Constructs a new [`FeeRate`] from satoshis per virtual bytes.
///
/// # Errors
///
@ -59,7 +59,7 @@ impl FeeRate {
Some(FeeRate(sat_vb.checked_mul(1000 / 4)?))
}
/// Constructs [`FeeRate`] from satoshis per virtual bytes without overflow check.
/// Constructs a new [`FeeRate`] from satoshis per virtual bytes without overflow check.
pub const fn from_sat_per_vb_unchecked(sat_vb: u64) -> Self { FeeRate(sat_vb * (1000 / 4)) }
/// Returns raw fee rate.

View File

@ -35,7 +35,7 @@ impl Height {
/// The maximum absolute block height.
pub const MAX: Self = Height(LOCK_TIME_THRESHOLD - 1);
/// Constructs a [`Height`] from a hex string.
/// Constructs a new [`Height`] from a hex string.
///
/// The input string may or may not contain a typical hex prefix e.g., `0x`.
pub fn from_hex(s: &str) -> Result<Self, ParseHeightError> {
@ -133,7 +133,7 @@ impl Time {
/// The maximum absolute block time (Sun Feb 07 2106 06:28:15 GMT+0000).
pub const MAX: Self = Time(u32::MAX);
/// Constructs a [`Time`] from a hex string.
/// Constructs a new [`Time`] from a hex string.
///
/// The input string may or may not contain a typical hex prefix e.g., `0x`.
pub fn from_hex(s: &str) -> Result<Self, ParseTimeError> { parse_hex(s, Self::from_consensus) }
@ -256,10 +256,10 @@ pub struct ConversionError {
}
impl ConversionError {
/// Constructs a `ConversionError` from an invalid `n` when expecting a height value.
/// Constructs a new `ConversionError` from an invalid `n` when expecting a height value.
const fn invalid_height(n: u32) -> Self { Self { unit: LockTimeUnit::Blocks, input: n } }
/// Constructs a `ConversionError` from an invalid `n` when expecting a time value.
/// Constructs a new `ConversionError` from an invalid `n` when expecting a time value.
const fn invalid_time(n: u32) -> Self { Self { unit: LockTimeUnit::Seconds, input: n } }
}

View File

@ -22,7 +22,7 @@ impl Height {
/// The maximum relative block height.
pub const MAX: Self = Height(u16::MAX);
/// Construct a [`Height`] using a count of blocks.
/// Constructs a new [`Height`] using a count of blocks.
#[inline]
pub const fn from_height(blocks: u16) -> Self { Height(blocks) }
@ -66,13 +66,13 @@ impl Time {
/// The maximum relative block time (33,554,432 seconds or approx 388 days).
pub const MAX: Self = Time(u16::MAX);
/// Constructs a [`Time`] using time intervals where each interval is equivalent to 512 seconds.
/// Constructs a new [`Time`] using time intervals where each interval is equivalent to 512 seconds.
///
/// Encoding finer granularity of time for relative lock-times is not supported in Bitcoin.
#[inline]
pub const fn from_512_second_intervals(intervals: u16) -> Self { Time(intervals) }
/// Constructs a [`Time`] from seconds, converting the seconds into 512 second interval with
/// Constructs a new [`Time`] from seconds, converting the seconds into 512 second interval with
/// truncating division.
///
/// # Errors
@ -89,7 +89,7 @@ impl Time {
}
}
/// Constructs a [`Time`] from seconds, converting the seconds into 512 second intervals with
/// Constructs a new [`Time`] from seconds, converting the seconds into 512 second intervals with
/// ceiling division.
///
/// # Errors

View File

@ -378,7 +378,7 @@ pub struct MissingPrefixError {
}
impl MissingPrefixError {
/// Constructs an error from the string with the missing prefix.
/// Constructs a new error from the string with the missing prefix.
pub(crate) fn new(hex: &str) -> Self { Self { hex: hex.into() } }
}
@ -398,7 +398,7 @@ pub struct ContainsPrefixError {
}
impl ContainsPrefixError {
/// Constructs an error from the string that contains the prefix.
/// Constructs a new error from the string that contains the prefix.
pub(crate) fn new(hex: &str) -> Self { Self { hex: hex.into() } }
}

View File

@ -45,21 +45,21 @@ impl Weight {
/// The minimum transaction weight for a valid serialized transaction.
pub const MIN_TRANSACTION: Weight = Weight(Self::WITNESS_SCALE_FACTOR * 60);
/// Directly constructs [`Weight`] from weight units.
/// Constructs a new [`Weight`] from weight units.
pub const fn from_wu(wu: u64) -> Self { Weight(wu) }
/// Directly constructs [`Weight`] from usize weight units.
/// Constructs a new [`Weight`] from usize weight units.
pub const fn from_wu_usize(wu: usize) -> Self { Weight(wu as u64) }
/// Constructs [`Weight`] from kilo weight units returning [`None`] if an overflow occurred.
/// Constructs a new [`Weight`] from kilo weight units returning [`None`] if an overflow occurred.
pub fn from_kwu(wu: u64) -> Option<Self> { wu.checked_mul(1000).map(Weight) }
/// Constructs [`Weight`] from virtual bytes, returning [`None`] if an overflow occurred.
/// Constructs a new [`Weight`] from virtual bytes, returning [`None`] if an overflow occurred.
pub fn from_vb(vb: u64) -> Option<Self> {
vb.checked_mul(Self::WITNESS_SCALE_FACTOR).map(Weight::from_wu)
}
/// Constructs [`Weight`] from virtual bytes panicking if an overflow occurred.
/// Constructs a new [`Weight`] from virtual bytes panicking if an overflow occurred.
///
/// # Panics
///
@ -71,13 +71,13 @@ impl Weight {
}
}
/// Constructs [`Weight`] from virtual bytes without an overflow check.
/// Constructs a new [`Weight`] from virtual bytes without an overflow check.
pub const fn from_vb_unchecked(vb: u64) -> Self { Weight::from_wu(vb * 4) }
/// Constructs [`Weight`] from witness size.
/// Constructs a new [`Weight`] from witness size.
pub const fn from_witness_data_size(witness_size: u64) -> Self { Weight(witness_size) }
/// Constructs [`Weight`] from non-witness size.
/// Constructs a new [`Weight`] from non-witness size.
pub const fn from_non_witness_data_size(non_witness_size: u64) -> Self {
Weight(non_witness_size * Self::WITNESS_SCALE_FACTOR)
}