(keystore_file, password, rpc_url, eth_amount, targets_file)
| 19 | @click.argument("eth-amount", type=int) |
| 20 | @click.argument("targets_file", type=click.File()) |
| 21 | def main(keystore_file, password, rpc_url, eth_amount, targets_file) -> None: |
| 22 | web3 = Web3(HTTPProvider(rpc_url)) |
| 23 | with open(keystore_file, "r") as keystore: |
| 24 | account = Account(json.load(keystore), password, keystore_file) |
| 25 | |
| 26 | assert account.privkey, "Could not decode keystore file: wrong password" |
| 27 | assert account.address, "Could not decode keystore file: no 'address' field found" |
| 28 | print("Using account:", to_checksum_address(account.address)) |
| 29 | |
| 30 | client = JSONRPCClient( |
| 31 | web3, account.privkey, block_num_confirmations=DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS |
| 32 | ) |
| 33 | |
| 34 | targets = [t.strip() for t in targets_file] |
| 35 | balance = client.balance(client.address) |
| 36 | |
| 37 | balance_needed = len(targets) * eth_amount |
| 38 | if balance_needed * WEI_TO_ETH > balance: |
| 39 | print( |
| 40 | "Not enough balance to fund {} accounts with {} eth each. Need {}, have {}".format( |
| 41 | len(targets), eth_amount, balance_needed, balance / WEI_TO_ETH |
| 42 | ) |
| 43 | ) |
| 44 | |
| 45 | print("Sending {} eth to:".format(eth_amount)) |
| 46 | |
| 47 | for target in targets: |
| 48 | print(" - {}".format(target)) |
| 49 | gas_price = web3.eth.gasPrice # pylint: disable=no-member |
| 50 | client.transact( |
| 51 | EthTransfer( |
| 52 | to_address=to_canonical_address(target), |
| 53 | value=eth_amount * WEI_TO_ETH, |
| 54 | gas_price=gas_price, |
| 55 | ) |
| 56 | ) |
| 57 | |
| 58 | |
| 59 | if __name__ == "__main__": |
no test coverage detected