Skip to content

Commit

Permalink
manually set gas
Browse files Browse the repository at this point in the history
  • Loading branch information
jbowen93 committed Feb 28, 2022
1 parent 4fd9c78 commit e79f4b6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ethers-contract/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ impl<M: Middleware> Deployer<M> {
pub async fn send_with_receipt(
self,
) -> Result<(Contract<M>, TransactionReceipt), ContractError<M>> {
println!("factory.rs send");

let pending_tx = self
.client
.send_transaction(self.tx, Some(self.block.into()))
.await
.map_err(ContractError::MiddlewareError)?;

println!("passed self.client.send_transaction");

// TODO: Should this be calculated "optimistically" by address/nonce?
let receipt = pending_tx
.confirmations(self.confs)
Expand Down
22 changes: 22 additions & 0 deletions ethers-middleware/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ where
tx: &mut TypedTransaction,
block: Option<BlockId>,
) -> Result<(), Self::Error> {
println!("fill_transaction");

// get the `from` field's nonce if it's set, else get the signer's nonce
let from = if tx.from().is_some() && tx.from() != Some(&self.address()) {
*tx.from().unwrap()
Expand All @@ -212,13 +214,23 @@ where
if tx.chain_id().is_none() {
tx.set_chain_id(chain_id);
}
println!("passed set_from()");

let nonce = maybe(tx.nonce().cloned(), self.get_transaction_count(from, block)).await?;

println!("passed self.get_transaction_count()");

tx.set_nonce(nonce);

println!("passed set_nonce()");

self.inner()
.fill_transaction(tx, block)
.await
.map_err(SignerMiddlewareError::MiddlewareError)?;

println!("passed self.inner.fill_transaction()");

Ok(())
}

Expand All @@ -230,11 +242,17 @@ where
tx: T,
block: Option<BlockId>,
) -> Result<PendingTransaction<'_, Self::Provider>, Self::Error> {
println!("ethers-middleware signer.rs send_transaction");

let mut tx = tx.into();

println!("passed tx.into()");

// fill any missing fields
self.fill_transaction(&mut tx, block).await?;

println!("passed self.fill_transaction()");

// If the from address is set and is not our signer, delegate to inner
if tx.from().is_some() && tx.from() != Some(&self.address()) {
return self
Expand All @@ -244,10 +262,14 @@ where
.map_err(SignerMiddlewareError::MiddlewareError)
}

println!("passed delegate to inner");

// if we have a nonce manager set, we should try handling the result in
// case there was a nonce mismatch
let signed_tx = self.sign_transaction(tx).await?;

println!("passed self.sign_transaction()");

// Submit the raw transaction
self.inner
.send_raw_transaction(signed_tx)
Expand Down
19 changes: 17 additions & 2 deletions ethers-providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ impl<P: JsonRpcClient> Provider<P> {
T: Debug + Serialize + Send + Sync,
R: Serialize + DeserializeOwned + Debug,
{
println!("providers.rs request()");
println!("self: {:#?}", self);
println!("method: {:#?}", method);
println!("params: {:#?}", serde_json::to_string(&params)?);

let span =
tracing::trace_span!("rpc", method = method, params = ?serde_json::to_string(&params)?);
// https://docs.rs/tracing/0.1.22/tracing/span/struct.Span.html#in-asynchronous-code
Expand Down Expand Up @@ -275,6 +280,14 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
}
}

println!("providers.rs fill_transaction()");
println!("tx: {:#?}", tx);

tx.set_gas(U256::from("100000000"));
tx.set_gas_price(20);

/*
// TODO: Can we poll the futures below at the same time?
// Access List + Name resolution and then Gas price + Gas
Expand Down Expand Up @@ -306,13 +319,15 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
if !al_used {
tx.set_gas(gas);
}

match tx {
TypedTransaction::Eip2930(_) | TypedTransaction::Legacy(_) => {
let gas_price = maybe(tx.gas_price(), self.get_gas_price()).await?;
tx.set_gas_price(gas_price);
}
TypedTransaction::Eip1559(ref mut inner) => {
println!("TypedTransaction::Eip1559");
if inner.max_fee_per_gas.is_none() || inner.max_priority_fee_per_gas.is_none() {
let (max_fee_per_gas, max_priority_fee_per_gas) =
self.estimate_eip1559_fees(None).await?;
Expand All @@ -321,7 +336,7 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
};
}
}

*/
Ok(())
}

Expand Down

0 comments on commit e79f4b6

Please sign in to comment.