# -*- coding: utf-8 -*- # Copyright (c) 2019 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php. import os import json import time import struct import traceback import threading import http.client import urllib.parse from http.server import BaseHTTPRequestHandler, HTTPServer from .util import ( COIN, format8, ) from .chainparams import ( chainparams, Coins, ) from .basicswap import ( SwapTypes, BidStates, TxStates, getOfferState, getBidState, getTxState, getLockName, SEQUENCE_LOCK_TIME, ABS_LOCK_TIME, ) def getCoinName(c): return chainparams[c]['name'].capitalize() def html_content_start(title, h2=None, refresh=None): content = '\n
' \ + '' \ + ('' if not refresh else ''.format(refresh)) \ + 'Error: ' + error_str + '
' \ + '' return bytes(content, 'UTF-8') def js_error(self, error_str): error_str_json = json.dumps({'error': error_str}) return bytes(error_str_json, 'UTF-8') def js_wallets(self, url_split): return bytes(json.dumps(self.server.swap_client.getWalletsInfo()), 'UTF-8') def js_offers(self, url_split): assert(False), 'TODO' return bytes(json.dumps(self.server.swap_client.listOffers()), 'UTF-8') def js_sentoffers(self, url_split): assert(False), 'TODO' return bytes(json.dumps(self.server.swap_client.listOffers(sent=True)), 'UTF-8') def js_bids(self, url_split): if len(url_split) > 3: bid_id = bytes.fromhex(url_split[3]) assert(len(bid_id) == 28) return bytes(json.dumps(self.server.swap_client.viewBid(bid_id)), 'UTF-8') return bytes(json.dumps(self.server.swap_client.listBids()), 'UTF-8') def js_sentbids(self, url_split): return bytes(json.dumps(self.server.swap_client.listBids(sent=True)), 'UTF-8') def js_index(self, url_split): return bytes(json.dumps(self.server.swap_client.getSummary()), 'UTF-8') def page_active(self, url_split, post_string): swap_client = self.server.swap_client content = html_content_start(self.server.title, self.server.title) \ + 'Bid ID | Offer ID | Bid Status |
---|---|---|
{0} | {1} | {2} |