From 154a4420fce5466273b492977d179b8f77b48a97 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 17 Jan 2025 10:24:45 +1100 Subject: [PATCH] Stop using FQP on Amount type Using `crate::Amount` adds no additional information - stop doing that. Internal change only. --- bitcoin/src/blockdata/script/borrowed.rs | 12 ++++++------ bitcoin/src/blockdata/script/tests.rs | 12 ++++++------ bitcoin/src/consensus_validation.rs | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bitcoin/src/blockdata/script/borrowed.rs b/bitcoin/src/blockdata/script/borrowed.rs index b3a65ff96..14c32e314 100644 --- a/bitcoin/src/blockdata/script/borrowed.rs +++ b/bitcoin/src/blockdata/script/borrowed.rs @@ -15,7 +15,7 @@ use crate::opcodes::{self, Opcode}; use crate::policy::{DUST_RELAY_TX_FEE, MAX_OP_RETURN_RELAY}; use crate::prelude::{sink, DisplayHex, String, ToString}; use crate::taproot::{LeafVersion, TapLeafHash, TapLeafHashExt as _}; -use crate::FeeRate; +use crate::{Amount, FeeRate}; #[rustfmt::skip] // Keep public re-exports separate. #[doc(inline)] @@ -261,7 +261,7 @@ crate::internal_macros::define_extension_trait! { /// Returns the minimum value an output with this script should have in order to be /// broadcastable on today’s Bitcoin network. #[deprecated(since = "0.32.0", note = "use `minimal_non_dust` etc. instead")] - fn dust_value(&self) -> crate::Amount { self.minimal_non_dust() } + fn dust_value(&self) -> Amount { self.minimal_non_dust() } /// Returns the minimum value an output with this script should have in order to be /// broadcastable on today's Bitcoin network. @@ -272,7 +272,7 @@ crate::internal_macros::define_extension_trait! { /// To use a custom value, use [`minimal_non_dust_custom`]. /// /// [`minimal_non_dust_custom`]: Script::minimal_non_dust_custom - fn minimal_non_dust(&self) -> crate::Amount { + fn minimal_non_dust(&self) -> Amount { self.minimal_non_dust_internal(DUST_RELAY_TX_FEE.into()) } @@ -287,7 +287,7 @@ crate::internal_macros::define_extension_trait! { /// To use the default Bitcoin Core value, use [`minimal_non_dust`]. /// /// [`minimal_non_dust`]: Script::minimal_non_dust - fn minimal_non_dust_custom(&self, dust_relay_fee: FeeRate) -> crate::Amount { + fn minimal_non_dust_custom(&self, dust_relay_fee: FeeRate) -> Amount { self.minimal_non_dust_internal(dust_relay_fee.to_sat_per_kwu() * 4) } @@ -394,7 +394,7 @@ mod sealed { crate::internal_macros::define_extension_trait! { pub(crate) trait ScriptExtPriv impl for Script { - fn minimal_non_dust_internal(&self, dust_relay_fee: u64) -> crate::Amount { + fn minimal_non_dust_internal(&self, dust_relay_fee: u64) -> Amount { // This must never be lower than Bitcoin Core's GetDustThreshold() (as of v0.21) as it may // otherwise allow users to create transactions which likely can never be broadcast/confirmed. let sats = dust_relay_fee @@ -414,7 +414,7 @@ crate::internal_macros::define_extension_trait! { // Note: We ensure the division happens at the end, since Core performs the division at the end. // This will make sure none of the implicit floor operations mess with the value. - crate::Amount::from_sat(sats) + Amount::from_sat(sats) } fn count_sigops_internal(&self, accurate: bool) -> usize { diff --git a/bitcoin/src/blockdata/script/tests.rs b/bitcoin/src/blockdata/script/tests.rs index b14ec86f4..4085085d2 100644 --- a/bitcoin/src/blockdata/script/tests.rs +++ b/bitcoin/src/blockdata/script/tests.rs @@ -9,7 +9,7 @@ use crate::address::script_pubkey::{ }; use crate::consensus::encode::{deserialize, serialize}; use crate::crypto::key::{PublicKey, XOnlyPublicKey}; -use crate::FeeRate; +use crate::{Amount, FeeRate}; #[test] #[rustfmt::skip] @@ -676,7 +676,7 @@ fn bitcoinconsensus() { let spent_bytes = hex!("0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d"); let spent = Script::from_bytes(&spent_bytes); let spending = hex!("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000"); - spent.verify(0, crate::Amount::from_sat_unchecked(18393430), &spending).unwrap(); + spent.verify(0, Amount::from_sat_unchecked(18393430), &spending).unwrap(); } #[test] @@ -685,10 +685,10 @@ fn default_dust_value() { // well-known scriptPubKey types. let script_p2wpkh = Builder::new().push_int_unchecked(0).push_slice([42; 20]).into_script(); assert!(script_p2wpkh.is_p2wpkh()); - assert_eq!(script_p2wpkh.minimal_non_dust(), crate::Amount::from_sat_unchecked(294)); + assert_eq!(script_p2wpkh.minimal_non_dust(), Amount::from_sat_unchecked(294)); assert_eq!( script_p2wpkh.minimal_non_dust_custom(FeeRate::from_sat_per_vb_unchecked(6)), - crate::Amount::from_sat_unchecked(588) + Amount::from_sat_unchecked(588) ); let script_p2pkh = Builder::new() @@ -699,10 +699,10 @@ fn default_dust_value() { .push_opcode(OP_CHECKSIG) .into_script(); assert!(script_p2pkh.is_p2pkh()); - assert_eq!(script_p2pkh.minimal_non_dust(), crate::Amount::from_sat_unchecked(546)); + assert_eq!(script_p2pkh.minimal_non_dust(), Amount::from_sat_unchecked(546)); assert_eq!( script_p2pkh.minimal_non_dust_custom(FeeRate::from_sat_per_vb_unchecked(6)), - crate::Amount::from_sat_unchecked(1092) + Amount::from_sat_unchecked(1092) ); } diff --git a/bitcoin/src/consensus_validation.rs b/bitcoin/src/consensus_validation.rs index b461374d1..e80994f90 100644 --- a/bitcoin/src/consensus_validation.rs +++ b/bitcoin/src/consensus_validation.rs @@ -134,7 +134,7 @@ define_extension_trait! { fn verify( &self, index: usize, - amount: crate::Amount, + amount: Amount, spending_tx: &[u8], ) -> Result<(), BitcoinconsensusError> { verify_script(self, index, amount, spending_tx) @@ -153,7 +153,7 @@ define_extension_trait! { fn verify_with_flags( &self, index: usize, - amount: crate::Amount, + amount: Amount, spending_tx: &[u8], flags: impl Into, ) -> Result<(), BitcoinconsensusError> {