|
|
@ -37,17 +37,24 @@ from .ui.page_offers import postNewOffer |
|
|
|
from .protocols.xmr_swap_1 import recoverNoScriptTxnWithKey, getChainBSplitKey |
|
|
|
from .protocols.xmr_swap_1 import recoverNoScriptTxnWithKey, getChainBSplitKey |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getFormData(post_string, is_json): |
|
|
|
|
|
|
|
if post_string == '': |
|
|
|
|
|
|
|
raise ValueError('No post data') |
|
|
|
|
|
|
|
if is_json: |
|
|
|
|
|
|
|
form_data = json.loads(post_string) |
|
|
|
|
|
|
|
form_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
form_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
return form_data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def js_error(self, error_str): |
|
|
|
def js_error(self, error_str): |
|
|
|
error_str_json = json.dumps({'error': error_str}) |
|
|
|
error_str_json = json.dumps({'error': error_str}) |
|
|
|
return bytes(error_str_json, 'UTF-8') |
|
|
|
return bytes(error_str_json, 'UTF-8') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def withdraw_coin(swap_client, coin_type, post_string, is_json): |
|
|
|
def withdraw_coin(swap_client, coin_type, post_string, is_json): |
|
|
|
if is_json: |
|
|
|
post_data = getFormData(post_string, 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') |
|
|
|
value = get_data_entry(post_data, 'value') |
|
|
|
address = get_data_entry(post_data, 'address') |
|
|
|
address = get_data_entry(post_data, 'address') |
|
|
@ -99,6 +106,13 @@ def js_wallets(self, url_split, post_string, is_json): |
|
|
|
return bytes(json.dumps(withdraw_coin(swap_client, coin_type, post_string, is_json)), 'UTF-8') |
|
|
|
return bytes(json.dumps(withdraw_coin(swap_client, coin_type, post_string, is_json)), 'UTF-8') |
|
|
|
if cmd == 'nextdepositaddr': |
|
|
|
if cmd == 'nextdepositaddr': |
|
|
|
return bytes(json.dumps(swap_client.cacheNewAddressForCoin(coin_type)), 'UTF-8') |
|
|
|
return bytes(json.dumps(swap_client.cacheNewAddressForCoin(coin_type)), 'UTF-8') |
|
|
|
|
|
|
|
if cmd == 'createutxo': |
|
|
|
|
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
|
|
|
|
ci = swap_client.ci(coin_type) |
|
|
|
|
|
|
|
value = ci.make_int(get_data_entry(post_data, 'value')) |
|
|
|
|
|
|
|
txid_hex, new_addr = ci.createUTXO(value) |
|
|
|
|
|
|
|
return bytes(json.dumps({'txid': txid_hex, 'address': new_addr}), 'UTF-8') |
|
|
|
|
|
|
|
|
|
|
|
raise ValueError('Unknown command') |
|
|
|
raise ValueError('Unknown command') |
|
|
|
|
|
|
|
|
|
|
|
rv = swap_client.getWalletInfo(coin_type) |
|
|
|
rv = swap_client.getWalletInfo(coin_type) |
|
|
@ -113,13 +127,7 @@ def js_offers(self, url_split, post_string, is_json, sent=False): |
|
|
|
offer_id = None |
|
|
|
offer_id = None |
|
|
|
if len(url_split) > 3: |
|
|
|
if len(url_split) > 3: |
|
|
|
if url_split[3] == 'new': |
|
|
|
if url_split[3] == 'new': |
|
|
|
if post_string == '': |
|
|
|
form_data = getFormData(post_string, is_json) |
|
|
|
raise ValueError('No post data') |
|
|
|
|
|
|
|
if is_json: |
|
|
|
|
|
|
|
form_data = json.loads(post_string) |
|
|
|
|
|
|
|
form_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
form_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
offer_id = postNewOffer(swap_client, form_data) |
|
|
|
offer_id = postNewOffer(swap_client, form_data) |
|
|
|
rv = {'offer_id': offer_id.hex()} |
|
|
|
rv = {'offer_id': offer_id.hex()} |
|
|
|
return bytes(json.dumps(rv), 'UTF-8') |
|
|
|
return bytes(json.dumps(rv), 'UTF-8') |
|
|
@ -138,11 +146,7 @@ def js_offers(self, url_split, post_string, is_json, sent=False): |
|
|
|
filters['offer_id'] = offer_id |
|
|
|
filters['offer_id'] = offer_id |
|
|
|
|
|
|
|
|
|
|
|
if post_string != '': |
|
|
|
if post_string != '': |
|
|
|
if is_json: |
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
post_data = json.loads(post_string) |
|
|
|
|
|
|
|
post_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
post_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
filters['coin_from'] = setCoinFilter(post_data, 'coin_from') |
|
|
|
filters['coin_from'] = setCoinFilter(post_data, 'coin_from') |
|
|
|
filters['coin_to'] = setCoinFilter(post_data, 'coin_to') |
|
|
|
filters['coin_to'] = setCoinFilter(post_data, 'coin_to') |
|
|
|
|
|
|
|
|
|
|
@ -191,13 +195,7 @@ def js_bids(self, url_split, post_string, is_json): |
|
|
|
swap_client.checkSystemStatus() |
|
|
|
swap_client.checkSystemStatus() |
|
|
|
if len(url_split) > 3: |
|
|
|
if len(url_split) > 3: |
|
|
|
if url_split[3] == 'new': |
|
|
|
if url_split[3] == 'new': |
|
|
|
if post_string == '': |
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
raise ValueError('No post data') |
|
|
|
|
|
|
|
if is_json: |
|
|
|
|
|
|
|
post_data = json.loads(post_string) |
|
|
|
|
|
|
|
post_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
post_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
offer_id = bytes.fromhex(get_data_entry(post_data, 'offer_id')) |
|
|
|
offer_id = bytes.fromhex(get_data_entry(post_data, 'offer_id')) |
|
|
|
assert (len(offer_id) == 28) |
|
|
|
assert (len(offer_id) == 28) |
|
|
@ -246,11 +244,7 @@ def js_bids(self, url_split, post_string, is_json): |
|
|
|
|
|
|
|
|
|
|
|
show_txns = False |
|
|
|
show_txns = False |
|
|
|
if post_string != '': |
|
|
|
if post_string != '': |
|
|
|
if is_json: |
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
post_data = json.loads(post_string) |
|
|
|
|
|
|
|
post_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
post_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
if have_data_entry(post_data, 'accept'): |
|
|
|
if have_data_entry(post_data, 'accept'): |
|
|
|
swap_client.acceptBid(bid_id) |
|
|
|
swap_client.acceptBid(bid_id) |
|
|
|
elif have_data_entry(post_data, 'debugind'): |
|
|
|
elif have_data_entry(post_data, 'debugind'): |
|
|
@ -314,13 +308,7 @@ def js_smsgaddresses(self, url_split, post_string, is_json): |
|
|
|
swap_client = self.server.swap_client |
|
|
|
swap_client = self.server.swap_client |
|
|
|
swap_client.checkSystemStatus() |
|
|
|
swap_client.checkSystemStatus() |
|
|
|
if len(url_split) > 3: |
|
|
|
if len(url_split) > 3: |
|
|
|
if post_string == '': |
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
raise ValueError('No post data') |
|
|
|
|
|
|
|
if is_json: |
|
|
|
|
|
|
|
post_data = json.loads(post_string) |
|
|
|
|
|
|
|
post_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
post_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
if url_split[3] == 'new': |
|
|
|
if url_split[3] == 'new': |
|
|
|
addressnote = get_data_entry_or(post_data, 'addressnote', '') |
|
|
|
addressnote = get_data_entry_or(post_data, 'addressnote', '') |
|
|
|
new_addr, pubkey = swap_client.newSMSGAddress(addressnote=addressnote) |
|
|
|
new_addr, pubkey = swap_client.newSMSGAddress(addressnote=addressnote) |
|
|
@ -341,13 +329,7 @@ def js_smsgaddresses(self, url_split, post_string, is_json): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def js_rates(self, url_split, post_string, is_json): |
|
|
|
def js_rates(self, url_split, post_string, is_json): |
|
|
|
if post_string == '': |
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
raise ValueError('No post data') |
|
|
|
|
|
|
|
if is_json: |
|
|
|
|
|
|
|
post_data = json.loads(post_string) |
|
|
|
|
|
|
|
post_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
post_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sc = self.server.swap_client |
|
|
|
sc = self.server.swap_client |
|
|
|
coin_from = get_data_entry(post_data, 'coin_from') |
|
|
|
coin_from = get_data_entry(post_data, 'coin_from') |
|
|
@ -365,13 +347,7 @@ def js_rates_list(self, url_split, query_string, is_json): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def js_rate(self, url_split, post_string, is_json): |
|
|
|
def js_rate(self, url_split, post_string, is_json): |
|
|
|
if post_string == '': |
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
raise ValueError('No post data') |
|
|
|
|
|
|
|
if is_json: |
|
|
|
|
|
|
|
post_data = json.loads(post_string) |
|
|
|
|
|
|
|
post_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
post_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sc = self.server.swap_client |
|
|
|
sc = self.server.swap_client |
|
|
|
coin_from = getCoinType(get_data_entry(post_data, 'coin_from')) |
|
|
|
coin_from = getCoinType(get_data_entry(post_data, 'coin_from')) |
|
|
@ -447,13 +423,7 @@ def js_vacuumdb(self, url_split, post_string, is_json): |
|
|
|
def js_getcoinseed(self, url_split, post_string, is_json): |
|
|
|
def js_getcoinseed(self, url_split, post_string, is_json): |
|
|
|
swap_client = self.server.swap_client |
|
|
|
swap_client = self.server.swap_client |
|
|
|
swap_client.checkSystemStatus() |
|
|
|
swap_client.checkSystemStatus() |
|
|
|
if post_string == '': |
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
raise ValueError('No post data') |
|
|
|
|
|
|
|
if is_json: |
|
|
|
|
|
|
|
post_data = json.loads(post_string) |
|
|
|
|
|
|
|
post_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
post_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
coin = getCoinType(get_data_entry(post_data, 'coin')) |
|
|
|
coin = getCoinType(get_data_entry(post_data, 'coin')) |
|
|
|
if coin in (Coins.PART, Coins.PART_ANON, Coins.PART_BLIND): |
|
|
|
if coin in (Coins.PART, Coins.PART_ANON, Coins.PART_BLIND): |
|
|
@ -471,13 +441,7 @@ def js_setpassword(self, url_split, post_string, is_json): |
|
|
|
# Only works with currently enabled coins |
|
|
|
# Only works with currently enabled coins |
|
|
|
# Will fail if any coin does not unlock on the old password |
|
|
|
# Will fail if any coin does not unlock on the old password |
|
|
|
swap_client = self.server.swap_client |
|
|
|
swap_client = self.server.swap_client |
|
|
|
if post_string == '': |
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
raise ValueError('No post data') |
|
|
|
|
|
|
|
if is_json: |
|
|
|
|
|
|
|
post_data = json.loads(post_string) |
|
|
|
|
|
|
|
post_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
post_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
old_password = get_data_entry(post_data, 'oldpassword') |
|
|
|
old_password = get_data_entry(post_data, 'oldpassword') |
|
|
|
new_password = get_data_entry(post_data, 'newpassword') |
|
|
|
new_password = get_data_entry(post_data, 'newpassword') |
|
|
@ -497,13 +461,7 @@ def js_setpassword(self, url_split, post_string, is_json): |
|
|
|
|
|
|
|
|
|
|
|
def js_unlock(self, url_split, post_string, is_json): |
|
|
|
def js_unlock(self, url_split, post_string, is_json): |
|
|
|
swap_client = self.server.swap_client |
|
|
|
swap_client = self.server.swap_client |
|
|
|
if post_string == '': |
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
raise ValueError('No post data') |
|
|
|
|
|
|
|
if is_json: |
|
|
|
|
|
|
|
post_data = json.loads(post_string) |
|
|
|
|
|
|
|
post_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
post_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
password = get_data_entry(post_data, 'password') |
|
|
|
password = get_data_entry(post_data, 'password') |
|
|
|
|
|
|
|
|
|
|
@ -520,13 +478,7 @@ def js_unlock(self, url_split, post_string, is_json): |
|
|
|
|
|
|
|
|
|
|
|
def js_lock(self, url_split, post_string, is_json): |
|
|
|
def js_lock(self, url_split, post_string, is_json): |
|
|
|
swap_client = self.server.swap_client |
|
|
|
swap_client = self.server.swap_client |
|
|
|
if post_string == '': |
|
|
|
post_data = getFormData(post_string, is_json) |
|
|
|
raise ValueError('No post data') |
|
|
|
|
|
|
|
if is_json: |
|
|
|
|
|
|
|
post_data = json.loads(post_string) |
|
|
|
|
|
|
|
post_data['is_json'] = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
post_data = urllib.parse.parse_qs(post_string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if have_data_entry(post_data, 'coin'): |
|
|
|
if have_data_entry(post_data, 'coin'): |
|
|
|
coin = getCoinType(get_data_entry(post_data, 'coin')) |
|
|
|
coin = getCoinType(get_data_entry(post_data, 'coin')) |
|
|
|