def send_transaction(to: Address) -> None: deploy_client.transact( EthTransfer( to_address=to, value=0, gas_price=gas_price_for_fast_transaction(deploy_client.web3), ))
def reclaim_eth(reclamation_candidates: List[ReclamationCandidate], account: Account, web3: Web3): txs = [] reclaim_amount = 0 gas_price = web3.eth.gasPrice reclaim_tx_cost = gas_price * VALUE_TX_GAS_COST log.info("Checking chain for claimable ETH") for node in reclamation_candidates: balance = web3.eth.getBalance(node.address) if balance > reclaim_tx_cost: drain_amount = balance - reclaim_tx_cost log.info( "Reclaiming", from_address=node.address, amount=drain_amount.__format__(",d"), ) reclaim_amount += drain_amount assert account.address txs.append( node.get_client(web3).transact( EthTransfer( to_address=account.address, value=drain_amount, gas_price=gas_price, ))) (node.node_dir / "reclaimed").touch() wait_for_txs(web3, txs, 1000) log.info("Reclaimed", reclaim_amount=reclaim_amount.__format__(",d"))
def main(keystore_file, password, rpc_url, eth_amount, targets_file) -> None: web3 = Web3(HTTPProvider(rpc_url)) with open(keystore_file, "r") as keystore: account = Account(json.load(keystore), password, keystore_file) assert account.privkey, "Could not decode keystore file: wrong password" assert account.address, "Could not decode keystore file: no 'address' field found" print("Using account:", to_checksum_address(account.address)) client = JSONRPCClient( web3, account.privkey, block_num_confirmations=DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS) targets = [t.strip() for t in targets_file] balance = client.balance(client.address) balance_needed = len(targets) * eth_amount if balance_needed * WEI_TO_ETH > balance: print( "Not enough balance to fund {} accounts with {} eth each. Need {}, have {}" .format(len(targets), eth_amount, balance_needed, balance / WEI_TO_ETH)) print("Sending {} eth to:".format(eth_amount)) for target in targets: print(" - {}".format(target)) gas_price = web3.eth.gasPrice # pylint: disable=no-member client.transact( EthTransfer(to_address=target, value=eth_amount * WEI_TO_ETH, gas_price=gas_price))
def eth_maybe_transfer( orchestration_client: JSONRPCClient, target: Address, minimum_balance: int, maximum_balance: int, ) -> None: balance = orchestration_client.balance(target) if balance < minimum_balance: eth_transfer = EthTransfer( to_address=target, value=maximum_balance - balance, gas_price=orchestration_client.web3.eth.gasPrice, ) tx_hash = orchestration_client.transact(eth_transfer) orchestration_client.poll_transaction(tx_hash)
def burn_eth(rpc_client: JSONRPCClient, amount_to_leave: int = 0) -> None: """Burns all the ETH on the account of the given raiden service""" address = rpc_client.address web3 = rpc_client.web3 gas_price = web3.eth.gasPrice # Leave enough ETH to pay for the burn transaction. amount_to_leave = TRANSACTION_INTRINSIC_GAS + amount_to_leave amount_to_burn = web3.eth.getBalance(address) - gas_price * amount_to_leave burn_transfer = EthTransfer(to_address=Address(HOP1), value=amount_to_burn, gas_price=gas_price) transaction_hash = rpc_client.transact(burn_transfer) rpc_client.poll_transaction(transaction_hash)