2025-03-16 automated rustfmt nightly
This commit is contained in:
parent
0ca9fcfd0e
commit
a74e08a53d
|
@ -413,7 +413,7 @@ mod test {
|
||||||
use crate::merkle_tree::TxMerkleNode;
|
use crate::merkle_tree::TxMerkleNode;
|
||||||
use crate::transaction::OutPointExt;
|
use crate::transaction::OutPointExt;
|
||||||
use crate::{
|
use crate::{
|
||||||
transaction, Amount, BlockChecked, CompactTarget, OutPoint, ScriptBuf, Sequence, BlockTime,
|
transaction, Amount, BlockChecked, BlockTime, CompactTarget, OutPoint, ScriptBuf, Sequence,
|
||||||
TxIn, TxOut, Txid, Witness,
|
TxIn, TxOut, Txid, Witness,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ use crate::opcodes::all::*;
|
||||||
use crate::pow::CompactTarget;
|
use crate::pow::CompactTarget;
|
||||||
use crate::transaction::{self, OutPoint, Transaction, TxIn, TxOut};
|
use crate::transaction::{self, OutPoint, Transaction, TxIn, TxOut};
|
||||||
use crate::witness::Witness;
|
use crate::witness::Witness;
|
||||||
use crate::{script, Amount, BlockHash, Sequence, TestnetVersion, BlockTime};
|
use crate::{script, Amount, BlockHash, BlockTime, Sequence, TestnetVersion};
|
||||||
|
|
||||||
/// How many seconds between blocks we expect on average.
|
/// How many seconds between blocks we expect on average.
|
||||||
pub const TARGET_BLOCK_SPACING: u32 = 600;
|
pub const TARGET_BLOCK_SPACING: u32 = 600;
|
||||||
|
|
|
@ -21,10 +21,10 @@ pub use self::{
|
||||||
|
|
||||||
/// Implements `FeeRate` and assoctiated features.
|
/// Implements `FeeRate` and assoctiated features.
|
||||||
pub mod fee_rate {
|
pub mod fee_rate {
|
||||||
/// Re-export everything from the [`units::fee_rate`] module.
|
|
||||||
pub use units::fee_rate::FeeRate;
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
pub use units::fee_rate::serde;
|
pub use units::fee_rate::serde;
|
||||||
|
/// Re-export everything from the [`units::fee_rate`] module.
|
||||||
|
pub use units::fee_rate::FeeRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Provides absolute and relative locktimes.
|
/// Provides absolute and relative locktimes.
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::address::script_pubkey::{
|
||||||
};
|
};
|
||||||
use crate::consensus::encode::{deserialize, serialize};
|
use crate::consensus::encode::{deserialize, serialize};
|
||||||
use crate::crypto::key::{PublicKey, XOnlyPublicKey};
|
use crate::crypto::key::{PublicKey, XOnlyPublicKey};
|
||||||
use crate::{Amount, FeeRate, opcodes};
|
use crate::{opcodes, Amount, FeeRate};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
|
|
@ -462,7 +462,7 @@ impl PrivateKey {
|
||||||
/// Deserializes a private key from a byte array.
|
/// Deserializes a private key from a byte array.
|
||||||
pub fn from_byte_array(
|
pub fn from_byte_array(
|
||||||
data: [u8; 32],
|
data: [u8; 32],
|
||||||
network: impl Into<NetworkKind>
|
network: impl Into<NetworkKind>,
|
||||||
) -> Result<PrivateKey, secp256k1::Error> {
|
) -> Result<PrivateKey, secp256k1::Error> {
|
||||||
Ok(PrivateKey::new(secp256k1::SecretKey::from_byte_array(&data)?, network))
|
Ok(PrivateKey::new(secp256k1::SecretKey::from_byte_array(&data)?, network))
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,9 +164,7 @@ pub use crate::{
|
||||||
blockdata::script::witness_program::{self, WitnessProgram},
|
blockdata::script::witness_program::{self, WitnessProgram},
|
||||||
blockdata::script::witness_version::{self, WitnessVersion},
|
blockdata::script::witness_version::{self, WitnessVersion},
|
||||||
// These modules also re-export all the respective `primitives` types.
|
// These modules also re-export all the respective `primitives` types.
|
||||||
blockdata::{
|
blockdata::{block, constants, fee_rate, locktime, script, transaction, weight, witness},
|
||||||
block, constants, fee_rate, locktime, script, transaction, weight, witness,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl Psbt {
|
||||||
/// An alias for [`extract_tx_fee_rate_limit`].
|
/// An alias for [`extract_tx_fee_rate_limit`].
|
||||||
///
|
///
|
||||||
/// [`extract_tx_fee_rate_limit`]: Psbt::extract_tx_fee_rate_limit
|
/// [`extract_tx_fee_rate_limit`]: Psbt::extract_tx_fee_rate_limit
|
||||||
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
|
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
|
||||||
pub fn extract_tx(self) -> Result<Transaction, ExtractTxError> {
|
pub fn extract_tx(self) -> Result<Transaction, ExtractTxError> {
|
||||||
self.internal_extract_tx_with_fee_rate_limit(Self::DEFAULT_MAX_FEE_RATE)
|
self.internal_extract_tx_with_fee_rate_limit(Self::DEFAULT_MAX_FEE_RATE)
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ impl Psbt {
|
||||||
/// [`ExtractTxError`] variants will contain either the [`Psbt`] itself or the [`Transaction`]
|
/// [`ExtractTxError`] variants will contain either the [`Psbt`] itself or the [`Transaction`]
|
||||||
/// that was extracted. These can be extracted from the Errors in order to recover.
|
/// that was extracted. These can be extracted from the Errors in order to recover.
|
||||||
/// See the error documentation for info on the variants. In general, it covers large fees.
|
/// See the error documentation for info on the variants. In general, it covers large fees.
|
||||||
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
|
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
|
||||||
pub fn extract_tx_fee_rate_limit(self) -> Result<Transaction, ExtractTxError> {
|
pub fn extract_tx_fee_rate_limit(self) -> Result<Transaction, ExtractTxError> {
|
||||||
self.internal_extract_tx_with_fee_rate_limit(Self::DEFAULT_MAX_FEE_RATE)
|
self.internal_extract_tx_with_fee_rate_limit(Self::DEFAULT_MAX_FEE_RATE)
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ impl Psbt {
|
||||||
/// See [`extract_tx`].
|
/// See [`extract_tx`].
|
||||||
///
|
///
|
||||||
/// [`extract_tx`]: Psbt::extract_tx
|
/// [`extract_tx`]: Psbt::extract_tx
|
||||||
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
|
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
|
||||||
pub fn extract_tx_with_fee_rate_limit(
|
pub fn extract_tx_with_fee_rate_limit(
|
||||||
self,
|
self,
|
||||||
max_fee_rate: FeeRate,
|
max_fee_rate: FeeRate,
|
||||||
|
@ -187,7 +187,7 @@ impl Psbt {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
|
#[allow(clippy::result_large_err)] // The PSBT returned in `SendingToomuch` is large.
|
||||||
fn internal_extract_tx_with_fee_rate_limit(
|
fn internal_extract_tx_with_fee_rate_limit(
|
||||||
self,
|
self,
|
||||||
max_fee_rate: FeeRate,
|
max_fee_rate: FeeRate,
|
||||||
|
|
|
@ -260,10 +260,8 @@ impl Serialize for XOnlyPublicKey {
|
||||||
|
|
||||||
impl Deserialize for XOnlyPublicKey {
|
impl Deserialize for XOnlyPublicKey {
|
||||||
fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
|
fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
|
||||||
XOnlyPublicKey::from_byte_array(
|
XOnlyPublicKey::from_byte_array(bytes.try_into().map_err(|_| Error::InvalidXOnlyPublicKey)?)
|
||||||
bytes.try_into().map_err(|_| Error::InvalidXOnlyPublicKey)?,
|
.map_err(|_| Error::InvalidXOnlyPublicKey)
|
||||||
)
|
|
||||||
.map_err(|_| Error::InvalidXOnlyPublicKey)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,11 +52,7 @@ impl TaprootMerkleBranch {
|
||||||
} else if node_hashes.len() > TAPROOT_CONTROL_MAX_NODE_COUNT {
|
} else if node_hashes.len() > TAPROOT_CONTROL_MAX_NODE_COUNT {
|
||||||
Err(InvalidMerkleTreeDepthError(sl.len() / TAPROOT_CONTROL_NODE_SIZE).into())
|
Err(InvalidMerkleTreeDepthError(sl.len() / TAPROOT_CONTROL_NODE_SIZE).into())
|
||||||
} else {
|
} else {
|
||||||
let inner = node_hashes
|
let inner = node_hashes.iter().copied().map(TapNodeHash::from_byte_array).collect();
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.map(TapNodeHash::from_byte_array)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(TaprootMerkleBranch(inner))
|
Ok(TaprootMerkleBranch(inner))
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,8 +109,7 @@ fn serde_regression_txin() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serde_regression_txout() {
|
fn serde_regression_txout() {
|
||||||
let txout =
|
let txout = TxOut { value: Amount::MAX, script_pubkey: ScriptBuf::from(vec![0u8, 1u8, 2u8]) };
|
||||||
TxOut { value: Amount::MAX, script_pubkey: ScriptBuf::from(vec![0u8, 1u8, 2u8]) };
|
|
||||||
let got = serialize(&txout).unwrap();
|
let got = serialize(&txout).unwrap();
|
||||||
let want = include_bytes!("data/serde/txout_bincode") as &[_];
|
let want = include_bytes!("data/serde/txout_bincode") as &[_];
|
||||||
assert_eq!(got, want)
|
assert_eq!(got, want)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use honggfuzz::fuzz;
|
|
||||||
|
|
||||||
use bitcoin_fuzz::fuzz_utils::consume_random_bytes;
|
use bitcoin_fuzz::fuzz_utils::consume_random_bytes;
|
||||||
|
use honggfuzz::fuzz;
|
||||||
|
|
||||||
fn do_test(data: &[u8]) {
|
fn do_test(data: &[u8]) {
|
||||||
let mut new_data = data;
|
let mut new_data = data;
|
||||||
|
|
|
@ -2,9 +2,8 @@ use bitcoin::address::Address;
|
||||||
use bitcoin::consensus::encode;
|
use bitcoin::consensus::encode;
|
||||||
use bitcoin::script::{self, ScriptExt as _};
|
use bitcoin::script::{self, ScriptExt as _};
|
||||||
use bitcoin::{FeeRate, Network};
|
use bitcoin::{FeeRate, Network};
|
||||||
use honggfuzz::fuzz;
|
|
||||||
|
|
||||||
use bitcoin_fuzz::fuzz_utils::{consume_random_bytes, consume_u64};
|
use bitcoin_fuzz::fuzz_utils::{consume_random_bytes, consume_u64};
|
||||||
|
use honggfuzz::fuzz;
|
||||||
|
|
||||||
fn do_test(data: &[u8]) {
|
fn do_test(data: &[u8]) {
|
||||||
let mut new_data = data;
|
let mut new_data = data;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// SPDX-License-Identifier: CC0-1.0
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
use internals::slice::SliceExt;
|
use internals::slice::SliceExt;
|
||||||
|
|
||||||
use super::{HashEngine, BLOCK_SIZE};
|
use super::{HashEngine, BLOCK_SIZE};
|
||||||
|
|
||||||
#[cfg(feature = "small-hash")]
|
#[cfg(feature = "small-hash")]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// SPDX-License-Identifier: CC0-1.0
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
use internals::slice::SliceExt;
|
use internals::slice::SliceExt;
|
||||||
|
|
||||||
use super::{HashEngine, BLOCK_SIZE};
|
use super::{HashEngine, BLOCK_SIZE};
|
||||||
|
|
||||||
impl HashEngine {
|
impl HashEngine {
|
||||||
|
|
|
@ -6,6 +6,7 @@ use core::arch::x86::*;
|
||||||
use core::arch::x86_64::*;
|
use core::arch::x86_64::*;
|
||||||
|
|
||||||
use internals::slice::SliceExt;
|
use internals::slice::SliceExt;
|
||||||
|
|
||||||
use super::{HashEngine, Midstate, BLOCK_SIZE};
|
use super::{HashEngine, Midstate, BLOCK_SIZE};
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
|
@ -9,6 +9,7 @@ mod crypto;
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use core::{cmp, convert, fmt};
|
use core::{cmp, convert, fmt};
|
||||||
|
|
||||||
use internals::slice::SliceExt;
|
use internals::slice::SliceExt;
|
||||||
|
|
||||||
use crate::{incomplete_block_len, sha256d, HashEngine as _};
|
use crate::{incomplete_block_len, sha256d, HashEngine as _};
|
||||||
|
@ -80,7 +81,8 @@ impl HashEngine {
|
||||||
/// Please see docs on [`Midstate`] before using this function.
|
/// Please see docs on [`Midstate`] before using this function.
|
||||||
pub fn from_midstate(midstate: Midstate) -> HashEngine {
|
pub fn from_midstate(midstate: Midstate) -> HashEngine {
|
||||||
let mut ret = [0; 8];
|
let mut ret = [0; 8];
|
||||||
for (ret_val, midstate_bytes) in ret.iter_mut().zip(midstate.as_ref().bitcoin_as_chunks().0) {
|
for (ret_val, midstate_bytes) in ret.iter_mut().zip(midstate.as_ref().bitcoin_as_chunks().0)
|
||||||
|
{
|
||||||
*ret_val = u32::from_be_bytes(*midstate_bytes);
|
*ret_val = u32::from_be_bytes(*midstate_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// SPDX-License-Identifier: CC0-1.0
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
use internals::slice::SliceExt;
|
use internals::slice::SliceExt;
|
||||||
|
|
||||||
use super::{HashEngine, BLOCK_SIZE};
|
use super::{HashEngine, BLOCK_SIZE};
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
|
@ -23,7 +23,9 @@ pub trait SliceExt {
|
||||||
/// let mut slice = [1, 2, 3];
|
/// let mut slice = [1, 2, 3];
|
||||||
/// let fail = slice.as_chunks_mut::<0>();
|
/// let fail = slice.as_chunks_mut::<0>();
|
||||||
/// ```
|
/// ```
|
||||||
fn bitcoin_as_chunks_mut<const N: usize>(&mut self) -> (&mut [[Self::Item; N]], &mut [Self::Item]);
|
fn bitcoin_as_chunks_mut<const N: usize>(
|
||||||
|
&mut self,
|
||||||
|
) -> (&mut [[Self::Item; N]], &mut [Self::Item]);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> SliceExt for [T] {
|
impl<T> SliceExt for [T] {
|
||||||
|
@ -40,11 +42,15 @@ impl<T> SliceExt for [T] {
|
||||||
// we're merely casting, so no aliasing issues here
|
// we're merely casting, so no aliasing issues here
|
||||||
// arrays of T have same alignment as T
|
// arrays of T have same alignment as T
|
||||||
// the resulting slice points within the obtained slice as was computed above
|
// the resulting slice points within the obtained slice as was computed above
|
||||||
let left = unsafe { core::slice::from_raw_parts(left.as_ptr().cast::<[Self::Item; N]>(), chunks_count) };
|
let left = unsafe {
|
||||||
|
core::slice::from_raw_parts(left.as_ptr().cast::<[Self::Item; N]>(), chunks_count)
|
||||||
|
};
|
||||||
(left, right)
|
(left, right)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bitcoin_as_chunks_mut<const N: usize>(&mut self) -> (&mut [[Self::Item; N]], &mut [Self::Item]) {
|
fn bitcoin_as_chunks_mut<const N: usize>(
|
||||||
|
&mut self,
|
||||||
|
) -> (&mut [[Self::Item; N]], &mut [Self::Item]) {
|
||||||
#[allow(clippy::let_unit_value)]
|
#[allow(clippy::let_unit_value)]
|
||||||
let _ = Hack::<N>::IS_NONZERO;
|
let _ = Hack::<N>::IS_NONZERO;
|
||||||
|
|
||||||
|
@ -55,7 +61,12 @@ impl<T> SliceExt for [T] {
|
||||||
// we're merely casting, so no aliasing issues here
|
// we're merely casting, so no aliasing issues here
|
||||||
// arrays of T have same alignment as T
|
// arrays of T have same alignment as T
|
||||||
// the resulting slice points within the obtained slice as was computed above
|
// the resulting slice points within the obtained slice as was computed above
|
||||||
let left = unsafe { core::slice::from_raw_parts_mut(left.as_mut_ptr().cast::<[Self::Item; N]>(), chunks_count) };
|
let left = unsafe {
|
||||||
|
core::slice::from_raw_parts_mut(
|
||||||
|
left.as_mut_ptr().cast::<[Self::Item; N]>(),
|
||||||
|
chunks_count,
|
||||||
|
)
|
||||||
|
};
|
||||||
(left, right)
|
(left, right)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +74,9 @@ impl<T> SliceExt for [T] {
|
||||||
struct Hack<const N: usize>;
|
struct Hack<const N: usize>;
|
||||||
|
|
||||||
impl<const N: usize> Hack<N> {
|
impl<const N: usize> Hack<N> {
|
||||||
const IS_NONZERO: () = { assert!(N != 0); };
|
const IS_NONZERO: () = {
|
||||||
|
assert!(N != 0);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
//! all of the opcodes for that language.
|
//! all of the opcodes for that language.
|
||||||
|
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![allow(dead_code)] // This module is private and is duplicated in `bitcoin`.
|
#![allow(dead_code)] // This module is private and is duplicated in `bitcoin`.
|
||||||
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
|
|
|
@ -670,7 +670,10 @@ mod tests {
|
||||||
witness: Witness::new(),
|
witness: Witness::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let txout = TxOut { value: Amount::from_sat(123_456_789).unwrap(), script_pubkey: ScriptBuf::new() };
|
let txout = TxOut {
|
||||||
|
value: Amount::from_sat(123_456_789).unwrap(),
|
||||||
|
script_pubkey: ScriptBuf::new(),
|
||||||
|
};
|
||||||
|
|
||||||
let tx_orig = Transaction {
|
let tx_orig = Transaction {
|
||||||
version: Version::ONE,
|
version: Version::ONE,
|
||||||
|
|
|
@ -355,8 +355,7 @@ impl<'de> serde::Deserialize<'de> for Witness {
|
||||||
self,
|
self,
|
||||||
mut a: A,
|
mut a: A,
|
||||||
) -> Result<Self::Value, A::Error> {
|
) -> Result<Self::Value, A::Error> {
|
||||||
use hex::FromHex;
|
use hex::{FromHex, HexToBytesError as E};
|
||||||
use hex::HexToBytesError as E;
|
|
||||||
use serde::de::{self, Unexpected};
|
use serde::de::{self, Unexpected};
|
||||||
|
|
||||||
let mut ret = match a.size_hint() {
|
let mut ret = match a.size_hint() {
|
||||||
|
@ -366,16 +365,17 @@ impl<'de> serde::Deserialize<'de> for Witness {
|
||||||
|
|
||||||
while let Some(elem) = a.next_element::<String>()? {
|
while let Some(elem) = a.next_element::<String>()? {
|
||||||
let vec = Vec::<u8>::from_hex(&elem).map_err(|e| match e {
|
let vec = Vec::<u8>::from_hex(&elem).map_err(|e| match e {
|
||||||
E::InvalidChar(ref e) => match core::char::from_u32(e.invalid_char().into()) {
|
E::InvalidChar(ref e) =>
|
||||||
Some(c) => de::Error::invalid_value(
|
match core::char::from_u32(e.invalid_char().into()) {
|
||||||
Unexpected::Char(c),
|
Some(c) => de::Error::invalid_value(
|
||||||
&"a valid hex character",
|
Unexpected::Char(c),
|
||||||
),
|
&"a valid hex character",
|
||||||
None => de::Error::invalid_value(
|
),
|
||||||
Unexpected::Unsigned(e.invalid_char().into()),
|
None => de::Error::invalid_value(
|
||||||
&"a valid hex character",
|
Unexpected::Unsigned(e.invalid_char().into()),
|
||||||
),
|
&"a valid hex character",
|
||||||
},
|
),
|
||||||
|
},
|
||||||
E::OddLengthString(ref e) =>
|
E::OddLengthString(ref e) =>
|
||||||
de::Error::invalid_length(e.length(), &"an even length string"),
|
de::Error::invalid_length(e.length(), &"an even length string"),
|
||||||
})?;
|
})?;
|
||||||
|
|
|
@ -115,7 +115,7 @@ impl Denomination {
|
||||||
Denomination::MicroBitcoin => -2,
|
Denomination::MicroBitcoin => -2,
|
||||||
Denomination::Bit => -2,
|
Denomination::Bit => -2,
|
||||||
Denomination::Satoshi => 0,
|
Denomination::Satoshi => 0,
|
||||||
Denomination::_DoNotUse(infallible) => match infallible {}
|
Denomination::_DoNotUse(infallible) => match infallible {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ impl Denomination {
|
||||||
Denomination::MicroBitcoin => "uBTC",
|
Denomination::MicroBitcoin => "uBTC",
|
||||||
Denomination::Bit => "bits",
|
Denomination::Bit => "bits",
|
||||||
Denomination::Satoshi => "satoshi",
|
Denomination::Satoshi => "satoshi",
|
||||||
Denomination::_DoNotUse(infallible) => match infallible {}
|
Denomination::_DoNotUse(infallible) => match infallible {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -345,14 +345,8 @@ fn parsing() {
|
||||||
assert_eq!(p("1.1", den_btc), Ok(sat(1_100_000_00)));
|
assert_eq!(p("1.1", den_btc), Ok(sat(1_100_000_00)));
|
||||||
assert_eq!(p("100", den_sat), Ok(sat(100)));
|
assert_eq!(p("100", den_sat), Ok(sat(100)));
|
||||||
assert_eq!(p("55", den_sat), Ok(sat(55)));
|
assert_eq!(p("55", den_sat), Ok(sat(55)));
|
||||||
assert_eq!(
|
assert_eq!(p("2100000000000000", den_sat), Ok(sat(21_000_000__000_000_00)));
|
||||||
p("2100000000000000", den_sat),
|
assert_eq!(p("2100000000000000.", den_sat), Ok(sat(21_000_000__000_000_00)));
|
||||||
Ok(sat(21_000_000__000_000_00))
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
p("2100000000000000.", den_sat),
|
|
||||||
Ok(sat(21_000_000__000_000_00))
|
|
||||||
);
|
|
||||||
assert_eq!(p("21000000", den_btc), Ok(sat(21_000_000__000_000_00)));
|
assert_eq!(p("21000000", den_btc), Ok(sat(21_000_000__000_000_00)));
|
||||||
|
|
||||||
// exactly 50 chars.
|
// exactly 50 chars.
|
||||||
|
@ -702,28 +696,15 @@ fn to_from_string_in() {
|
||||||
assert_eq!(ua_str(&ua_sat(21_000_000).to_string_in(D::Bit), D::Bit), Ok(ua_sat(21_000_000)));
|
assert_eq!(ua_str(&ua_sat(21_000_000).to_string_in(D::Bit), D::Bit), Ok(ua_sat(21_000_000)));
|
||||||
assert_eq!(ua_str(&ua_sat(0).to_string_in(D::Satoshi), D::Satoshi), Ok(ua_sat(0)));
|
assert_eq!(ua_str(&ua_sat(0).to_string_in(D::Satoshi), D::Satoshi), Ok(ua_sat(0)));
|
||||||
|
|
||||||
assert!(
|
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Bitcoin), D::Bitcoin).is_ok());
|
||||||
ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Bitcoin), D::Bitcoin).is_ok()
|
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::CentiBitcoin), D::CentiBitcoin)
|
||||||
);
|
.is_ok());
|
||||||
assert!(ua_str(
|
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::MilliBitcoin), D::MilliBitcoin)
|
||||||
&ua_sat(Amount::MAX.to_sat()).to_string_in(D::CentiBitcoin),
|
.is_ok());
|
||||||
D::CentiBitcoin
|
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::MicroBitcoin), D::MicroBitcoin)
|
||||||
)
|
.is_ok());
|
||||||
.is_ok());
|
|
||||||
assert!(ua_str(
|
|
||||||
&ua_sat(Amount::MAX.to_sat()).to_string_in(D::MilliBitcoin),
|
|
||||||
D::MilliBitcoin
|
|
||||||
)
|
|
||||||
.is_ok());
|
|
||||||
assert!(ua_str(
|
|
||||||
&ua_sat(Amount::MAX.to_sat()).to_string_in(D::MicroBitcoin),
|
|
||||||
D::MicroBitcoin
|
|
||||||
)
|
|
||||||
.is_ok());
|
|
||||||
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Bit), D::Bit).is_ok());
|
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Bit), D::Bit).is_ok());
|
||||||
assert!(
|
assert!(ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Satoshi), D::Satoshi).is_ok());
|
||||||
ua_str(&ua_sat(Amount::MAX.to_sat()).to_string_in(D::Satoshi), D::Satoshi).is_ok()
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
sa_str(&SignedAmount::MAX.to_string_in(D::Satoshi), D::MicroBitcoin),
|
sa_str(&SignedAmount::MAX.to_string_in(D::Satoshi), D::MicroBitcoin),
|
||||||
|
@ -970,11 +951,19 @@ fn sum_amounts() {
|
||||||
assert_eq!([].iter().sum::<NumOpResult<Amount>>(), Amount::ZERO.into());
|
assert_eq!([].iter().sum::<NumOpResult<Amount>>(), Amount::ZERO.into());
|
||||||
assert_eq!([].iter().sum::<NumOpResult<SignedAmount>>(), SignedAmount::ZERO.into());
|
assert_eq!([].iter().sum::<NumOpResult<SignedAmount>>(), SignedAmount::ZERO.into());
|
||||||
|
|
||||||
let results = [NumOpResult::Valid(sat(42)), NumOpResult::Valid(sat(1337)), NumOpResult::Valid(sat(21))];
|
let results =
|
||||||
|
[NumOpResult::Valid(sat(42)), NumOpResult::Valid(sat(1337)), NumOpResult::Valid(sat(21))];
|
||||||
assert_eq!(results.iter().sum::<NumOpResult<Amount>>(), NumOpResult::Valid(sat(1400)));
|
assert_eq!(results.iter().sum::<NumOpResult<Amount>>(), NumOpResult::Valid(sat(1400)));
|
||||||
|
|
||||||
let signed_results = [NumOpResult::Valid(ssat(42)), NumOpResult::Valid(ssat(1337)), NumOpResult::Valid(ssat(21))];
|
let signed_results = [
|
||||||
assert_eq!(signed_results.iter().sum::<NumOpResult<SignedAmount>>(), NumOpResult::Valid(ssat(1400)));
|
NumOpResult::Valid(ssat(42)),
|
||||||
|
NumOpResult::Valid(ssat(1337)),
|
||||||
|
NumOpResult::Valid(ssat(21)),
|
||||||
|
];
|
||||||
|
assert_eq!(
|
||||||
|
signed_results.iter().sum::<NumOpResult<SignedAmount>>(),
|
||||||
|
NumOpResult::Valid(ssat(1400))
|
||||||
|
);
|
||||||
|
|
||||||
let amounts = [sat(42), sat(1337), sat(21)];
|
let amounts = [sat(42), sat(1337), sat(21)];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -1240,9 +1229,7 @@ fn unsigned_amount_div_by_amount() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "attempt to divide by zero")]
|
#[should_panic(expected = "attempt to divide by zero")]
|
||||||
fn unsigned_amount_div_by_amount_zero() {
|
fn unsigned_amount_div_by_amount_zero() { let _ = sat(1897) / Amount::ZERO; }
|
||||||
let _ = sat(1897) / Amount::ZERO;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn signed_amount_div_by_amount() {
|
fn signed_amount_div_by_amount() {
|
||||||
|
@ -1256,9 +1243,7 @@ fn signed_amount_div_by_amount() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "attempt to divide by zero")]
|
#[should_panic(expected = "attempt to divide by zero")]
|
||||||
fn signed_amount_div_by_amount_zero() {
|
fn signed_amount_div_by_amount_zero() { let _ = ssat(1897) / SignedAmount::ZERO; }
|
||||||
let _ = ssat(1897) / SignedAmount::ZERO;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_const() {
|
fn check_const() {
|
||||||
|
|
|
@ -14,8 +14,8 @@ use arbitrary::{Arbitrary, Unstructured};
|
||||||
// These imports test "typical" usage by user code.
|
// These imports test "typical" usage by user code.
|
||||||
use bitcoin_units::locktime::{absolute, relative}; // Typical usage is `absolute::Height`.
|
use bitcoin_units::locktime::{absolute, relative}; // Typical usage is `absolute::Height`.
|
||||||
use bitcoin_units::{
|
use bitcoin_units::{
|
||||||
amount, block, fee_rate, locktime, parse, weight, Amount, BlockHeight, BlockInterval, FeeRate,
|
amount, block, fee_rate, locktime, parse, weight, Amount, BlockHeight, BlockInterval,
|
||||||
SignedAmount, BlockTime, Weight,
|
BlockTime, FeeRate, SignedAmount, Weight,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A struct that includes all public non-error enums.
|
/// A struct that includes all public non-error enums.
|
||||||
|
@ -147,7 +147,7 @@ fn api_can_use_modules_from_crate_root() {
|
||||||
#[test]
|
#[test]
|
||||||
fn api_can_use_types_from_crate_root() {
|
fn api_can_use_types_from_crate_root() {
|
||||||
use bitcoin_units::{
|
use bitcoin_units::{
|
||||||
Amount, BlockHeight, BlockInterval, FeeRate, SignedAmount, BlockTime, Weight,
|
Amount, BlockHeight, BlockInterval, BlockTime, FeeRate, SignedAmount, Weight,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue