mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-06 02:38:11 +01:00
api: Add withdraw.
This commit is contained in:
@@ -712,7 +712,7 @@ class BasicSwap(BaseApp):
|
||||
self.upgradeDatabase(self.db_version)
|
||||
|
||||
for c in Coins:
|
||||
if not c in chainparams:
|
||||
if c not in chainparams:
|
||||
continue
|
||||
self.setCoinRunParams(c)
|
||||
self.createCoinInterface(c)
|
||||
@@ -780,7 +780,7 @@ class BasicSwap(BaseApp):
|
||||
|
||||
def stopDaemons(self):
|
||||
for c in Coins:
|
||||
if not c in chainparams:
|
||||
if c not in chainparams:
|
||||
continue
|
||||
chain_client_settings = self.getChainClientSettings(c)
|
||||
if self.coin_clients[c]['connection_type'] == 'rpc' and chain_client_settings['manage_daemon'] is True:
|
||||
@@ -4893,8 +4893,9 @@ class BasicSwap(BaseApp):
|
||||
}
|
||||
|
||||
if coin == Coins.PART:
|
||||
rv['stealth_address'] = self.getCachedStealthAddressForCoin(Coins.PART)
|
||||
rv['anon_balance'] = walletinfo['anon_balance']
|
||||
rv['anon_unconfirmed'] = walletinfo['unconfirmed_anon']
|
||||
rv['anon_pending'] = walletinfo['unconfirmed_anon'] + walletinfo['immature_anon_balance']
|
||||
rv['blind_balance'] = walletinfo['blind_balance']
|
||||
rv['blind_unconfirmed'] = walletinfo['unconfirmed_blind']
|
||||
|
||||
@@ -4903,7 +4904,7 @@ class BasicSwap(BaseApp):
|
||||
def getWalletsInfo(self, opts=None):
|
||||
rv = {}
|
||||
for c in Coins:
|
||||
if not c in chainparams:
|
||||
if c not in chainparams:
|
||||
continue
|
||||
if self.coin_clients[c]['connection_type'] == 'rpc':
|
||||
try:
|
||||
|
||||
@@ -76,7 +76,7 @@ def extractDomain(url):
|
||||
def listAvailableExplorers(swap_client):
|
||||
explorers = []
|
||||
for c in Coins:
|
||||
if not c in chainparams:
|
||||
if c not in chainparams:
|
||||
continue
|
||||
for i, e in enumerate(swap_client.coin_clients[c]['explorers']):
|
||||
explorers.append(('{}_{}'.format(int(c), i), swap_client.coin_clients[c]['name'].capitalize() + ' - ' + extractDomain(e.base_url)))
|
||||
@@ -220,7 +220,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||
form_data = self.checkForm(post_string, 'wallets', messages)
|
||||
if form_data:
|
||||
for c in Coins:
|
||||
if not c in chainparams:
|
||||
if c not in chainparams:
|
||||
continue
|
||||
cid = str(int(c))
|
||||
|
||||
@@ -304,13 +304,12 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||
wf['unconfirmed'] = w['unconfirmed']
|
||||
|
||||
if k == Coins.PART:
|
||||
wf['stealth_address'] = swap_client.getCachedStealthAddressForCoin(Coins.PART)
|
||||
wf['blind_balance'] = w['blind_balance']
|
||||
if float(w['blind_unconfirmed']) > 0.0:
|
||||
wf['blind_unconfirmed'] = w['blind_unconfirmed']
|
||||
wf['anon_balance'] = w['anon_balance']
|
||||
if float(w['anon_unconfirmed']) > 0.0:
|
||||
wf['anon_unconfirmed'] = w['anon_unconfirmed']
|
||||
if float(w['anon_pending']) > 0.0:
|
||||
wf['anon_pending'] = w['anon_pending']
|
||||
|
||||
if 'wd_type_from_' + cid in page_data:
|
||||
wf['wd_type_from'] = page_data['wd_type_from_' + cid]
|
||||
|
||||
@@ -97,4 +97,3 @@ class PARTInterfaceAnon(PARTInterface):
|
||||
@staticmethod
|
||||
def balance_type():
|
||||
return BalanceTypes.ANON
|
||||
|
||||
|
||||
@@ -8,19 +8,25 @@ import json
|
||||
import urllib.parse
|
||||
|
||||
from .util import (
|
||||
toBool,
|
||||
format_timestamp,
|
||||
)
|
||||
from .basicswap import (
|
||||
strBidState,
|
||||
SwapTypes,
|
||||
)
|
||||
from .chainparams import (
|
||||
Coins,
|
||||
)
|
||||
from .ui import (
|
||||
PAGE_LIMIT,
|
||||
inputAmount,
|
||||
describeBid,
|
||||
setCoinFilter,
|
||||
get_data_entry,
|
||||
get_data_entry_or,
|
||||
have_data_entry,
|
||||
tickerToCoinId,
|
||||
)
|
||||
|
||||
|
||||
@@ -29,8 +35,40 @@ def js_error(self, error_str):
|
||||
return bytes(error_str_json, 'UTF-8')
|
||||
|
||||
|
||||
def withdraw_coin(swap_client, coin_type, post_string, is_json):
|
||||
if is_json:
|
||||
post_data = json.loads(post_string)
|
||||
post_data['is_json'] = True
|
||||
else:
|
||||
post_data = urllib.parse.parse_qs(post_string)
|
||||
|
||||
value = get_data_entry(post_data, 'value')
|
||||
address = get_data_entry(post_data, 'address')
|
||||
subfee = get_data_entry(post_data, 'subfee')
|
||||
if not isinstance(subfee, bool):
|
||||
subfee = toBool(subfee)
|
||||
|
||||
if coin_type == Coins.PART:
|
||||
type_from = get_data_entry_or(post_data, 'type_from', 'plain')
|
||||
type_to = get_data_entry_or(post_data, 'type_to', 'plain')
|
||||
txid_hex = swap_client.withdrawParticl(type_from, type_to, value, address, subfee)
|
||||
else:
|
||||
txid_hex = swap_client.withdrawCoin(coin_type, value, address, subfee)
|
||||
|
||||
return {'txid': txid_hex}
|
||||
|
||||
|
||||
def js_wallets(self, url_split, post_string, is_json):
|
||||
# TODO: Withdrawals
|
||||
if len(url_split) > 3:
|
||||
ticker_str = url_split[3]
|
||||
coin_type = tickerToCoinId(ticker_str)
|
||||
|
||||
if len(url_split) > 4:
|
||||
cmd = url_split[4]
|
||||
if cmd == 'withdraw':
|
||||
return bytes(json.dumps(withdraw_coin(self.server.swap_client, coin_type, post_string, is_json)), 'UTF-8')
|
||||
raise ValueError('Unknown command')
|
||||
return bytes(json.dumps(self.server.swap_client.getWalletInfo(coin_type)), 'UTF-8')
|
||||
return bytes(json.dumps(self.server.swap_client.getWalletsInfo()), 'UTF-8')
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
{% if w.cid == '1' %}
|
||||
<tr><td>Blind Balance:</td><td>{{ w.blind_balance }}</td>{% if w.blind_unconfirmed %}<td>Blind Unconfirmed:</td><td>{{ w.blind_unconfirmed }}</td>{% endif %}</tr>
|
||||
<tr><td>Anon Balance:</td><td>{{ w.anon_balance }}</td>{% if w.anon_unconfirmed %}<td>Anon Unconfirmed:</td><td>{{ w.anon_unconfirmed }}</td>{% endif %}</tr>
|
||||
<tr><td>Anon Balance:</td><td>{{ w.anon_balance }}</td>{% if w.anon_pending %}<td>Anon Pending:</td><td>{{ w.anon_pending }}</td>{% endif %}</tr>
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
@@ -56,6 +56,15 @@ def inputAmount(amount_str, ci):
|
||||
return make_int(amount_str, ci.exp())
|
||||
|
||||
|
||||
def get_data_entry_or(post_data, name, default):
|
||||
if 'is_json' in post_data:
|
||||
return post_data.get(name, default)
|
||||
key_bytes = name.encode('utf-8')
|
||||
if key_bytes in post_data:
|
||||
return post_data[key_bytes][0].decode('utf-8')
|
||||
return default
|
||||
|
||||
|
||||
def get_data_entry(post_data, name):
|
||||
if 'is_json' in post_data:
|
||||
return post_data[name]
|
||||
|
||||
Reference in New Issue
Block a user