api: Add withdraw.

This commit is contained in:
tecnovert
2021-02-07 12:01:58 +02:00
parent b1ea76dcb6
commit c4fc2c70dc
9 changed files with 221 additions and 122 deletions

View File

@@ -9,6 +9,7 @@ import os
import json
import signal
import logging
import urllib
from urllib.request import urlopen
from basicswap.rpc import callrpc
@@ -230,6 +231,26 @@ def waitForNumSwapping(delay_event, port, bids, wait_for=60):
raise ValueError('waitForNumSwapping failed')
def wait_for_balance(delay_event, url, balance_key, expect_amount, iterations=20, delay_time=3):
i = 0
while not delay_event.is_set():
rv_js = json.loads(urlopen(url).read())
if float(rv_js[balance_key]) >= expect_amount:
break
delay_event.wait(delay_time)
i += 1
if i > iterations:
raise ValueError('Expect {} {}'.format(balance_key, expect_amount))
def post_json_req(url, json_data):
req = urllib.request.Request(url)
req.add_header('Content-Type', 'application/json; charset=utf-8')
post_bytes = json.dumps(json_data).encode('utf-8')
req.add_header('Content-Length', len(post_bytes))
return urlopen(req, post_bytes).read()
def delay_for(delay_event, delay_for=60):
logging.info('Delaying for {} seconds.'.format(delay_for))
delay_event.wait(delay_for)