mirror of
https://github.com/basicswap/basicswap.git
synced 2025-12-04 14:37:07 +01:00
api: Add withdraw.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user