Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions bindings/python/src/ldk_node/test_ldk_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,43 @@ def mine_and_wait(esplora_endpoint, blocks):

def wait_for_block(esplora_endpoint, block_hash):
url = esplora_endpoint + "/block/" + block_hash + "/status"
esplora_picked_up_block = False
while not esplora_picked_up_block:
res = requests.get(url)
attempts = 0
max_attempts = 30

while attempts < max_attempts:
try:
res = requests.get(url, timeout=10)
json = res.json()
esplora_picked_up_block = json['in_best_chain']
except:
pass
time.sleep(1)
if json.get('in_best_chain'):
return

except Exception as e:
print(f"Error: {e}")

attempts += 1
time.sleep(0.5)

raise Exception(f"Failed to confirm block {block_hash} after {max_attempts} attempts")

def wait_for_tx(esplora_endpoint, txid):
url = esplora_endpoint + "/tx/" + txid
esplora_picked_up_tx = False
while not esplora_picked_up_tx:
res = requests.get(url)
attempts = 0
max_attempts = 30

while attempts < max_attempts:
try:
res = requests.get(url, timeout=10)
json = res.json()
esplora_picked_up_tx = json['txid'] == txid
except:
pass
time.sleep(1)
if json.get('txid') == txid:
return

except Exception as e:
print(f"Error: {e}")

attempts += 1
time.sleep(0.5)

raise Exception(f"Failed to confirm transaction {txid} after {max_attempts} attempts")

def send_to_address(address, amount_sats):
amount_btc = amount_sats/100000000.0
Expand Down