diff --git a/bitcoin/examples/bip32.rs b/bitcoin/examples/bip32.rs index 7cde6c646..41f3791ea 100644 --- a/bitcoin/examples/bip32.rs +++ b/bitcoin/examples/bip32.rs @@ -22,7 +22,7 @@ fn main() { } let seed_hex = &args[1]; - println!("Seed: {}", seed_hex); + println!("Seed: {seed_hex}"); println!("Using mainnet network"); let seed = Vec::from_hex(seed_hex).unwrap(); @@ -34,19 +34,19 @@ fn main() { // calculate root key from seed let root = Xpriv::new_master(NetworkKind::Main, &seed); - println!("Root key: {}", root); + println!("Root key: {root}"); // derive child xpub let path = "84h/0h/0h".parse::().unwrap(); let child = root.derive_xpriv(&secp, &path).expect("only deriving three steps"); - println!("Child at {}: {}", path, child); + println!("Child at {path}: {child}"); let xpub = Xpub::from_xpriv(&secp, &child); - println!("Public key at {}: {}", path, xpub); + println!("Public key at {path}: {xpub}"); // generate first receiving address at m/0/0 // manually creating indexes this time let zero = ChildNumber::ZERO_NORMAL; let public_key = xpub.derive_xpub(&secp, &[zero, zero]).unwrap().public_key; let address = Address::p2wpkh(CompressedPublicKey(public_key), KnownHrp::Mainnet); - println!("First receiving address: {}", address); + println!("First receiving address: {address}"); } diff --git a/bitcoin/examples/create-p2wpkh-address.rs b/bitcoin/examples/create-p2wpkh-address.rs index b8ec758f8..e92ffe531 100644 --- a/bitcoin/examples/create-p2wpkh-address.rs +++ b/bitcoin/examples/create-p2wpkh-address.rs @@ -19,6 +19,6 @@ fn main() { // Create a Bitcoin P2WPKH address. let address = Address::p2wpkh(public_key, Network::Bitcoin); - println!("Private Key: {}", private_key); - println!("Address: {}", address); + println!("Private Key: {private_key}"); + println!("Address: {address}"); } diff --git a/bitcoin/examples/ecdsa-psbt-simple.rs b/bitcoin/examples/ecdsa-psbt-simple.rs index 21b9f6cad..73f209bb2 100644 --- a/bitcoin/examples/ecdsa-psbt-simple.rs +++ b/bitcoin/examples/ecdsa-psbt-simple.rs @@ -244,8 +244,8 @@ fn main() { // BOOM! Transaction signed and ready to broadcast. let signed_tx = psbt.extract_tx().expect("valid transaction"); let serialized_signed_tx = consensus::encode::serialize_hex(&signed_tx); - println!("Transaction Details: {:#?}", signed_tx); + println!("Transaction Details: {signed_tx:#?}"); // check with: // bitcoin-cli decoderawtransaction true - println!("Raw Transaction: {}", serialized_signed_tx); + println!("Raw Transaction: {serialized_signed_tx}"); } diff --git a/bitcoin/examples/ecdsa-psbt.rs b/bitcoin/examples/ecdsa-psbt.rs index 1abdf6751..0ac297654 100644 --- a/bitcoin/examples/ecdsa-psbt.rs +++ b/bitcoin/examples/ecdsa-psbt.rs @@ -87,7 +87,7 @@ fn main() -> Result<()> { tx.verify(|_| Some(previous_output())).expect("failed to verify transaction"); let hex = encode::serialize_hex(&tx); - println!("You should now be able to broadcast the following transaction: \n\n{}", hex); + println!("You should now be able to broadcast the following transaction: \n\n{hex}"); Ok(()) } diff --git a/bitcoin/examples/handshake.rs b/bitcoin/examples/handshake.rs index db5a4fb17..4382de02a 100644 --- a/bitcoin/examples/handshake.rs +++ b/bitcoin/examples/handshake.rs @@ -19,7 +19,7 @@ fn main() { let str_address = &args[1]; let address: SocketAddr = str_address.parse().unwrap_or_else(|error| { - eprintln!("error parsing address: {:?}", error); + eprintln!("error parsing address: {error:?}"); process::exit(1); }); diff --git a/bitcoin/examples/script.rs b/bitcoin/examples/script.rs index de72033d4..ee8be6ee0 100644 --- a/bitcoin/examples/script.rs +++ b/bitcoin/examples/script.rs @@ -22,14 +22,14 @@ fn main() { assert_eq!(decoded, script_code); // Writes the script as human-readable eg, OP_DUP OP_HASH160 OP_PUSHBYTES_20 ... - println!("human-readable script: {}", script_code); + println!("human-readable script: {script_code}"); // We do not implement parsing scripts from human-readable format. // let decoded = s.parse::().unwrap(); // This is equivalent to consensus encoding i.e., includes the length prefix. - let hex_lower_hex_trait = format!("{:x}", script_code); - println!("hex created using `LowerHex`: {}", hex_lower_hex_trait); + let hex_lower_hex_trait = format!("{script_code:x}"); + println!("hex created using `LowerHex`: {hex_lower_hex_trait}"); // The `deserialize_hex` function requires the length prefix. assert_eq!(encode::deserialize_hex::(&hex_lower_hex_trait).unwrap(), script_code); @@ -43,7 +43,7 @@ fn main() { // This is consensus encoding i.e., includes the length prefix. let hex_inherent = script_code.to_hex_string(); // Defined in `ScriptExt`. - println!("hex created using inherent `to_hex_string`: {}", hex_inherent); + println!("hex created using inherent `to_hex_string`: {hex_inherent}"); // The inverse of `to_hex_string` is `from_hex`. let decoded = ScriptBuf::from_hex(&hex_inherent).unwrap(); // Defined in `ScriptBufExt`. @@ -54,7 +54,7 @@ fn main() { // We also support encode/decode using `consensus::encode` functions. let encoded = encode::serialize_hex(&script_code); - println!("hex created using consensus::encode::serialize_hex: {}", encoded); + println!("hex created using consensus::encode::serialize_hex: {encoded}"); let decoded: ScriptBuf = encode::deserialize_hex(&encoded).unwrap(); assert_eq!(decoded, script_code); diff --git a/bitcoin/examples/sighash.rs b/bitcoin/examples/sighash.rs index 1055a52f7..bfa82216e 100644 --- a/bitcoin/examples/sighash.rs +++ b/bitcoin/examples/sighash.rs @@ -24,7 +24,7 @@ fn compute_sighash_p2wpkh(raw_tx: &[u8], inp_idx: usize, amount: Amount) { let tx: Transaction = consensus::deserialize(raw_tx).unwrap(); let inp = &tx.input[inp_idx]; let witness = &inp.witness; - println!("Witness: {:?}", witness); + println!("Witness: {witness:?}"); // BIP-141: The witness must consist of exactly 2 items (≤ 520 bytes each). The first one a // signature, and the second one a public key. @@ -38,16 +38,16 @@ fn compute_sighash_p2wpkh(raw_tx: &[u8], inp_idx: usize, amount: Amount) { //this is nothing but a standard P2PKH script OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG: let pk = CompressedPublicKey::from_slice(pk_bytes).expect("failed to parse pubkey"); let wpkh = pk.wpubkey_hash(); - println!("Script pubkey hash: {:x}", wpkh); + println!("Script pubkey hash: {wpkh:x}"); let spk = ScriptBuf::new_p2wpkh(wpkh); let mut cache = sighash::SighashCache::new(&tx); let sighash = cache .p2wpkh_signature_hash(inp_idx, &spk, amount, sig.sighash_type) .expect("failed to compute sighash"); - println!("SegWit p2wpkh sighash: {:x}", sighash); + println!("SegWit p2wpkh sighash: {sighash:x}"); let msg = secp256k1::Message::from(sighash); - println!("Message is {:x}", msg); + println!("Message is {msg:x}"); let secp = secp256k1::Secp256k1::verification_only(); pk.verify(&secp, msg, sig).unwrap() } @@ -63,7 +63,7 @@ fn compute_sighash_legacy(raw_tx: &[u8], inp_idx: usize, script_pubkey_bytes_opt let tx: Transaction = consensus::deserialize(raw_tx).unwrap(); let inp = &tx.input[inp_idx]; let script_sig = &inp.script_sig; - println!("scriptSig is: {}", script_sig); + println!("scriptSig is: {script_sig}"); let cache = sighash::SighashCache::new(&tx); //In the P2SH case we get scriptPubKey from scriptSig of the spending input. //The scriptSig that corresponds to an M of N multisig should be: PUSHBYTES_0 PUSHBYTES_K0 ... PUSHBYTES_Km PUSHBYTES_X @@ -83,8 +83,7 @@ fn compute_sighash_legacy(raw_tx: &[u8], inp_idx: usize, script_pubkey_bytes_opt let pushbytes_0 = instructions.remove(0).unwrap(); assert!( pushbytes_0.push_bytes().unwrap().as_bytes().is_empty(), - "first in ScriptSig must be PUSHBYTES_0 got {:?}", - pushbytes_0 + "first in ScriptSig must be PUSHBYTES_0 got {pushbytes_0:?}" ); //All other scriptSig instructions must be signatures @@ -109,7 +108,7 @@ fn compute_sighash_p2wsh(raw_tx: &[u8], inp_idx: usize, amount: Amount) { let tx: Transaction = consensus::deserialize(raw_tx).unwrap(); let inp = &tx.input[inp_idx]; let witness = &inp.witness; - println!("witness {:?}", witness); + println!("witness {witness:?}"); //last element is called witnessScript according to BIP141. It supersedes scriptPubKey. let witness_script_bytes: &[u8] = witness.last().expect("out of bounds"); @@ -122,7 +121,7 @@ fn compute_sighash_p2wsh(raw_tx: &[u8], inp_idx: usize, amount: Amount) { let sig = ecdsa::Signature::from_slice(sig_bytes).expect("failed to parse sig"); let sig_len = sig_bytes.len() - 1; //last byte is EcdsaSighashType sighash flag //ECDSA signature in DER format lengths are between 70 and 72 bytes - assert!((70..=72).contains(&sig_len), "signature length {} out of bounds", sig_len); + assert!((70..=72).contains(&sig_len), "signature length {sig_len} out of bounds"); //here we assume that all sighash_flags are the same. Can they be different? let sighash = cache .p2wsh_signature_hash(inp_idx, witness_script, amount, sig.sighash_type) diff --git a/bitcoin/examples/sign-tx-segwit-v0.rs b/bitcoin/examples/sign-tx-segwit-v0.rs index b163a24b0..e9a49385d 100644 --- a/bitcoin/examples/sign-tx-segwit-v0.rs +++ b/bitcoin/examples/sign-tx-segwit-v0.rs @@ -82,7 +82,7 @@ fn main() { let tx = sighasher.into_transaction(); // BOOM! Transaction signed and ready to broadcast. - println!("{:#?}", tx); + println!("{tx:#?}"); } /// An example of keys controlled by the transaction sender. diff --git a/bitcoin/examples/sign-tx-taproot.rs b/bitcoin/examples/sign-tx-taproot.rs index 2abb4d580..00cedd4f1 100644 --- a/bitcoin/examples/sign-tx-taproot.rs +++ b/bitcoin/examples/sign-tx-taproot.rs @@ -81,7 +81,7 @@ fn main() { let tx = sighasher.into_transaction(); // BOOM! Transaction signed and ready to broadcast. - println!("{:#?}", tx); + println!("{tx:#?}"); } /// An example of keys controlled by the transaction sender. diff --git a/bitcoin/examples/taproot-psbt-simple.rs b/bitcoin/examples/taproot-psbt-simple.rs index d2ca8f9e2..0105dc59f 100644 --- a/bitcoin/examples/taproot-psbt-simple.rs +++ b/bitcoin/examples/taproot-psbt-simple.rs @@ -244,8 +244,8 @@ fn main() { // BOOM! Transaction signed and ready to broadcast. let signed_tx = psbt.extract_tx().expect("valid transaction"); let serialized_signed_tx = consensus::encode::serialize_hex(&signed_tx); - println!("Transaction Details: {:#?}", signed_tx); + println!("Transaction Details: {signed_tx:#?}"); // check with: // bitcoin-cli decoderawtransaction true - println!("Raw Transaction: {}", serialized_signed_tx); + println!("Raw Transaction: {serialized_signed_tx}"); } diff --git a/bitcoin/examples/taproot-psbt.rs b/bitcoin/examples/taproot-psbt.rs index 75bb0b8b2..040b0857e 100644 --- a/bitcoin/examples/taproot-psbt.rs +++ b/bitcoin/examples/taproot-psbt.rs @@ -125,8 +125,7 @@ fn main() -> Result<(), Box> { ], )?); println!( - "\nYou should now be able to broadcast the following transaction: \n\n{}", - tx_hex_string + "\nYou should now be able to broadcast the following transaction: \n\n{tx_hex_string}" ); println!("\nEND EXAMPLE 1\n"); @@ -147,7 +146,7 @@ fn main() -> Result<(), Box> { )?; let tx_hex = encode::serialize_hex(&tx); - println!("Inheritance funding tx hex:\n\n{}", tx_hex); + println!("Inheritance funding tx hex:\n\n{tx_hex}"); // You can now broadcast the transaction hex: // bt sendrawtransaction ... // @@ -160,7 +159,7 @@ fn main() -> Result<(), Box> { to_address, )?; let spending_tx_hex = encode::serialize_hex(&spending_tx); - println!("\nInheritance spending tx hex:\n\n{}", spending_tx_hex); + println!("\nInheritance spending tx hex:\n\n{spending_tx_hex}"); // If you try to broadcast now, the transaction will be rejected as it is timelocked. // First mine 900 blocks so we're sure we are over the 1000 block locktime: // bt generatetoaddress 900 $(bt-benefactor getnewaddress '' 'bech32m') @@ -185,7 +184,7 @@ fn main() -> Result<(), Box> { )?; let tx_hex = encode::serialize_hex(&tx); - println!("Inheritance funding tx hex:\n\n{}", tx_hex); + println!("Inheritance funding tx hex:\n\n{tx_hex}"); // You can now broadcast the transaction hex: // bt sendrawtransaction ... // @@ -200,7 +199,7 @@ fn main() -> Result<(), Box> { let (tx, _) = benefactor.refresh_tx(1000)?; let tx_hex = encode::serialize_hex(&tx); - println!("\nRefreshed inheritance tx hex:\n\n{}\n", tx_hex); + println!("\nRefreshed inheritance tx hex:\n\n{tx_hex}\n"); println!("\nEND EXAMPLE 3\n"); println!("----------------\n");