Skip to content

Commit 99425df

Browse files
Merge pull request #65 from dashpay/chore/fmt
chore: fmt
2 parents fcc7c22 + f9cc6b2 commit 99425df

File tree

129 files changed

+3829
-1469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+3829
-1469
lines changed

dash/examples/bip32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ extern crate dashcore;
33
use std::str::FromStr;
44
use std::{env, process};
55

6-
use dashcore::PublicKey;
76
use dashcore::address::Address;
87
use dashcore::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, ExtendedPubKey};
98
use dashcore::hashes::hex::FromHex;
10-
use dashcore::secp256k1::Secp256k1;
119
use dashcore::secp256k1::ffi::types::AlignedType;
10+
use dashcore::secp256k1::Secp256k1;
11+
use dashcore::PublicKey;
1212

1313
fn main() {
1414
// This example derives root xprv from a 32-byte seed,

dash/examples/ecdsa-psbt.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,19 @@ impl ColdStorage {
124124
let input_xpriv = master_xpriv.derive_priv(secp, &path)?;
125125
let input_xpub = ExtendedPubKey::from_priv(secp, &input_xpriv);
126126

127-
let wallet = ColdStorage { master_xpriv, master_xpub };
127+
let wallet = ColdStorage {
128+
master_xpriv,
129+
master_xpub,
130+
};
128131
let fingerprint = wallet.master_fingerprint();
129132

130133
Ok((wallet, fingerprint, account_0_xpub, input_xpub))
131134
}
132135

133136
/// Returns the fingerprint for the master extended public key.
134-
fn master_fingerprint(&self) -> Fingerprint { self.master_xpub.fingerprint() }
137+
fn master_fingerprint(&self) -> Fingerprint {
138+
self.master_xpub.fingerprint()
139+
}
135140

136141
/// Signs `psbt` with this signer.
137142
fn sign_psbt<C: Signing>(&self, secp: &Secp256k1<C>, mut psbt: Psbt) -> Result<Psbt> {
@@ -169,7 +174,11 @@ impl WatchOnly {
169174
input_xpub: ExtendedPubKey,
170175
master_fingerprint: Fingerprint,
171176
) -> Self {
172-
WatchOnly { account_0_xpub, input_xpub, master_fingerprint }
177+
WatchOnly {
178+
account_0_xpub,
179+
input_xpub,
180+
master_fingerprint,
181+
}
173182
}
174183

175184
/// Creates the PSBT, in BIP174 parlance this is the 'Creater'.
@@ -184,13 +193,19 @@ impl WatchOnly {
184193
version: 2,
185194
lock_time: 0,
186195
input: vec![TxIn {
187-
previous_output: OutPoint { txid: INPUT_UTXO_TXID.parse()?, vout: INPUT_UTXO_VOUT },
196+
previous_output: OutPoint {
197+
txid: INPUT_UTXO_TXID.parse()?,
198+
vout: INPUT_UTXO_VOUT,
199+
},
188200
script_sig: ScriptBuf::new(),
189201
sequence: u32::MAX, // Disable LockTime and RBF.
190202
witness: Witness::default(),
191203
}],
192204
output: vec![
193-
TxOut { value: to_amount.to_sat(), script_pubkey: to_address.script_pubkey() },
205+
TxOut {
206+
value: to_amount.to_sat(),
207+
script_pubkey: to_address.script_pubkey(),
208+
},
194209
TxOut {
195210
value: change_amount.to_sat(),
196211
script_pubkey: change_address.script_pubkey(),
@@ -206,7 +221,10 @@ impl WatchOnly {
206221

207222
/// Updates the PSBT, in BIP174 parlance this is the 'Updater'.
208223
fn update_psbt(&self, mut psbt: Psbt) -> Result<Psbt> {
209-
let mut input = Input { witness_utxo: Some(previous_output()), ..Default::default() };
224+
let mut input = Input {
225+
witness_utxo: Some(previous_output()),
226+
..Default::default()
227+
};
210228

211229
let pk = self.input_xpub.to_pub();
212230
let wpkh = pk.wpubkey_hash().expect("a compressed pubkey");
@@ -281,15 +299,22 @@ fn previous_output() -> TxOut {
281299
.expect("failed to parse input utxo scriptPubkey");
282300
let amount = Amount::from_str(INPUT_UTXO_VALUE).expect("failed to parse input utxo value");
283301

284-
TxOut { value: amount.to_sat(), script_pubkey }
302+
TxOut {
303+
value: amount.to_sat(),
304+
script_pubkey,
305+
}
285306
}
286307

287308
struct Error(Box<dyn std::error::Error>);
288309

289310
impl<T: std::error::Error + 'static> From<T> for Error {
290-
fn from(e: T) -> Self { Error(Box::new(e)) }
311+
fn from(e: T) -> Self {
312+
Error(Box::new(e))
313+
}
291314
}
292315

293316
impl fmt::Debug for Error {
294-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.0, f) }
317+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
318+
fmt::Debug::fmt(&self.0, f)
319+
}
295320
}

dash/examples/handshake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpStream};
55
use std::time::{SystemTime, UNIX_EPOCH};
66
use std::{env, process};
77

8-
use dashcore::consensus::{Decodable, encode};
8+
use dashcore::consensus::{encode, Decodable};
99
use dashcore::network::{address, constants, message, message_network};
1010
use dashcore::secp256k1;
1111
use dashcore::secp256k1::rand::Rng;

dash/examples/taproot-psbt.rs

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ use dashcore::secp256k1::Secp256k1;
8888
use dashcore::sighash::{self, SighashCache, TapSighash, TapSighashType};
8989
use dashcore::taproot::{self, LeafVersion, TapLeafHash, TaprootBuilder, TaprootSpendInfo};
9090
use dashcore::{
91-
Address, Amount, Network, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Witness, absolute,
92-
script,
91+
absolute, script, Address, Amount, Network, OutPoint, ScriptBuf, Transaction, TxIn, TxOut,
92+
Witness,
9393
};
9494

9595
fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -119,8 +119,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
119119
// Set these fields with valid data for the UTXO from step 5 above
120120
UTXO_1,
121121
vec![
122-
TxOut { value: amount_to_send_in_sats, script_pubkey: to_address.script_pubkey() },
123-
TxOut { value: change_amount, script_pubkey: change_address.script_pubkey() },
122+
TxOut {
123+
value: amount_to_send_in_sats,
124+
script_pubkey: to_address.script_pubkey(),
125+
},
126+
TxOut {
127+
value: change_amount,
128+
script_pubkey: change_address.script_pubkey(),
129+
},
124130
],
125131
)?);
126132
println!(
@@ -234,7 +240,10 @@ fn generate_bip86_key_spend_tx(
234240
version: 2,
235241
lock_time: 0,
236242
input: vec![TxIn {
237-
previous_output: OutPoint { txid: input_utxo.txid.parse()?, vout: input_utxo.vout },
243+
previous_output: OutPoint {
244+
txid: input_utxo.txid.parse()?,
245+
vout: input_utxo.vout,
246+
},
238247
script_sig: ScriptBuf::new(),
239248
sequence: 0xFFFFFFFF, // Ignore nSequence.
240249
witness: Witness::default(),
@@ -262,7 +271,10 @@ fn generate_bip86_key_spend_tx(
262271
.expect("failed to parse input utxo scriptPubkey");
263272
let amount = Amount::from_sat(from_amount);
264273

265-
Some(TxOut { value: amount.to_sat(), script_pubkey })
274+
Some(TxOut {
275+
value: amount.to_sat(),
276+
script_pubkey,
277+
})
266278
},
267279
tap_key_origins: origins,
268280
..Default::default()
@@ -380,7 +392,10 @@ impl BenefactorWallet {
380392
lock_time: absolute::LockTime,
381393
input_utxo: P2trUtxo,
382394
) -> Result<(Transaction, Psbt), Box<dyn std::error::Error>> {
383-
if let ChildNumber::Normal { index } = self.next {
395+
if let ChildNumber::Normal {
396+
index,
397+
} = self.next
398+
{
384399
if index > 0 && self.current_spend_info.is_some() {
385400
return Err("Transaction already exists, use refresh_inheritance_timelock to refresh the timelock".into());
386401
}
@@ -414,15 +429,21 @@ impl BenefactorWallet {
414429
&self.secp,
415430
self.master_xpriv,
416431
input_utxo,
417-
vec![TxOut { script_pubkey: script_pubkey.clone(), value }],
432+
vec![TxOut {
433+
script_pubkey: script_pubkey.clone(),
434+
value,
435+
}],
418436
)?;
419437

420438
// CREATOR + UPDATER
421439
let next_tx = Transaction {
422440
version: 2,
423441
lock_time: lock_time.to_consensus_u32(),
424442
input: vec![TxIn {
425-
previous_output: OutPoint { txid: tx.txid(), vout: 0 },
443+
previous_output: OutPoint {
444+
txid: tx.txid(),
445+
vout: 0,
446+
},
426447
script_sig: ScriptBuf::new(),
427448
sequence: 0xFFFFFFFD, // enable locktime and opt-in RBF
428449
witness: Witness::default(),
@@ -452,7 +473,10 @@ impl BenefactorWallet {
452473
let script_pubkey = script_pubkey;
453474
let amount = Amount::from_sat(value);
454475

455-
Some(TxOut { value: amount.to_sat(), script_pubkey })
476+
Some(TxOut {
477+
value: amount.to_sat(),
478+
script_pubkey,
479+
})
456480
},
457481
tap_key_origins: origins,
458482
tap_merkle_root: taproot_spend_info.merkle_root(),
@@ -509,8 +533,10 @@ impl BenefactorWallet {
509533
taproot_spend_info.merkle_root(),
510534
);
511535

512-
psbt.unsigned_tx.output =
513-
vec![TxOut { script_pubkey: output_script_pubkey.clone(), value: output_value }];
536+
psbt.unsigned_tx.output = vec![TxOut {
537+
script_pubkey: output_script_pubkey.clone(),
538+
value: output_value,
539+
}];
514540
psbt.outputs = vec![Output::default()];
515541
psbt.unsigned_tx.lock_time = 0;
516542

@@ -562,15 +588,21 @@ impl BenefactorWallet {
562588
// EXTRACTOR
563589
let tx = psbt.extract_tx();
564590
tx.verify(|_| {
565-
Some(TxOut { value: input_value, script_pubkey: output_script_pubkey.clone() })
591+
Some(TxOut {
592+
value: input_value,
593+
script_pubkey: output_script_pubkey.clone(),
594+
})
566595
})
567596
.expect("failed to verify transaction");
568597

569598
let next_tx = Transaction {
570599
version: 2,
571600
lock_time: lock_time.to_consensus_u32(),
572601
input: vec![TxIn {
573-
previous_output: OutPoint { txid: tx.txid(), vout: 0 },
602+
previous_output: OutPoint {
603+
txid: tx.txid(),
604+
vout: 0,
605+
},
574606
script_sig: ScriptBuf::new(),
575607
sequence: 0xFFFFFFFD, // enable locktime and opt-in RBF
576608
witness: Witness::default(),
@@ -598,7 +630,10 @@ impl BenefactorWallet {
598630
let script_pubkey = output_script_pubkey;
599631
let amount = Amount::from_sat(output_value);
600632

601-
Some(TxOut { value: amount.to_sat(), script_pubkey })
633+
Some(TxOut {
634+
value: amount.to_sat(),
635+
script_pubkey,
636+
})
602637
},
603638
tap_key_origins: origins,
604639
tap_merkle_root: taproot_spend_info.merkle_root(),
@@ -628,7 +663,10 @@ struct BeneficiaryWallet {
628663

629664
impl BeneficiaryWallet {
630665
fn new(master_xpriv: ExtendedPrivKey) -> Result<Self, Box<dyn std::error::Error>> {
631-
Ok(Self { master_xpriv, secp: Secp256k1::new() })
666+
Ok(Self {
667+
master_xpriv,
668+
secp: Secp256k1::new(),
669+
})
632670
}
633671

634672
fn master_xpub(&self) -> ExtendedPubKey {
@@ -707,7 +745,10 @@ impl BeneficiaryWallet {
707745
// EXTRACTOR
708746
let tx = psbt.extract_tx();
709747
tx.verify(|_| {
710-
Some(TxOut { value: input_value, script_pubkey: input_script_pubkey.clone() })
748+
Some(TxOut {
749+
value: input_value,
750+
script_pubkey: input_script_pubkey.clone(),
751+
})
711752
})
712753
.expect("failed to verify transaction");
713754

@@ -746,7 +787,10 @@ fn sign_psbt_taproot(
746787

747788
let sig = secp.sign_schnorr(&hash.into(), &keypair);
748789

749-
let final_signature = taproot::Signature { sig, hash_ty };
790+
let final_signature = taproot::Signature {
791+
sig,
792+
hash_ty,
793+
};
750794

751795
if let Some(lh) = leaf_hash {
752796
psbt_input.tap_script_sigs.insert((pubkey, lh), final_signature);

0 commit comments

Comments
 (0)