Run the formatter

Run `just fmt`, no other manual changes.
This commit is contained in:
Tobin C. Harding 2024-10-10 10:39:53 +11:00
parent 2c40b4f4ec
commit 2e4179ed0f
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
11 changed files with 37 additions and 48 deletions

View File

@ -297,7 +297,8 @@ fn generate_bip86_key_spend_tx(
.get(&input.tap_internal_key.ok_or("internal key missing in PSBT")?)
.ok_or("missing Taproot key origin")?;
let secret_key = master_xpriv.derive_xpriv(secp, &derivation_path).to_private_key().inner;
let secret_key =
master_xpriv.derive_xpriv(secp, &derivation_path).to_private_key().inner;
sign_psbt_taproot(
secret_key,
input.tap_internal_key.unwrap(),
@ -484,8 +485,10 @@ impl BenefactorWallet {
.master_xpriv
.derive_xpriv(&self.secp, &new_derivation_path)
.to_keypair(&self.secp);
let beneficiary_key =
self.beneficiary_xpub.derive_xpub(&self.secp, &new_derivation_path)?.to_x_only_public_key();
let beneficiary_key = self
.beneficiary_xpub
.derive_xpub(&self.secp, &new_derivation_path)?
.to_x_only_public_key();
// Build up the leaf script and combine with internal key into a Taproot commitment
let lock_time = absolute::LockTime::from_height(
@ -530,8 +533,11 @@ impl BenefactorWallet {
.tap_key_origins
.get(&input.tap_internal_key.ok_or("internal key missing in PSBT")?)
.ok_or("missing Taproot key origin")?;
let secret_key =
self.master_xpriv.derive_xpriv(&self.secp, &derivation_path).to_private_key().inner;
let secret_key = self
.master_xpriv
.derive_xpriv(&self.secp, &derivation_path)
.to_private_key()
.inner;
sign_psbt_taproot(
secret_key,
spend_info.internal_key(),

View File

@ -12,7 +12,7 @@ use hashes::{sha256, siphash24};
use internals::{impl_array_newtype, ToU64 as _};
use io::{BufRead, Write};
use crate::consensus::encode::{self, Decodable, Encodable, WriteExt, ReadExt};
use crate::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt};
use crate::internal_macros::{impl_array_newtype_stringify, impl_consensus_encoding};
use crate::prelude::Vec;
use crate::transaction::TxIdentifier;

View File

@ -593,9 +593,7 @@ impl Xpriv {
/// Constructs ECDSA compressed private key matching internal secret key representation.
#[deprecated(since = "TBD", note = "use `to_private_key()`")]
pub fn to_priv(self) -> PrivateKey {
self.to_private_key()
}
pub fn to_priv(self) -> PrivateKey { self.to_private_key() }
/// Constructs ECDSA compressed private key matching internal secret key representation.
pub fn to_private_key(self) -> PrivateKey {
@ -603,7 +601,7 @@ impl Xpriv {
}
/// Creates new extended public key from this extended private key.
pub fn to_xpub<C: secp256k1::Signing>(&self, secp: &Secp256k1<C>,) -> Xpub {
pub fn to_xpub<C: secp256k1::Signing>(&self, secp: &Secp256k1<C>) -> Xpub {
Xpub::from_xpriv(secp, self)
}
@ -775,7 +773,6 @@ impl Xpub {
secp: &Secp256k1<C>,
path: &P,
) -> Result<Xpub, Error> {
self.derive_xpub(secp, path)
}

View File

@ -88,7 +88,6 @@ crate::internal_macros::define_extension_trait! {
}
}
/// Bitcoin transaction input.
///
/// It contains the location of the previous transaction's output,
@ -1267,13 +1266,16 @@ impl InputWeightPrediction {
T: IntoIterator,
T::Item: Borrow<usize>,
{
let (count, total_size) =
witness_element_lengths.into_iter().fold((0usize, 0), |(count, total_size), elem_len| {
let (count, total_size) = witness_element_lengths.into_iter().fold(
(0usize, 0),
|(count, total_size), elem_len| {
let elem_len = *elem_len.borrow();
let elem_size = elem_len + compact_size::encoded_size(elem_len);
(count + 1, total_size + elem_size)
});
let witness_size = if count > 0 { total_size + compact_size::encoded_size(count) } else { 0 };
},
);
let witness_size =
if count > 0 { total_size + compact_size::encoded_size(count) } else { 0 };
let script_size = input_script_len + compact_size::encoded_size(input_script_len);
InputWeightPrediction { script_size, witness_size }
@ -1299,7 +1301,8 @@ impl InputWeightPrediction {
} else {
0
};
let script_size = input_script_len + compact_size::encoded_size_const(input_script_len as u64);
let script_size =
input_script_len + compact_size::encoded_size_const(input_script_len as u64);
InputWeightPrediction { script_size, witness_size }
}

View File

@ -12,7 +12,7 @@ use arbitrary::{Arbitrary, Unstructured};
use internals::compact_size;
use io::{BufRead, Write};
use crate::consensus::encode::{self, Error, MAX_VEC_SIZE, ReadExt, WriteExt};
use crate::consensus::encode::{self, Error, ReadExt, WriteExt, MAX_VEC_SIZE};
use crate::consensus::{Decodable, Encodable};
use crate::crypto::ecdsa;
use crate::prelude::Vec;
@ -185,7 +185,8 @@ impl Decodable for Witness {
encode_cursor(&mut content, 0, i, cursor - witness_index_space);
resize_if_needed(&mut content, required_len);
cursor += (&mut content[cursor..cursor + element_size_len]).emit_compact_size(element_size)?;
cursor += (&mut content[cursor..cursor + element_size_len])
.emit_compact_size(element_size)?;
r.read_exact(&mut content[cursor..cursor + element_size])?;
cursor += element_size;
}
@ -629,7 +630,7 @@ mod test {
use hex::test_hex_unwrap as hex;
use super::*;
use crate::consensus::{encode, deserialize, serialize};
use crate::consensus::{deserialize, encode, serialize};
use crate::hex::DisplayHex;
use crate::sighash::EcdsaSighashType;
use crate::Transaction;
@ -649,11 +650,7 @@ mod test {
// The last four bytes represent start at index 0.
let content = [0_u8; 5];
Witness {
witness_elements: 1,
content: content.to_vec(),
indices_start: 1,
}
Witness { witness_elements: 1, content: content.to_vec(), indices_start: 1 }
}
#[test]
@ -960,7 +957,6 @@ mod test {
let ser = serde_json::to_string(&original).unwrap();
let rinsed: Witness = serde_json::from_str(&ser).unwrap();
assert_eq!(rinsed, original);
}
#[test]

View File

@ -493,9 +493,7 @@ pub const fn varint_size_u64(v: u64) -> usize {
/// Returns 1 for 0..=0xFC, 3 for 0xFD..=(2^16-1), 5 for 0x10000..=(2^32-1), and 9 otherwise.
#[inline]
pub fn varint_size(v: impl ToU64) -> usize {
varint_size_u64(v.to_u64())
}
pub fn varint_size(v: impl ToU64) -> usize { varint_size_u64(v.to_u64()) }
impl Encodable for bool {
#[inline]
@ -935,14 +933,8 @@ mod tests {
assert_eq!(encode(0xFD), [0xFDu8, 0xFD, 0]);
assert_eq!(encode(0xFFF), [0xFDu8, 0xFF, 0xF]);
assert_eq!(encode(0xF0F0F0F), [0xFEu8, 0xF, 0xF, 0xF, 0xF]);
assert_eq!(
encode(0xF0F0F0F0F0E0),
vec![0xFFu8, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0, 0],
);
assert_eq!(
test_varint_encode(0xFF, &0x100000000_u64.to_le_bytes()).unwrap(),
0x100000000,
);
assert_eq!(encode(0xF0F0F0F0F0E0), vec![0xFFu8, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0, 0],);
assert_eq!(test_varint_encode(0xFF, &0x100000000_u64.to_le_bytes()).unwrap(), 0x100000000,);
assert_eq!(test_varint_encode(0xFE, &0x10000_u64.to_le_bytes()).unwrap(), 0x10000);
assert_eq!(test_varint_encode(0xFD, &0xFD_u64.to_le_bytes()).unwrap(), 0xFD);

View File

@ -16,7 +16,7 @@ use io::{BufRead, Write};
use self::MerkleBlockError::*;
use crate::block::{self, Block};
use crate::consensus::encode::{self, Decodable, Encodable, MAX_VEC_SIZE, WriteExt, ReadExt};
use crate::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt, MAX_VEC_SIZE};
use crate::merkle_tree::{MerkleNode as _, TxMerkleNode};
use crate::prelude::Vec;
use crate::transaction::{Transaction, Txid};

View File

@ -11,7 +11,7 @@ use hashes::sha256d;
use internals::ToU64 as _;
use io::{BufRead, Write};
use crate::consensus::encode::{self, CheckedData, Decodable, Encodable, WriteExt, ReadExt};
use crate::consensus::encode::{self, CheckedData, Decodable, Encodable, ReadExt, WriteExt};
use crate::merkle_tree::MerkleBlock;
use crate::p2p::address::{AddrV2Message, Address};
use crate::p2p::{

View File

@ -29,9 +29,7 @@ const MAX_ENCODING_SIZE: usize = 9;
/// - 5 for 0x10000..=(2^32-1)
/// - 9 otherwise.
#[inline]
pub fn encoded_size(value: impl ToU64) -> usize {
encoded_size_const(value.to_u64())
}
pub fn encoded_size(value: impl ToU64) -> usize { encoded_size_const(value.to_u64()) }
/// Returns the number of bytes used to encode this `CompactSize` value (in const context).
///

View File

@ -32,8 +32,8 @@ extern crate serde;
pub mod block;
#[cfg(feature = "alloc")]
pub mod locktime;
pub mod opcodes;
pub mod merkle_tree;
pub mod opcodes;
pub mod pow;
pub mod sequence;
pub mod transaction;

View File

@ -197,10 +197,7 @@ impl fmt::Display for Version {
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for OutPoint {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(OutPoint{
txid: Txid::arbitrary(u)?,
vout: u32::arbitrary(u)?
})
Ok(OutPoint { txid: Txid::arbitrary(u)?, vout: u32::arbitrary(u)? })
}
}