Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
Use env var for gas price or 2 GWEI as default
Browse files Browse the repository at this point in the history
  • Loading branch information
bonomat committed Jun 19, 2018
1 parent 04374a5 commit d3e932a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion exchange_service/src/bin/exchange_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ fn main() {
InMemoryWallet::new(private_key, network_id).expect("Failed to create wallet instance");

let endpoint = var_or_exit("ETHEREUM_NODE_ENDPOINT");
let gas_price = var_or_exit("ETHEREUM_GAS_PRICE_IN_WEI")
.map(|gas| u64::from_str(gas.as_str()).unwrap())
.unwrap_or(2_000_000_000);

let (_event_loop, transport) = web3::transports::Http::new(&endpoint).unwrap();
let web3 = web3::api::Web3::new(transport);
Expand All @@ -74,7 +77,7 @@ fn main() {

let ethereum_service = EthereumService::new(
Arc::new(wallet),
Arc::new(StaticGasPriceService::default()),
Arc::new(StaticGasPriceService::new(gas_price)),
Arc::new(web3),
nonce,
);
Expand Down
2 changes: 1 addition & 1 deletion exchange_service/src/ethereum_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl EthereumService {

let transaction = ethereum_wallet::UnsignedTransaction::new_contract_deployment(
contract.compile_to_hex(),
100000, // TODO calculate exact gas needed for this transaction
86578, //TODO: calculate the gas consumption based on 32k + 200*bytes
gas_price,
funding,
*nonce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ impl GasPriceService for StaticGasPriceService {
Ok(self.0)
}
}

impl StaticGasPriceService {
pub fn new(gas: u64) -> Self {
StaticGasPriceService(U256::from(gas))
}
}

0 comments on commit d3e932a

Please sign in to comment.