Skip to content

Commit

Permalink
Use gas limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 20, 2023
1 parent db2a86c commit a4e9cac
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ethereum/write_oz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl WriteProvider {
}
ParsedOptions::TxSitter(tx_sitter_options) => {
tracing::info!("Initializing TxSitter");
Arc::new(TxSitter::new(tx_sitter_options.tx_sitter_url))
Arc::new(TxSitter::new(&tx_sitter_options))
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/ethereum/write_oz/openzeppelin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@ impl OzRelay {
/// take multiple seconds to restart.
pub async fn send_transaction(
&self,
tx: TypedTransaction,
mut tx: TypedTransaction,
only_once: bool,
) -> Result<TransactionId, TxError> {
let mut tx = tx.clone();
if let Some(gas_limit) = self.gas_limit {
tx.set_gas(gas_limit);
}
Expand Down
13 changes: 9 additions & 4 deletions src/ethereum/write_oz/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub struct Options {

#[clap(long, env)]
pub tx_sitter_address: Option<H160>,

#[clap(long, env)]
pub tx_sitter_gas_limit: Option<u64>,
}

fn duration_from_str(value: &str) -> Result<Duration, ParseIntError> {
Expand Down Expand Up @@ -134,22 +137,24 @@ impl<'a> TryFrom<&'a Options> for OzOptions {
}

pub struct TxSitterOptions {
pub tx_sitter_url: String,
pub tx_sitter_address: H160,
pub tx_sitter_url: String,
pub tx_sitter_address: H160,
pub tx_sitter_gas_limit: Option<u64>,
}

impl<'a> TryFrom<&'a Options> for TxSitterOptions {
type Error = anyhow::Error;

fn try_from(value: &'a Options) -> Result<Self, Self::Error> {
Ok(Self {
tx_sitter_url: value
tx_sitter_url: value
.tx_sitter_url
.clone()
.ok_or_else(|| anyhow!("Missing tx_sitter_url"))?,
tx_sitter_address: value
tx_sitter_address: value
.tx_sitter_address
.ok_or_else(|| anyhow!("Missing tx_sitter_address"))?,
tx_sitter_gas_limit: value.tx_sitter_gas_limit,
})
}
}
15 changes: 11 additions & 4 deletions src/ethereum/write_oz/tx_sitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ use tx_sitter_client::data::{SendTxRequest, TransactionPriority, TxStatus};
use tx_sitter_client::TxSitterClient;

use super::inner::{Inner, TransactionResult};
use super::options::TxSitterOptions;
use crate::ethereum::write::TransactionId;
use crate::ethereum::TxError;

const MINING_TIMEOUT: Duration = Duration::from_secs(60);

pub struct TxSitter {
client: TxSitterClient,
client: TxSitterClient,
gas_limit: Option<u64>,
}

impl TxSitter {
pub fn new(url: impl ToString) -> Self {
pub fn new(options: &TxSitterOptions) -> Self {
Self {
client: TxSitterClient::new(url),
client: TxSitterClient::new(&options.tx_sitter_url),
gas_limit: options.tx_sitter_gas_limit,
}
}

Expand Down Expand Up @@ -51,9 +54,13 @@ impl TxSitter {
impl Inner for TxSitter {
async fn send_transaction(
&self,
tx: TypedTransaction,
mut tx: TypedTransaction,
_only_once: bool,
) -> Result<TransactionId, TxError> {
if let Some(gas_limit) = self.gas_limit {
tx.set_gas(gas_limit);
}

// TODO: Handle only_once
let tx = self
.client
Expand Down

0 comments on commit a4e9cac

Please sign in to comment.