Skip to content

Commit

Permalink
adjust gas price API
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Rodrigues Lordello committed May 26, 2020
1 parent d007e39 commit 7ed1073
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/transaction/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ async fn build_transaction_request_for_local_signing<T: Transport>(
.get(0)
.ok_or(ExecutionError::NoLocalAccounts)?,
};
let gas_price = gas_price
.resolve_for_transaction_request(&web3)
.await
.transpose()?;
let gas_price = gas_price.resolve_for_transaction_request(&web3).await?;

let request = options.build_request(from, gas_price);

Expand All @@ -176,10 +173,7 @@ async fn build_transaction_signed_with_locked_account<T: Transport>(
gas_price: GasPrice,
options: TransactionRequestOptions,
) -> Result<Bytes, ExecutionError> {
let gas_price = gas_price
.resolve_for_transaction_request(&web3)
.await
.transpose()?;
let gas_price = gas_price.resolve_for_transaction_request(&web3).await?;

let request = options.build_request(from, gas_price);
let signed_tx = web3
Expand Down
13 changes: 6 additions & 7 deletions src/transaction/gas_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ impl GasPrice {
pub async fn resolve_for_transaction_request<T: Transport>(
self,
web3: &Web3<T>,
) -> Option<Result<U256, ExecutionError>> {
match self {
) -> Result<Option<U256>, ExecutionError> {
let gas_price = match self {
GasPrice::Standard => None,
_ => Some(self.resolve(web3).await),
}
_ => Some(self.resolve(web3).await?),
};

Ok(gas_price)
}
}

Expand Down Expand Up @@ -180,7 +182,6 @@ mod tests {
GasPrice::Standard
.resolve_for_transaction_request(&web3)
.immediate()
.transpose()
.expect("error resolving gas price"),
None
);
Expand All @@ -191,7 +192,6 @@ mod tests {
GasPrice::Scaled(2.0)
.resolve_for_transaction_request(&web3)
.immediate()
.transpose()
.expect("error resolving gas price"),
Some(gas_price * 2),
);
Expand All @@ -202,7 +202,6 @@ mod tests {
GasPrice::Value(gas_price)
.resolve_for_transaction_request(&web3)
.immediate()
.transpose()
.expect("error resolving gas price"),
Some(gas_price)
);
Expand Down

0 comments on commit 7ed1073

Please sign in to comment.