Replace `creates` with `constructs`
In functions that act like constructors there is a mixture of the usage of `creates` and `constructs`. Replace all occurrences of `creates` with `constructs` in the first line of docs of constructor like functions.
This commit is contained in:
parent
3b0cb0e87d
commit
27f94d5540
|
@ -108,7 +108,7 @@ fn receivers_address() -> Address {
|
|||
.expect("valid address for mainnet")
|
||||
}
|
||||
|
||||
/// Creates a p2wpkh output locked to the key associated with `wpkh`.
|
||||
/// Constructs a 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
|
||||
|
|
|
@ -105,7 +105,7 @@ fn receivers_address() -> Address {
|
|||
.expect("valid address for mainnet")
|
||||
}
|
||||
|
||||
/// Creates a p2wpkh output locked to the key associated with `wpkh`.
|
||||
/// Constructs a 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
|
||||
|
|
|
@ -202,7 +202,7 @@ pub enum KnownHrp {
|
|||
}
|
||||
|
||||
impl KnownHrp {
|
||||
/// Creates a `KnownHrp` from `network`.
|
||||
/// Constructs a `KnownHrp` from `network`.
|
||||
fn from_network(network: Network) -> Self {
|
||||
use Network::*;
|
||||
|
||||
|
@ -213,7 +213,7 @@ impl KnownHrp {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a `KnownHrp` from a [`bech32::Hrp`].
|
||||
/// Constructs a `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 {
|
||||
/// Creates a pay to (compressed) public key hash address from a public key.
|
||||
/// Constructs a 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)
|
||||
}
|
||||
|
||||
/// Creates a pay to script hash P2SH address from a script.
|
||||
/// Constructs a 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))
|
||||
}
|
||||
|
||||
/// Creates a pay to script hash P2SH address from a script hash.
|
||||
/// Constructs a 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)
|
||||
}
|
||||
|
||||
/// Creates a witness pay to public key address from a public key.
|
||||
/// Constructs a 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)
|
||||
}
|
||||
|
||||
/// Creates a pay to script address that embeds a witness pay to public key.
|
||||
/// Constructs a 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)
|
||||
}
|
||||
|
||||
/// Creates a witness pay to script hash address.
|
||||
/// Constructs a 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))
|
||||
}
|
||||
|
||||
/// Creates a witness pay to script hash address.
|
||||
/// Constructs a 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)
|
||||
}
|
||||
|
||||
/// Creates a pay to script address that embeds a witness pay to script hash address.
|
||||
/// Constructs a 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))
|
||||
}
|
||||
|
||||
/// Creates a pay to Taproot address from an untweaked key.
|
||||
/// Constructs a 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)
|
||||
}
|
||||
|
||||
/// Creates a pay to Taproot address from a pre-tweaked output key.
|
||||
/// Constructs a 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)
|
||||
}
|
||||
|
||||
/// Creates an address from an arbitrary witness program.
|
||||
/// Constructs an 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.
|
||||
|
@ -608,7 +608,7 @@ impl Address {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a URI string *bitcoin:address* optimized to be encoded in QR codes.
|
||||
/// Constructs a 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.
|
||||
|
|
|
@ -192,7 +192,7 @@ impl Encodable for HeaderAndShortIds {
|
|||
}
|
||||
|
||||
impl HeaderAndShortIds {
|
||||
/// Creates a new [`HeaderAndShortIds`] from a full block.
|
||||
/// Constructs a new [`HeaderAndShortIds`] from a full block.
|
||||
///
|
||||
/// The version number must be either 1 or 2.
|
||||
///
|
||||
|
|
|
@ -122,7 +122,7 @@ impl FilterHash {
|
|||
}
|
||||
|
||||
impl BlockFilter {
|
||||
/// Creates a new filter from pre-computed data.
|
||||
/// Constructs a new filter from pre-computed data.
|
||||
pub fn new(content: &[u8]) -> BlockFilter { BlockFilter { content: content.to_vec() } }
|
||||
|
||||
/// Computes a SCRIPT_FILTER that contains spent and output scripts.
|
||||
|
@ -182,7 +182,7 @@ pub struct BlockFilterWriter<'a, W> {
|
|||
}
|
||||
|
||||
impl<'a, W: Write> BlockFilterWriter<'a, W> {
|
||||
/// Creates a new [`BlockFilterWriter`] from `block`.
|
||||
/// Constructs a new [`BlockFilterWriter`] from `block`.
|
||||
pub fn new(writer: &'a mut W, block: &'a Block) -> BlockFilterWriter<'a, W> {
|
||||
let block_hash_as_int = block.block_hash().to_byte_array();
|
||||
let k0 = u64::from_le_bytes(block_hash_as_int[0..8].try_into().expect("8 byte slice"));
|
||||
|
@ -237,7 +237,7 @@ pub struct BlockFilterReader {
|
|||
}
|
||||
|
||||
impl BlockFilterReader {
|
||||
/// Creates a new [`BlockFilterReader`] from `block_hash`.
|
||||
/// Constructs a new [`BlockFilterReader`] from `block_hash`.
|
||||
pub fn new(block_hash: BlockHash) -> BlockFilterReader {
|
||||
let block_hash_as_int = block_hash.to_byte_array();
|
||||
let k0 = u64::from_le_bytes(block_hash_as_int[0..8].try_into().expect("8 byte slice"));
|
||||
|
@ -273,7 +273,7 @@ pub struct GcsFilterReader {
|
|||
}
|
||||
|
||||
impl GcsFilterReader {
|
||||
/// Creates a new [`GcsFilterReader`] with specific seed to siphash.
|
||||
/// Constructs a new [`GcsFilterReader`] with specific seed to siphash.
|
||||
pub fn new(k0: u64, k1: u64, m: u64, p: u8) -> GcsFilterReader {
|
||||
GcsFilterReader { filter: GcsFilter::new(k0, k1, p), m }
|
||||
}
|
||||
|
@ -378,7 +378,7 @@ pub struct GcsFilterWriter<'a, W> {
|
|||
}
|
||||
|
||||
impl<'a, W: Write> GcsFilterWriter<'a, W> {
|
||||
/// Creates a new [`GcsFilterWriter`] wrapping a generic writer, with specific seed to siphash.
|
||||
/// Constructs a new [`GcsFilterWriter`] wrapping a generic writer, with specific seed to siphash.
|
||||
pub fn new(writer: &'a mut W, k0: u64, k1: u64, m: u64, p: u8) -> GcsFilterWriter<'a, W> {
|
||||
GcsFilterWriter { filter: GcsFilter::new(k0, k1, p), writer, elements: BTreeSet::new(), m }
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ struct GcsFilter {
|
|||
}
|
||||
|
||||
impl GcsFilter {
|
||||
/// Creates a new [`GcsFilter`].
|
||||
/// Constructs a new [`GcsFilter`].
|
||||
fn new(k0: u64, k1: u64, p: u8) -> GcsFilter { GcsFilter { k0, k1, p } }
|
||||
|
||||
/// Golomb-Rice encodes a number `n` to a bit stream (parameter 2^k).
|
||||
|
@ -476,7 +476,7 @@ pub struct BitStreamReader<'a, R: ?Sized> {
|
|||
}
|
||||
|
||||
impl<'a, R: BufRead + ?Sized> BitStreamReader<'a, R> {
|
||||
/// Creates a new [`BitStreamReader`] that reads bitwise from a given `reader`.
|
||||
/// Constructs a new [`BitStreamReader`] that reads bitwise from a given `reader`.
|
||||
pub fn new(reader: &'a mut R) -> BitStreamReader<'a, R> {
|
||||
BitStreamReader { buffer: [0u8], reader, offset: 8 }
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ pub struct BitStreamWriter<'a, W> {
|
|||
}
|
||||
|
||||
impl<'a, W: Write> BitStreamWriter<'a, W> {
|
||||
/// Creates a new [`BitStreamWriter`] that writes bitwise to a given `writer`.
|
||||
/// Constructs a new [`BitStreamWriter`] that writes bitwise to a given `writer`.
|
||||
pub fn new(writer: &'a mut W) -> BitStreamWriter<'a, W> {
|
||||
BitStreamWriter { buffer: [0u8], writer, offset: 0 }
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ impl ChildNumber {
|
|||
/// Hardened child number with index 1.
|
||||
pub const ONE_HARDENED: Self = ChildNumber::Hardened { index: 1 };
|
||||
|
||||
/// Create a [`Normal`] from an index, returns an error if the index is not within
|
||||
/// Construct a [`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 {
|
|||
}
|
||||
}
|
||||
|
||||
/// Create a [`Hardened`] from an index, returns an error if the index is not within
|
||||
/// Construct a [`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() }
|
||||
|
||||
/// Create a new [DerivationPath] that is a child of this one.
|
||||
/// Construct 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() }
|
||||
|
||||
/// Creates a derivation path from a slice of u32s.
|
||||
/// Constructs a derivation path from a slice of u32s.
|
||||
/// ```
|
||||
/// use bitcoin::bip32::DerivationPath;
|
||||
///
|
||||
|
@ -600,7 +600,7 @@ impl Xpriv {
|
|||
PrivateKey { compressed: true, network: self.network, inner: self.private_key }
|
||||
}
|
||||
|
||||
/// Creates new extended public key from this extended private key.
|
||||
/// Constructs 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)
|
||||
}
|
||||
|
@ -730,13 +730,13 @@ impl Xpriv {
|
|||
}
|
||||
|
||||
impl Xpub {
|
||||
/// Creates extended public key from an extended private key.
|
||||
/// Constructs 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)
|
||||
}
|
||||
|
||||
/// Creates extended public key from an extended private key.
|
||||
/// Constructs 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,
|
||||
|
|
|
@ -28,7 +28,7 @@ crate::internal_macros::define_extension_trait! {
|
|||
#[inline]
|
||||
fn bytes(&self) -> Bytes<'_> { Bytes(self.as_bytes().iter().copied()) }
|
||||
|
||||
/// Creates a new script builder
|
||||
/// Constructs a new script builder
|
||||
fn builder() -> Builder { Builder::new() }
|
||||
|
||||
/// Returns 160-bit hash of the script for P2SH outputs.
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::Sequence;
|
|||
pub struct Builder(ScriptBuf, Option<Opcode>);
|
||||
|
||||
impl Builder {
|
||||
/// Creates a new empty script.
|
||||
/// Constructs a new empty script.
|
||||
#[inline]
|
||||
pub const fn new() -> Self { Builder(ScriptBuf::new(), None) }
|
||||
|
||||
|
@ -137,7 +137,7 @@ impl Default for Builder {
|
|||
fn default() -> Builder { Builder::new() }
|
||||
}
|
||||
|
||||
/// Creates a new builder from an existing vector.
|
||||
/// Constructs a new builder from an existing vector.
|
||||
impl From<Vec<u8>> for Builder {
|
||||
fn from(v: Vec<u8>) -> Builder {
|
||||
let script = ScriptBuf::from(v);
|
||||
|
|
|
@ -220,7 +220,7 @@ impl<'a> InstructionIndices<'a> {
|
|||
#[inline]
|
||||
pub fn as_script(&self) -> &'a Script { self.instructions.as_script() }
|
||||
|
||||
/// Creates `Self` setting `pos` to 0.
|
||||
/// Constructs `Self` setting `pos` to 0.
|
||||
pub(super) fn from_instructions(instructions: Instructions<'a>) -> Self {
|
||||
InstructionIndices { instructions, pos: 0 }
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ hashes::hash_newtype! {
|
|||
impl_asref_push_bytes!(ScriptHash, WScriptHash);
|
||||
|
||||
impl ScriptHash {
|
||||
/// Creates a `ScriptHash` after first checking the script size.
|
||||
/// Constructs a `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())))
|
||||
}
|
||||
|
||||
/// Creates a `ScriptHash` from any script irrespective of script size.
|
||||
/// Constructs a `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 {
|
||||
/// Creates a `WScriptHash` after first checking the script size.
|
||||
/// Constructs a `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())))
|
||||
}
|
||||
|
||||
/// Creates a `WScriptHash` from any script irrespective of script size.
|
||||
/// Constructs a `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 {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates the script code used for spending a P2WPKH output.
|
||||
/// Constructs the script code used for spending a P2WPKH output.
|
||||
///
|
||||
/// The `scriptCode` is described in [BIP143].
|
||||
///
|
||||
|
|
|
@ -18,7 +18,7 @@ pub use primitives::script::ScriptBuf;
|
|||
crate::internal_macros::define_extension_trait! {
|
||||
/// Extension functionality for the [`ScriptBuf`] type.
|
||||
pub trait ScriptBufExt impl for ScriptBuf {
|
||||
/// Creates a new script builder
|
||||
/// Constructs a new script builder
|
||||
fn builder() -> Builder { Builder::new() }
|
||||
|
||||
/// Generates OP_RETURN-type of scriptPubkey for the given data.
|
||||
|
@ -26,7 +26,7 @@ crate::internal_macros::define_extension_trait! {
|
|||
Builder::new().push_opcode(OP_RETURN).push_slice(data).into_script()
|
||||
}
|
||||
|
||||
/// Creates a [`ScriptBuf`] from a hex string.
|
||||
/// Constructs a [`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))
|
||||
|
|
|
@ -45,7 +45,7 @@ mod primitive {
|
|||
pub struct PushBytes([u8]);
|
||||
|
||||
impl PushBytes {
|
||||
/// Creates `&PushBytes` without checking the length.
|
||||
/// Constructs `&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) }
|
||||
}
|
||||
|
||||
/// Creates `&mut PushBytes` without checking the length.
|
||||
/// Constructs `&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 {
|
||||
|
@ -63,7 +63,7 @@ mod primitive {
|
|||
unsafe { &mut *(bytes as *mut [u8] as *mut PushBytes) }
|
||||
}
|
||||
|
||||
/// Creates an empty `&PushBytes`.
|
||||
/// Constructs an empty `&PushBytes`.
|
||||
pub fn empty() -> &'static Self {
|
||||
Self::from_slice_unchecked(&[])
|
||||
}
|
||||
|
@ -200,11 +200,11 @@ mod primitive {
|
|||
pub struct PushBytesBuf(Vec<u8>);
|
||||
|
||||
impl PushBytesBuf {
|
||||
/// Creates a new empty `PushBytesBuf`.
|
||||
/// Constructs a new empty `PushBytesBuf`.
|
||||
#[inline]
|
||||
pub const fn new() -> Self { PushBytesBuf(Vec::new()) }
|
||||
|
||||
/// Creates a new empty `PushBytesBuf` with reserved capacity.
|
||||
/// Constructs a new empty `PushBytesBuf` with reserved capacity.
|
||||
pub fn with_capacity(capacity: usize) -> Self { PushBytesBuf(Vec::with_capacity(capacity)) }
|
||||
|
||||
/// Reserve capacity for `additional_capacity` bytes.
|
||||
|
|
|
@ -38,7 +38,7 @@ pub struct WitnessProgram {
|
|||
}
|
||||
|
||||
impl WitnessProgram {
|
||||
/// Creates a new witness program, copying the content from the given byte slice.
|
||||
/// Constructs a new witness program, copying the content from the given byte slice.
|
||||
pub fn new(version: WitnessVersion, bytes: &[u8]) -> Result<Self, Error> {
|
||||
use Error::*;
|
||||
|
||||
|
@ -56,38 +56,38 @@ impl WitnessProgram {
|
|||
Ok(WitnessProgram { version, program })
|
||||
}
|
||||
|
||||
/// Creates a [`WitnessProgram`] from a 20 byte pubkey hash.
|
||||
/// Constructs a [`WitnessProgram`] from a 20 byte pubkey hash.
|
||||
fn new_p2wpkh(program: [u8; 20]) -> Self {
|
||||
WitnessProgram { version: WitnessVersion::V0, program: ArrayVec::from_slice(&program) }
|
||||
}
|
||||
|
||||
/// Creates a [`WitnessProgram`] from a 32 byte script hash.
|
||||
/// Constructs a [`WitnessProgram`] from a 32 byte script hash.
|
||||
fn new_p2wsh(program: [u8; 32]) -> Self {
|
||||
WitnessProgram { version: WitnessVersion::V0, program: ArrayVec::from_slice(&program) }
|
||||
}
|
||||
|
||||
/// Creates a [`WitnessProgram`] from a 32 byte serialize Taproot xonly pubkey.
|
||||
/// Constructs a [`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) }
|
||||
}
|
||||
|
||||
/// Creates a [`WitnessProgram`] from `pk` for a P2WPKH output.
|
||||
/// Constructs a [`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())
|
||||
}
|
||||
|
||||
/// Creates a [`WitnessProgram`] from `script` for a P2WSH output.
|
||||
/// Constructs a [`WitnessProgram`] from `script` for a P2WSH output.
|
||||
pub fn p2wsh(script: &Script) -> Result<Self, WitnessScriptSizeError> {
|
||||
script.wscript_hash().map(Self::p2wsh_from_hash)
|
||||
}
|
||||
|
||||
/// Creates a [`WitnessProgram`] from `script` for a P2WSH output.
|
||||
/// Constructs a [`WitnessProgram`] from `script` for a P2WSH output.
|
||||
pub fn p2wsh_from_hash(hash: WScriptHash) -> Self {
|
||||
WitnessProgram::new_p2wsh(hash.to_byte_array())
|
||||
}
|
||||
|
||||
/// Creates a pay to Taproot address from an untweaked key.
|
||||
/// Constructs a 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)
|
||||
}
|
||||
|
||||
/// Creates a pay to Taproot address from a pre-tweaked output key.
|
||||
/// Constructs a 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)
|
||||
|
|
|
@ -68,7 +68,7 @@ const SEGWIT_FLAG: u8 = 0x01;
|
|||
crate::internal_macros::define_extension_trait! {
|
||||
/// Extension functionality for the [`OutPoint`] type.
|
||||
pub trait OutPointExt impl for OutPoint {
|
||||
/// Creates a new [`OutPoint`].
|
||||
/// Constructs a new [`OutPoint`].
|
||||
#[inline]
|
||||
#[deprecated(since = "TBD", note = "use struct initialization syntax instead")]
|
||||
#[allow(clippy::new-ret-no-self)]
|
||||
|
@ -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) }
|
||||
|
||||
/// Creates a `TxOut` with given script and the smallest possible `value` that is **not** dust
|
||||
/// Constructs a `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 }
|
||||
}
|
||||
|
||||
/// Creates a `TxOut` with given script and the smallest possible `value` that is **not** dust
|
||||
/// Constructs a `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 {
|
||||
/// Creates a non-standard transaction version.
|
||||
/// Constructs a non-standard transaction version.
|
||||
fn non_standard(version: i32) -> Version { Self(version) }
|
||||
|
||||
/// Returns true if this transaction version number is considered standard.
|
||||
|
|
|
@ -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 {
|
||||
/// Creates a witness required to spend a P2WPKH output.
|
||||
/// Constructs a 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
|
||||
}
|
||||
|
||||
/// Creates a witness required to do a key path spend of a P2TR output.
|
||||
/// Constructs a 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());
|
||||
|
|
|
@ -332,7 +332,7 @@ pub struct CheckedData {
|
|||
}
|
||||
|
||||
impl CheckedData {
|
||||
/// Creates a new `CheckedData` computing the checksum of given data.
|
||||
/// Constructs a new `CheckedData` computing the checksum of given data.
|
||||
pub fn new(data: Vec<u8>) -> Self {
|
||||
let checksum = sha2_checksum(&data);
|
||||
Self { data, checksum }
|
||||
|
|
|
@ -438,7 +438,7 @@ impl PrivateKey {
|
|||
PrivateKey { compressed: false, network: network.into(), inner: key }
|
||||
}
|
||||
|
||||
/// Creates a public key from this private key.
|
||||
/// Constructs a public key from this private key.
|
||||
pub fn public_key<C: secp256k1::Signing>(&self, secp: &Secp256k1<C>) -> PublicKey {
|
||||
PublicKey {
|
||||
compressed: self.compressed,
|
||||
|
@ -845,7 +845,7 @@ impl TweakedPublicKey {
|
|||
TweakedPublicKey(xonly)
|
||||
}
|
||||
|
||||
/// Creates a new [`TweakedPublicKey`] from a [`XOnlyPublicKey`]. No tweak is applied, consider
|
||||
/// Constructs a new [`TweakedPublicKey`] from a [`XOnlyPublicKey`]. No tweak is applied, consider
|
||||
/// calling `tap_tweak` on an [`UntweakedPublicKey`] instead of using this constructor.
|
||||
///
|
||||
/// This method is dangerous and can lead to loss of funds if used incorrectly.
|
||||
|
@ -866,7 +866,7 @@ impl TweakedPublicKey {
|
|||
}
|
||||
|
||||
impl TweakedKeypair {
|
||||
/// Creates a new [`TweakedKeypair`] from a [`Keypair`]. No tweak is applied, consider
|
||||
/// Constructs a new [`TweakedKeypair`] from a [`Keypair`]. No tweak is applied, consider
|
||||
/// calling `tap_tweak` on an [`UntweakedKeypair`] instead of using this constructor.
|
||||
///
|
||||
/// This method is dangerous and can lead to loss of funds if used incorrectly.
|
||||
|
|
|
@ -319,11 +319,11 @@ impl std::error::Error for PrevoutsIndexError {
|
|||
}
|
||||
|
||||
impl<'s> ScriptPath<'s> {
|
||||
/// Creates a new `ScriptPath` structure.
|
||||
/// Constructs a new `ScriptPath` structure.
|
||||
pub fn new(script: &'s Script, leaf_version: LeafVersion) -> Self {
|
||||
ScriptPath { script, leaf_version }
|
||||
}
|
||||
/// Creates a new `ScriptPath` structure using default leaf version value.
|
||||
/// Constructs a new `ScriptPath` structure using default leaf version value.
|
||||
pub fn with_defaults(script: &'s Script) -> Self { Self::new(script, LeafVersion::TapScript) }
|
||||
/// Computes the leaf hash for this `ScriptPath`.
|
||||
pub fn leaf_hash(&self) -> TapLeafHash {
|
||||
|
@ -418,7 +418,7 @@ impl EcdsaSighashType {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a [`EcdsaSighashType`] from a raw `u32`.
|
||||
/// Constructs a [`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 {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a [`EcdsaSighashType`] from a raw `u32`.
|
||||
/// Constructs a [`EcdsaSighashType`] from a raw `u32`.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
|
@ -1156,7 +1156,7 @@ impl<R: BorrowMut<Transaction>> SighashCache<R> {
|
|||
pub struct Annex<'a>(&'a [u8]);
|
||||
|
||||
impl<'a> Annex<'a> {
|
||||
/// Creates a new `Annex` struct checking the first byte is `0x50`.
|
||||
/// Constructs a new `Annex` struct checking the first byte is `0x50`.
|
||||
pub fn new(annex_bytes: &'a [u8]) -> Result<Self, AnnexError> {
|
||||
use AnnexError::*;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ pub(crate) use impl_consensus_encoding;
|
|||
macro_rules! impl_array_newtype_stringify {
|
||||
($t:ident, $len:literal) => {
|
||||
impl $t {
|
||||
/// Creates `Self` from a hex string.
|
||||
/// Constructs `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 {
|
||||
/// Creates `Self` by wrapping `bytes`.
|
||||
/// Constructs `Self` by wrapping `bytes`.
|
||||
#[inline]
|
||||
pub fn from_byte_array(bytes: [u8; $len]) -> Self { Self(bytes) }
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ pub struct MerkleBlock {
|
|||
}
|
||||
|
||||
impl MerkleBlock {
|
||||
/// Create a MerkleBlock from a block, that contains proofs for specific txids.
|
||||
/// Construct a 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();
|
||||
///
|
||||
/// // Create a Merkle block containing a single transaction
|
||||
/// // Construct a 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)
|
||||
}
|
||||
|
||||
/// Create a MerkleBlock from the block's header and txids, that contain proofs for specific txids.
|
||||
/// Construct a 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.
|
||||
|
@ -653,7 +653,7 @@ mod tests {
|
|||
assert_eq!(mb_hex, encode::serialize(&mb).to_lower_hex_string().as_str());
|
||||
}
|
||||
|
||||
/// Create a CMerkleBlock using a list of txids which will be found in the
|
||||
/// Construct a 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);
|
||||
}
|
||||
|
||||
/// Create a CMerkleBlock using a list of txids which will not be found in the given block
|
||||
/// Construct a 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();
|
||||
|
|
|
@ -124,7 +124,7 @@ impl<'de> Deserialize<'de> for Network {
|
|||
}
|
||||
|
||||
impl Network {
|
||||
/// Creates a `Network` from the magic bytes.
|
||||
/// Constructs a `Network` from the magic bytes.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -207,7 +207,7 @@ impl Network {
|
|||
/// ```
|
||||
pub fn chain_hash(self) -> ChainHash { ChainHash::using_genesis_block_const(self) }
|
||||
|
||||
/// Creates a `Network` from the chain hash (genesis block hash).
|
||||
/// Constructs a `Network` from the chain hash (genesis block hash).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
//! }
|
||||
//!
|
||||
//! impl CustomParams {
|
||||
//! /// Creates a new custom params.
|
||||
//! /// Constructs a new custom params.
|
||||
//! pub fn new() -> Self {
|
||||
//! let mut params = Params::new(Network::Signet);
|
||||
//! params.pow_target_spacing = POW_TARGET_SPACING;
|
||||
|
|
|
@ -28,7 +28,7 @@ pub struct Address {
|
|||
const ONION: [u16; 3] = [0xFD87, 0xD87E, 0xEB43];
|
||||
|
||||
impl Address {
|
||||
/// Create an address message for a socket
|
||||
/// Construct an 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()),
|
||||
|
|
|
@ -301,7 +301,7 @@ impl NetworkMessage {
|
|||
}
|
||||
|
||||
impl RawNetworkMessage {
|
||||
/// Creates a [RawNetworkMessage]
|
||||
/// Constructs a [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");
|
||||
|
|
|
@ -228,7 +228,7 @@ impl Magic {
|
|||
/// Bitcoin regtest network magic bytes.
|
||||
pub const REGTEST: Self = Self([0xFA, 0xBF, 0xB5, 0xDA]);
|
||||
|
||||
/// Create network magic from bytes.
|
||||
/// Construct network magic from bytes.
|
||||
pub const fn from_bytes(bytes: [u8; 4]) -> Magic { Magic(bytes) }
|
||||
|
||||
/// Get network magic bytes.
|
||||
|
|
|
@ -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 {
|
||||
/// Creates a `CompactTarget` from a prefixed hex string.
|
||||
/// Constructs a `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))
|
||||
}
|
||||
|
||||
/// Creates a `CompactTarget` from an unprefixed hex string.
|
||||
/// Constructs a `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);
|
||||
|
||||
/// Creates a `U256` from a prefixed hex string.
|
||||
/// Constructs a `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)?)
|
||||
}
|
||||
|
||||
/// Creates a `U256` from an unprefixed hex string.
|
||||
/// Constructs a `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))
|
||||
}
|
||||
|
||||
/// Creates `U256` from a big-endian array of `u8`s.
|
||||
/// Constructs `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)
|
||||
}
|
||||
|
||||
/// Creates a `U256` from a little-endian array of `u8`s.
|
||||
/// Constructs a `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 {
|
||||
/// Creates a U256 from a big-endian array of u64's
|
||||
/// Constructs a 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);
|
||||
|
|
|
@ -229,7 +229,7 @@ impl PsbtSighashType {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a [`PsbtSighashType`] from a raw `u32`.
|
||||
/// Constructs a [`PsbtSighashType`] from a raw `u32`.
|
||||
///
|
||||
/// Allows construction of a non-standard or non-valid sighash flag
|
||||
/// ([`EcdsaSighashType`], [`TapSighashType`] respectively).
|
||||
|
|
|
@ -103,7 +103,7 @@ impl Psbt {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Creates a PSBT from an unsigned transaction.
|
||||
/// Constructs a PSBT from an unsigned transaction.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
|
|
|
@ -92,7 +92,7 @@ mod message_signing {
|
|||
}
|
||||
|
||||
impl MessageSignature {
|
||||
/// Create a new [MessageSignature].
|
||||
/// Construct a new [MessageSignature].
|
||||
pub fn new(signature: RecoverableSignature, compressed: bool) -> MessageSignature {
|
||||
MessageSignature { signature, compressed }
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ mod message_signing {
|
|||
serialized
|
||||
}
|
||||
|
||||
/// Creates a `MessageSignature` from a fixed-length array.
|
||||
/// Constructs a `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 {
|
|||
})
|
||||
}
|
||||
|
||||
/// Create a `MessageSignature` from a byte slice.
|
||||
/// Construct a `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] =
|
||||
|
|
|
@ -63,7 +63,7 @@ impl TaprootMerkleBranch {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a Merkle proof from list of hashes.
|
||||
/// Constructs a Merkle proof from list of hashes.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
|
@ -121,7 +121,7 @@ macro_rules! impl_try_from {
|
|||
impl TryFrom<$from> for TaprootMerkleBranch {
|
||||
type Error = InvalidMerkleTreeDepthError;
|
||||
|
||||
/// Creates a Merkle proof from list of hashes.
|
||||
/// Constructs a Merkle proof from list of hashes.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
|
|
|
@ -34,7 +34,7 @@ pub use primitives::taproot::{
|
|||
crate::internal_macros::define_extension_trait! {
|
||||
/// Extension functionality for the [`TapTweakHash`] type.
|
||||
pub trait TapTweakHashExt impl for TapTweakHash {
|
||||
/// Creates a new BIP341 [`TapTweakHash`] from key and tweak. Produces `H_taptweak(P||R)` where
|
||||
/// Constructs a new BIP341 [`TapTweakHash`] from key and tweak. Produces `H_taptweak(P||R)` where
|
||||
/// `P` is the internal key and `R` is the Merkle root.
|
||||
fn from_key_and_tweak(
|
||||
internal_key: UntweakedPublicKey,
|
||||
|
@ -181,7 +181,7 @@ pub struct TaprootSpendInfo {
|
|||
}
|
||||
|
||||
impl TaprootSpendInfo {
|
||||
/// Creates a new [`TaprootSpendInfo`] from a list of scripts (with default script version) and
|
||||
/// Constructs a new [`TaprootSpendInfo`] from a list of scripts (with default script version) and
|
||||
/// weights of satisfaction for that script.
|
||||
///
|
||||
/// See [`TaprootBuilder::with_huffman_tree`] for more detailed documentation.
|
||||
|
@ -198,7 +198,7 @@ impl TaprootSpendInfo {
|
|||
Ok(builder.finalize(secp, internal_key).expect("Huffman tree is always complete"))
|
||||
}
|
||||
|
||||
/// Creates a new key spend with `internal_key` and `merkle_root`. Provide [`None`] for
|
||||
/// Constructs a new key spend with `internal_key` and `merkle_root`. Provide [`None`] for
|
||||
/// the `merkle_root` if there is no script path.
|
||||
///
|
||||
/// *Note*: As per BIP341
|
||||
|
@ -355,17 +355,17 @@ pub struct TaprootBuilder {
|
|||
}
|
||||
|
||||
impl TaprootBuilder {
|
||||
/// Creates a new instance of [`TaprootBuilder`].
|
||||
/// Constructs a new instance of [`TaprootBuilder`].
|
||||
pub fn new() -> Self { TaprootBuilder { branch: vec![] } }
|
||||
|
||||
/// Creates a new instance of [`TaprootBuilder`] with a capacity hint for `size` elements.
|
||||
/// Constructs a new instance of [`TaprootBuilder`] with a capacity hint for `size` elements.
|
||||
///
|
||||
/// The size here should be maximum depth of the tree.
|
||||
pub fn with_capacity(size: usize) -> Self {
|
||||
TaprootBuilder { branch: Vec::with_capacity(size) }
|
||||
}
|
||||
|
||||
/// Creates a new [`TaprootSpendInfo`] from a list of scripts (with default script version) and
|
||||
/// Constructs a new [`TaprootSpendInfo`] from a list of scripts (with default script version) and
|
||||
/// weights of satisfaction for that script.
|
||||
///
|
||||
/// The weights represent the probability of each branch being taken. If probabilities/weights
|
||||
|
@ -501,7 +501,7 @@ impl TaprootBuilder {
|
|||
self.branch.iter().flatten().any(|node| node.has_hidden_nodes)
|
||||
}
|
||||
|
||||
/// Creates a [`TaprootSpendInfo`] with the given internal key.
|
||||
/// Constructs a [`TaprootSpendInfo`] with the given internal key.
|
||||
///
|
||||
/// Returns the unmodified builder as Err if the builder is not finalizable.
|
||||
/// See also [`TaprootBuilder::is_finalizable`]
|
||||
|
@ -810,12 +810,12 @@ impl core::hash::Hash for NodeInfo {
|
|||
impl Eq for NodeInfo {}
|
||||
|
||||
impl NodeInfo {
|
||||
/// Creates a new [`NodeInfo`] with omitted/hidden info.
|
||||
/// Constructs a new [`NodeInfo`] with omitted/hidden info.
|
||||
pub fn new_hidden_node(hash: TapNodeHash) -> Self {
|
||||
Self { hash, leaves: vec![], has_hidden_nodes: true }
|
||||
}
|
||||
|
||||
/// Creates a new leaf [`NodeInfo`] with given [`ScriptBuf`] and [`LeafVersion`].
|
||||
/// Constructs a new leaf [`NodeInfo`] with given [`ScriptBuf`] and [`LeafVersion`].
|
||||
pub fn new_leaf_with_ver(script: ScriptBuf, ver: LeafVersion) -> Self {
|
||||
Self {
|
||||
hash: TapNodeHash::from_script(&script, ver),
|
||||
|
@ -971,12 +971,12 @@ pub struct LeafNode {
|
|||
}
|
||||
|
||||
impl LeafNode {
|
||||
/// Creates an new [`ScriptLeaf`] from `script` and `ver` and no Merkle branch.
|
||||
/// Constructs an 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() }
|
||||
}
|
||||
|
||||
/// Creates an new [`ScriptLeaf`] from `hash` and no Merkle branch.
|
||||
/// Constructs an 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 {
|
||||
/// Creates a [`LeafVersion`] from consensus byte representation.
|
||||
/// Constructs a [`LeafVersion`] from consensus byte representation.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
|
|
|
@ -131,7 +131,7 @@ impl<'a> TryFrom<&'a SerializedSignature> for Signature {
|
|||
}
|
||||
|
||||
impl SerializedSignature {
|
||||
/// Creates `SerializedSignature` from data and length.
|
||||
/// Constructs `SerializedSignature` from data and length.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
@ -159,7 +159,7 @@ impl SerializedSignature {
|
|||
Signature::from_slice(self)
|
||||
}
|
||||
|
||||
/// Create a SerializedSignature from a Signature.
|
||||
/// Construct a SerializedSignature from a Signature.
|
||||
/// (this serializes it)
|
||||
#[inline]
|
||||
pub fn from_signature(sig: Signature) -> SerializedSignature { sig.serialize() }
|
||||
|
|
|
@ -18,7 +18,7 @@ const CHACHA_BLOCKSIZE: usize = 64;
|
|||
pub struct Key([u8; 32]);
|
||||
|
||||
impl Key {
|
||||
/// Create a new key.
|
||||
/// Construct 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 {
|
||||
/// Create a new nonce.
|
||||
/// Construct a new nonce.
|
||||
pub const fn new(nonce: [u8; 12]) -> Self { Nonce(nonce) }
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ crate::internal_macros::general_hash_type! {
|
|||
pub struct HashEngine(sha256::HashEngine);
|
||||
|
||||
impl HashEngine {
|
||||
/// Creates a new HASH160 hash engine.
|
||||
/// Constructs a new HASH160 hash engine.
|
||||
pub const fn new() -> Self { Self(sha256::HashEngine::new()) }
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ pub struct HashEngine {
|
|||
}
|
||||
|
||||
impl HashEngine {
|
||||
/// Creates a new SHA256 hash engine.
|
||||
/// Constructs a new SHA256 hash engine.
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
h: [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0],
|
||||
|
|
|
@ -42,7 +42,7 @@ pub struct HashEngine {
|
|||
}
|
||||
|
||||
impl HashEngine {
|
||||
/// Creates a new SHA1 hash engine.
|
||||
/// Constructs a new SHA1 hash engine.
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
h: [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0],
|
||||
|
|
|
@ -62,7 +62,7 @@ pub struct HashEngine {
|
|||
}
|
||||
|
||||
impl HashEngine {
|
||||
/// Creates a new SHA256 hash engine.
|
||||
/// Constructs a new SHA256 hash engine.
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
h: [
|
||||
|
@ -74,7 +74,7 @@ impl HashEngine {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a new [`HashEngine`] from a [`Midstate`].
|
||||
/// Constructs a new [`HashEngine`] from a [`Midstate`].
|
||||
///
|
||||
/// Please see docs on [`Midstate`] before using this function.
|
||||
pub fn from_midstate(midstate: Midstate) -> HashEngine {
|
||||
|
@ -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) }
|
||||
|
||||
/// Creates midstate for tagged hashes.
|
||||
/// Constructs midstate for tagged hashes.
|
||||
///
|
||||
/// Warning: this function is inefficient. It should be only used in `const` context.
|
||||
///
|
||||
|
|
|
@ -15,7 +15,7 @@ crate::internal_macros::general_hash_type! {
|
|||
pub struct HashEngine(sha256::HashEngine);
|
||||
|
||||
impl HashEngine {
|
||||
/// Creates a new SHA256d hash engine.
|
||||
/// Constructs a new SHA256d hash engine.
|
||||
pub const fn new() -> Self { Self(sha256::HashEngine::new()) }
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ fn from_engine(e: HashEngine) -> Hash {
|
|||
pub struct HashEngine(sha512::HashEngine);
|
||||
|
||||
impl HashEngine {
|
||||
/// Creates a new SHA384 hash engine.
|
||||
/// Constructs a new SHA384 hash engine.
|
||||
pub const fn new() -> Self { Self(sha512::HashEngine::sha384()) }
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ pub struct HashEngine {
|
|||
}
|
||||
|
||||
impl HashEngine {
|
||||
/// Creates a new SHA512 hash engine.
|
||||
/// Constructs a new SHA512 hash engine.
|
||||
#[rustfmt::skip]
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
|
|
|
@ -31,7 +31,7 @@ fn from_engine(e: HashEngine) -> Hash {
|
|||
pub struct HashEngine(sha512::HashEngine);
|
||||
|
||||
impl HashEngine {
|
||||
/// Creates a new SHA512/256 hash engine.
|
||||
/// Constructs a new SHA512/256 hash engine.
|
||||
pub const fn new() -> Self { Self(sha512::HashEngine::sha512_256()) }
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ pub struct HashEngine {
|
|||
}
|
||||
|
||||
impl HashEngine {
|
||||
/// Creates a new SipHash24 engine with keys.
|
||||
/// Constructs a new SipHash24 engine with keys.
|
||||
#[inline]
|
||||
pub const fn with_keys(k0: u64, k1: u64) -> HashEngine {
|
||||
HashEngine {
|
||||
|
@ -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) }
|
||||
|
||||
/// Creates a hash from its (little endian) 64-bit integer representation.
|
||||
/// Constructs a hash from its (little endian) 64-bit integer representation.
|
||||
pub fn from_u64(hash: u64) -> Hash { Hash(hash.to_le_bytes()) }
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,10 @@ mod safety_boundary {
|
|||
}
|
||||
|
||||
impl<T: Copy, const CAP: usize> ArrayVec<T, CAP> {
|
||||
/// Creates an empty `ArrayVec`.
|
||||
/// Constructs an empty `ArrayVec`.
|
||||
pub const fn new() -> Self { Self { len: 0, data: [MaybeUninit::uninit(); CAP] } }
|
||||
|
||||
/// Creates an `ArrayVec` initialized with the contets of `slice`.
|
||||
/// Constructs an `ArrayVec` initialized with the contets of `slice`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
|
|
@ -25,7 +25,7 @@ macro_rules! parse_error_type {
|
|||
}
|
||||
|
||||
impl $name {
|
||||
/// Creates `Self`.
|
||||
/// Constructs `Self`.
|
||||
fn new<T: Into<$crate::error::InputString>>(input: T, source: $source) -> Self {
|
||||
$name {
|
||||
input: input.into(),
|
||||
|
|
|
@ -18,7 +18,7 @@ pub struct Error {
|
|||
}
|
||||
|
||||
impl Error {
|
||||
/// Creates a new I/O error.
|
||||
/// Constructs a new I/O error.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn new<E>(kind: ErrorKind, error: E) -> Error
|
||||
where
|
||||
|
@ -27,7 +27,7 @@ impl Error {
|
|||
Self { kind, _not_unwind_safe: core::marker::PhantomData, error: Some(error.into()) }
|
||||
}
|
||||
|
||||
/// Creates a new I/O error.
|
||||
/// Constructs a new I/O error.
|
||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||
pub fn new<E: sealed::IntoBoxDynDebug>(kind: ErrorKind, error: E) -> Error {
|
||||
Self { kind, _not_unwind_safe: core::marker::PhantomData, error: Some(error.into()) }
|
||||
|
|
|
@ -58,7 +58,7 @@ pub trait Read {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Creates an adapter which will read at most `limit` bytes.
|
||||
/// Constructs an 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> {
|
||||
/// Creates a `Cursor` by wrapping `inner`.
|
||||
/// Constructs a `Cursor` by wrapping `inner`.
|
||||
#[inline]
|
||||
pub fn new(inner: T) -> Self { Cursor { inner, pos: 0 } }
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// Creates a [`Version`] from a signed 32 bit integer value.
|
||||
/// Constructs a [`Version`] from a signed 32 bit integer value.
|
||||
///
|
||||
/// This is the data type used in consensus code in Bitcoin Core.
|
||||
#[inline]
|
||||
|
|
|
@ -92,13 +92,13 @@ 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.
|
||||
|
||||
/// Creates a `LockTime` from a prefixed hex string.
|
||||
/// Constructs a `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))
|
||||
}
|
||||
|
||||
/// Creates a `LockTime` from an unprefixed hex string.
|
||||
/// Constructs a `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))
|
||||
|
|
|
@ -114,7 +114,7 @@ impl LockTime {
|
|||
LockTime::Time(Time::from_512_second_intervals(intervals))
|
||||
}
|
||||
|
||||
/// Create a [`LockTime`] from seconds, converting the seconds into 512 second interval
|
||||
/// Construct a [`LockTime`] from seconds, converting the seconds into 512 second interval
|
||||
/// with truncating division.
|
||||
///
|
||||
/// # Errors
|
||||
|
@ -128,7 +128,7 @@ impl LockTime {
|
|||
}
|
||||
}
|
||||
|
||||
/// Create a [`LockTime`] from seconds, converting the seconds into 512 second interval
|
||||
/// Construct a [`LockTime`] from seconds, converting the seconds into 512 second interval
|
||||
/// with ceiling division.
|
||||
///
|
||||
/// # Errors
|
||||
|
|
|
@ -495,7 +495,7 @@ macro_rules! ordinary_opcode {
|
|||
}
|
||||
}
|
||||
|
||||
/// Try to create a [`Ordinary`] from an [`Opcode`].
|
||||
/// Try to construct a [`Ordinary`] from an [`Opcode`].
|
||||
pub fn from_opcode(b: Opcode) -> Option<Self> {
|
||||
match b {
|
||||
$( $op => { Some(Ordinary::$op) } ),*
|
||||
|
|
|
@ -23,7 +23,7 @@ use core::fmt;
|
|||
pub struct CompactTarget(u32);
|
||||
|
||||
impl CompactTarget {
|
||||
/// Creates a [`CompactTarget`] from a consensus encoded `u32`.
|
||||
/// Constructs a [`CompactTarget`] from a consensus encoded `u32`.
|
||||
pub fn from_consensus(bits: u32) -> Self { Self(bits) }
|
||||
|
||||
/// Returns the consensus encoded `u32` representation of this [`CompactTarget`].
|
||||
|
|
|
@ -63,7 +63,7 @@ impl ToOwned for Script {
|
|||
}
|
||||
|
||||
impl Script {
|
||||
/// Creates a new empty script.
|
||||
/// Constructs a new empty script.
|
||||
#[inline]
|
||||
pub fn new() -> &'static Script { Script::from_bytes(&[]) }
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ use crate::prelude::{Box, Vec};
|
|||
pub struct ScriptBuf(pub(in crate::script) Vec<u8>);
|
||||
|
||||
impl ScriptBuf {
|
||||
/// Creates a new empty script.
|
||||
/// Constructs a new empty script.
|
||||
#[inline]
|
||||
pub const fn new() -> Self { ScriptBuf(Vec::new()) }
|
||||
|
||||
|
@ -56,7 +56,7 @@ impl ScriptBuf {
|
|||
unsafe { Box::from_raw(rw) }
|
||||
}
|
||||
|
||||
/// Creates a new empty script with pre-allocated capacity.
|
||||
/// Constructs a new empty script with pre-allocated capacity.
|
||||
pub fn with_capacity(capacity: usize) -> Self { ScriptBuf(Vec::with_capacity(capacity)) }
|
||||
|
||||
/// Pre-allocates at least `additional_len` bytes if needed.
|
||||
|
|
|
@ -126,25 +126,25 @@ impl Sequence {
|
|||
self.is_relative_lock_time() & (self.0 & Sequence::LOCK_TYPE_MASK > 0)
|
||||
}
|
||||
|
||||
/// Creates a `Sequence` from a prefixed hex string.
|
||||
/// Constructs a `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))
|
||||
}
|
||||
|
||||
/// Creates a `Sequence` from an unprefixed hex string.
|
||||
/// Constructs a `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))
|
||||
}
|
||||
|
||||
/// Creates a relative lock-time using block height.
|
||||
/// Constructs a relative lock-time using block height.
|
||||
#[inline]
|
||||
pub fn from_height(height: u16) -> Self { Sequence(u32::from(height)) }
|
||||
|
||||
/// Creates a relative lock-time using time intervals where each interval is equivalent
|
||||
/// Constructs a 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)
|
||||
}
|
||||
|
||||
/// Creates a relative lock-time from seconds, converting the seconds into 512 second
|
||||
/// Constructs a 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 {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a relative lock-time from seconds, converting the seconds into 512 second
|
||||
/// Constructs a 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 {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a sequence from a u32 value.
|
||||
/// Constructs a 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 }
|
||||
|
||||
/// Creates a [`relative::LockTime`] from this [`Sequence`] number.
|
||||
/// Constructs a [`relative::LockTime`] from this [`Sequence`] number.
|
||||
#[inline]
|
||||
#[cfg(feature = "alloc")]
|
||||
pub fn to_relative_lock_time(&self) -> Option<relative::LockTime> {
|
||||
|
|
|
@ -49,13 +49,13 @@ pub struct Witness {
|
|||
}
|
||||
|
||||
impl Witness {
|
||||
/// Creates a new empty [`Witness`].
|
||||
/// Constructs a new empty [`Witness`].
|
||||
#[inline]
|
||||
pub const fn new() -> Self {
|
||||
Witness { content: Vec::new(), witness_elements: 0, indices_start: 0 }
|
||||
}
|
||||
|
||||
/// Creates a new [`Witness`] from inner parts.
|
||||
/// Constructs a new [`Witness`] from inner parts.
|
||||
///
|
||||
/// This function leaks implementation details of the `Witness`, as such it is unstable and
|
||||
/// should not be relied upon (it is primarily provided for use in `rust-bitcoin`).
|
||||
|
@ -72,7 +72,7 @@ impl Witness {
|
|||
Witness { content, witness_elements, indices_start }
|
||||
}
|
||||
|
||||
/// Creates a [`Witness`] object from a slice of bytes slices where each slice is a witness item.
|
||||
/// Constructs a [`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;
|
||||
|
|
|
@ -46,7 +46,7 @@ impl SignedAmount {
|
|||
/// The maximum value of an amount.
|
||||
pub const MAX: SignedAmount = SignedAmount(i64::MAX);
|
||||
|
||||
/// Creates a [`SignedAmount`] with satoshi precision and the given number of satoshis.
|
||||
/// Constructs a [`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)
|
||||
}
|
||||
|
||||
/// Creates an object that implements [`fmt::Display`] using specified denomination.
|
||||
/// Constructs an 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 {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates an object that implements [`fmt::Display`] dynamically selecting denomination.
|
||||
/// Constructs an 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.
|
||||
|
|
|
@ -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.
|
||||
|
||||
/// Creates an [`Amount`] with satoshi precision and the given number of satoshis.
|
||||
/// Constructs an [`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)
|
||||
}
|
||||
|
||||
/// Creates an object that implements [`fmt::Display`] using specified denomination.
|
||||
/// Constructs an 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 {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates an object that implements [`fmt::Display`] dynamically selecting denomination.
|
||||
/// Constructs an 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.
|
||||
|
|
|
@ -41,7 +41,7 @@ impl BlockHeight {
|
|||
/// The maximum block height.
|
||||
pub const MAX: Self = BlockHeight(u32::MAX);
|
||||
|
||||
/// Creates a block height from a `u32`.
|
||||
/// Constructs a 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);
|
||||
|
||||
/// Creates a block interval from a `u32`.
|
||||
/// Constructs a block interval from a `u32`.
|
||||
// Because From<u32> is not const.
|
||||
pub const fn from_u32(inner: u32) -> Self { Self(inner) }
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ impl Height {
|
|||
/// The maximum absolute block height.
|
||||
pub const MAX: Self = Height(LOCK_TIME_THRESHOLD - 1);
|
||||
|
||||
/// Creates a [`Height`] from a hex string.
|
||||
/// Constructs a [`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);
|
||||
|
||||
/// Creates a [`Time`] from a hex string.
|
||||
/// Constructs a [`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) }
|
||||
|
|
|
@ -22,7 +22,7 @@ impl Height {
|
|||
/// The maximum relative block height.
|
||||
pub const MAX: Self = Height(u16::MAX);
|
||||
|
||||
/// Create a [`Height`] using a count of blocks.
|
||||
/// Construct a [`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);
|
||||
|
||||
/// Creates a [`Time`] using time intervals where each interval is equivalent to 512 seconds.
|
||||
/// Constructs a [`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) }
|
||||
|
||||
/// Creates a [`Time`] from seconds, converting the seconds into 512 second interval with
|
||||
/// Constructs a [`Time`] from seconds, converting the seconds into 512 second interval with
|
||||
/// truncating division.
|
||||
///
|
||||
/// # Errors
|
||||
|
@ -89,7 +89,7 @@ impl Time {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a [`Time`] from seconds, converting the seconds into 512 second intervals with
|
||||
/// Constructs a [`Time`] from seconds, converting the seconds into 512 second intervals with
|
||||
/// ceiling division.
|
||||
///
|
||||
/// # Errors
|
||||
|
@ -133,7 +133,7 @@ pub struct TimeOverflowError {
|
|||
}
|
||||
|
||||
impl TimeOverflowError {
|
||||
/// Creates a new `TimeOverflowError` using `seconds`.
|
||||
/// Constructs a new `TimeOverflowError` using `seconds`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
|
|
@ -378,7 +378,7 @@ pub struct MissingPrefixError {
|
|||
}
|
||||
|
||||
impl MissingPrefixError {
|
||||
/// Creates an error from the string with the missing prefix.
|
||||
/// Constructs an 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 {
|
||||
/// Creates an error from the string that contains the prefix.
|
||||
/// Constructs an error from the string that contains the prefix.
|
||||
pub(crate) fn new(hex: &str) -> Self { Self { hex: hex.into() } }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue