def regtest_topup_account(receive_address: P2PKH_Address, amount: int = 25) -> Optional[str]: matured_balance = regtest_get_mined_balance() while matured_balance < amount: nblocks = 1 if matured_balance == 0: nblocks = 200 result = node_rpc_call("generatetoaddress", nblocks, Net.REGTEST_P2PKH_ADDRESS) if result.status_code == 200: logger.debug(f"generated {nblocks}: {result.json()['result']}") matured_balance = regtest_get_mined_balance() # Note: for bare multi-sig support may need to craft rawtxs manually via bitcoind's # 'signrawtransaction' jsonrpc method - AustEcon payload = json.dumps({ "jsonrpc": "2.0", "method": "sendtoaddress", "params": [receive_address.to_string(), amount], "id": 0 }) result = requests.post("http://*****:*****@127.0.0.1:18332", data=payload) if result.status_code != 200: raise requests.exceptions.HTTPError(result.text) txid = result.json()['result'] logger.info( "topped up wallet with %s coins to receive address='%s'. txid=%s", amount, receive_address.to_string(), txid) return txid
def regtest_topup_account(receive_address: P2PKH_Address, max_amount: int=25) -> str: matured_balance = regtest_get_mined_balance() # Sweep up to 25 coins to wallet receive address amount = min(max_amount, matured_balance) if not amount > 0: logger.error("Insufficient funds in regtest slush fund to topup wallet. Mine " "more blocks") # Note: for bare multi-sig support may need to craft rawtxs manually via bitcoind's # 'signrawtransaction' jsonrpc method - AustEcon payload = json.dumps({"jsonrpc": "2.0", "method": "sendtoaddress", "params": [receive_address.to_string(), amount], "id": 0}) result = requests.post("http://*****:*****@127.0.0.1:18332", data=payload) result.raise_for_status() txid = result.json()['result'] logger.info("topped up wallet with %s coins to receive address='%s'. txid=%s", amount, receive_address.to_string(), txid) return txid