Sitelet https://github.com/SharkHand3/examples/commit/026a2a6554a9aa232f2d55947c267694531c0be0
Skip to content

Commit 026a2a6

Browse files
committed
nit: use hex! macro and remove 1 confirmations, other examples are clear enough
1 parent 1e68146 commit 026a2a6

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎examples/wallets/examples/create_keystore.rs‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ async fn main() -> Result<()> {
1212
let mut rng = thread_rng();
1313

1414
// Private key of Alice, the first default Anvil account.
15-
let private_key =
16-
hex::decode("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")?;
15+
let private_key = hex!("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80");
1716

1817
// Password to encrypt the keystore file with.
1918
let password = "test";
@@ -22,26 +21,26 @@ async fn main() -> Result<()> {
2221
let (wallet, file_path) =
2322
Wallet::encrypt_keystore(&dir, &mut rng, private_key, password, None).unwrap();
2423

25-
let key_file_path = dir.path().join(file_path.clone());
24+
let keystore_file_path = dir.path().join(file_path.clone());
2625

27-
println!("Wrote keystore for {:?} to {:?}", wallet.address(), key_file_path);
26+
println!("Wrote keystore for {:?} to {:?}", wallet.address(), keystore_file_path);
2827

2928
// Read the keystore file back.
30-
let recovered_wallet = Wallet::decrypt_keystore(key_file_path.clone(), password)?;
29+
let recovered_wallet = Wallet::decrypt_keystore(keystore_file_path.clone(), password)?;
3130

3231
println!(
3332
"Read keystore from {:?}, recovered address: {:?}",
34-
key_file_path,
33+
keystore_file_path,
3534
recovered_wallet.address()
3635
);
3736

3837
// Assert that the address of the original key and the recovered key are the same.
3938
assert_eq!(wallet.address(), recovered_wallet.address());
4039

4140
// Display the contents of the keystore file.
42-
let keystore_contents = read_to_string(key_file_path)?;
41+
let keystore_contents = read_to_string(keystore_file_path)?;
4342

44-
print!("Keystore file contents: {:?}\n", keystore_contents);
43+
println!("Keystore file contents: {:?}", keystore_contents);
4544

4645
Ok(())
4746
}

‎examples/wallets/examples/keystore_signer.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use alloy::{
99
signers::wallet::Wallet,
1010
};
1111
use eyre::Result;
12+
use std::path::Path;
1213

1314
#[tokio::main]
1415
async fn main() -> Result<()> {
@@ -20,8 +21,8 @@ async fn main() -> Result<()> {
2021

2122
// Set up a wallet using Alice's keystore file.
2223
// The private key belongs to Alice, the first default Anvil account.
23-
let wallet =
24-
Wallet::decrypt_keystore("./examples/wallets/examples/keystore/alice.json", password)?;
24+
let keystore_file_path = Path::new("./examples/wallets/examples/keystore/alice.json");
25+
let wallet = Wallet::decrypt_keystore(keystore_file_path, password)?;
2526

2627
// Create a provider with the signer.
2728
let http = anvil.endpoint().parse()?;
@@ -40,7 +41,7 @@ async fn main() -> Result<()> {
4041
};
4142

4243
// Broadcast the transaction and wait for the receipt.
43-
let receipt = provider.send_transaction(tx).await?.with_confirmations(1).get_receipt().await?;
44+
let receipt = provider.send_transaction(tx).await?.get_receipt().await?;
4445

4546
println!("Send transaction: {:?}", receipt.transaction_hash);
4647

‎examples/wallets/examples/private_key_signer.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async fn main() -> Result<()> {
3535
};
3636

3737
// Broadcast the transaction and wait for the receipt.
38-
let receipt = provider.send_transaction(tx).await?.with_confirmations(1).get_receipt().await?;
38+
let receipt = provider.send_transaction(tx).await?.get_receipt().await?;
3939

4040
println!("Send transaction: {:?}", receipt.transaction_hash);
4141

0 commit comments

Comments
 (0)