Esempio n. 1
0
def datafeed_fallback_gas_price_strategy(web3: Web3, transaction_params: TxParams = None) -> Wei:
    feeds = (GasnowGasPriceDatafeed, EtherchainGasPriceDatafeed, UpvestGasPriceDatafeed)

    for gas_price_feed_class in feeds:
        try:
            gas_strategy = gas_price_feed_class.construct_gas_strategy()
            gas_price = gas_strategy(web3, transaction_params)
            gas_price = Wei(min(int(gas_price), Web3.toWei(100, 'gwei')))
        except Datafeed.DatafeedError:
            continue
        else:
            return gas_price
    else:
        # Worst-case scenario, we get the price from the ETH node itself
        return rpc_gas_price_strategy(web3, transaction_params)
Esempio n. 2
0
    def datafeed_median_gas_price_strategy(web3: Web3,
                                           transaction_params: TxParams = None
                                           ) -> Wei:
        feeds = (UpvestGasPriceDatafeed, EtherchainGasPriceDatafeed,
                 ZoltuGasPriceDatafeed)

        prices = []
        for gas_price_feed_class in feeds:
            try:
                gas_strategy = gas_price_feed_class.construct_gas_strategy(
                    speed=speed)
                gas_price = gas_strategy(web3, transaction_params)
            except Datafeed.DatafeedError:
                continue
            else:
                prices.append(gas_price)

        if prices:
            median_price = statistics.median(prices)
            return median_price
        else:  # Worst-case scenario, we get the price from the ETH node itself
            return rpc_gas_price_strategy(web3, transaction_params)
Esempio n. 3
0
    def datafeed_median_gas_price_strategy(web3: Web3,
                                           transaction_params: TxParams = None
                                           ) -> Wei:
        feeds = (UpvestGasPriceDatafeed, ZoltuGasPriceDatafeed
                 )  # removed EtherchainGasPriceDatafeed due to EIP-1559

        prices = []
        for gas_price_feed_class in feeds:
            try:
                gas_strategy = gas_price_feed_class.construct_gas_strategy(
                    speed=speed)
                gas_price = gas_strategy(web3, transaction_params)
            except Exception:
                # some problem; onward and upward
                continue
            else:
                prices.append(gas_price)

        if prices:
            median_price = statistics.median(prices)
            return int(median_price)  # must return an int
        else:  # Worst-case scenario, we get the price from the ETH node itself
            return rpc_gas_price_strategy(web3, transaction_params)
def test_default_rpc_gas_price_strategy_callable_without_transaction(web3):
    assert rpc_gas_price_strategy(web3) == 1
def test_default_rpc_gas_price_strategy(web3):
    assert rpc_gas_price_strategy(web3, {'to': '0x0', 'value': 1}) == 1
def test_default_rpc_gas_price_strategy(web3):
    assert rpc_gas_price_strategy(web3, {
        'to': '0x0',
        'value': 1
    }) == 1
def test_default_rpc_gas_price_strategy_callable_without_transaction(web3):
    assert rpc_gas_price_strategy(web3) == 1