From 33248528b9ed1f1f8d168b98f3b2d1f13d86584f Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 14 May 2016 14:53:46 +0100 Subject: [PATCH] Provide fallback for usd-per-eth option when offline. Fixes #1073. --- parity/cli.rs | 4 +++- parity/configuration.rs | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/parity/cli.rs b/parity/cli.rs index 009f03b89..90d7167dc 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -102,7 +102,9 @@ Sealing/Mining Options: [default: 0.005]. The minimum gas price is set accordingly. --usd-per-eth SOURCE USD value of a single ETH. SOURCE may be either an - amount in USD or a web service [default: etherscan]. + amount in USD, a web service or 'auto' to use each + web service in turn and fallback on the last known + good value [default: auto]. --gas-floor-target GAS Amount of gas per block to target when sealing a new block [default: 4712388]. --author ADDRESS Specify the block author (aka "coinbase") address diff --git a/parity/configuration.rs b/parity/configuration.rs index 96885f83b..ede71029c 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -91,11 +91,18 @@ impl Configuration { die!("{}: Invalid basic transaction price given in USD. Must be a decimal number.", self.args.flag_usd_per_tx) }); let usd_per_eth = match self.args.flag_usd_per_eth.as_str() { + "auto" => PriceInfo::get().map_or_else(|| { + let last_known_good = 9.69696; + // TODO: use #1083 to read last known good value. + last_known_good + }, |x| x.ethusd), "etherscan" => PriceInfo::get().map_or_else(|| { die!("Unable to retrieve USD value of ETH from etherscan. Rerun with a different value for --usd-per-eth.") }, |x| x.ethusd), x => FromStr::from_str(x).unwrap_or_else(|_| die!("{}: Invalid ether price given in USD. Must be a decimal number.", x)) }; + // TODO: use #1083 to write last known good value as use_per_eth. + let wei_per_usd: f32 = 1.0e18 / usd_per_eth; let gas_per_tx: f32 = 21000.0; let wei_per_gas: f32 = wei_per_usd * usd_per_tx / gas_per_tx;