Skip to content

Commit

Permalink
chore: update send command impl
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Nov 1, 2024
1 parent 9a11980 commit 9307f14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
4 changes: 2 additions & 2 deletions bolt-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ pub struct SendCommand {

/// The max fee per gas in gwei.
#[clap(long, env = "MAX_FEE")]
pub max_fee: Option<String>,
pub max_fee: Option<u128>,

/// The max priority fee per gas in gwei.
#[clap(long, env = "PRIORITY_FEE", default_value = "2")]
pub priority_fee: String,
pub priority_fee: u128,

/// If set, the transaction will target the devnet environment.
/// This is only used in Kurtosis for internal testing purposes
Expand Down
29 changes: 9 additions & 20 deletions bolt-cli/src/commands/send.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::time::Duration;

use alloy::{
consensus::{BlobTransactionSidecar, SidecarBuilder, SimpleCoder, Transaction},
consensus::{
constants::GWEI_TO_WEI, BlobTransactionSidecar, SidecarBuilder, SimpleCoder, Transaction,
},
eips::eip2718::Encodable2718,
network::{EthereumWallet, TransactionBuilder, TransactionBuilder4844},
primitives::{keccak256, utils::parse_units, Address, B256, U256},
primitives::{keccak256, Address, B256, U256},
providers::{ProviderBuilder, SendableTx},
rpc::types::TransactionRequest,
signers::{local::PrivateKeySigner, Signer},
Expand All @@ -25,29 +27,16 @@ impl SendCommand {
/// Run the `send` command.
pub async fn run(self) -> Result<()> {
let wallet: PrivateKeySigner = self.private_key.parse().wrap_err("invalid private key")?;
let max_fee = self.max_fee.as_ref().map(|fee| {
parse_units(fee, "gwei").expect("Correct unit").try_into().expect("Correct unit")
});

let priority_fee = parse_units(&self.priority_fee, "gwei")
.expect("Correct unit")
.try_into()
.expect("Correct unit");

if self.devnet {
self.send_devnet_transaction(&wallet).await
} else {
self.send_transaction(&wallet, max_fee, priority_fee).await
self.send_transaction(&wallet).await
}
}

/// Send a transaction.
async fn send_transaction(
self,
wallet: &PrivateKeySigner,
max_fee: Option<u128>,
priority_fee: u128,
) -> Result<()> {
async fn send_transaction(self, wallet: &PrivateKeySigner) -> Result<()> {
let transaction_signer = EthereumWallet::from(wallet.clone());
let provider = ProviderBuilder::new()
.with_recommended_fillers()
Expand Down Expand Up @@ -86,11 +75,11 @@ impl SendCommand {
for _ in 0..self.count {
// generate a simple self-transfer of ETH
let mut req = create_tx_request(wallet.address(), self.blob);
if let Some(max_fee) = max_fee {
req.set_max_fee_per_gas(max_fee);
if let Some(max_fee) = self.max_fee {
req.set_max_fee_per_gas(max_fee * GWEI_TO_WEI as u128);
}

req.set_max_priority_fee_per_gas(priority_fee);
req.set_max_priority_fee_per_gas(self.priority_fee * GWEI_TO_WEI as u128);

if let Some(next_nonce) = next_nonce {
req.set_nonce(next_nonce);
Expand Down

0 comments on commit 9307f14

Please sign in to comment.