diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 729174c..5cc4f49 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -1602,23 +1602,44 @@ class BasicSwap(BaseApp): session.remove() self.mxDB.release() - def list_bid_events(self, bid_id): + def getXmrBidAndOffer(self, bid_id, list_events=True): self.mxDB.acquire() - events = [] try: session = scoped_session(self.session_factory) - query_str = 'SELECT created_at, event_type, event_msg FROM eventlog ' + \ - 'WHERE linked_type = {} AND linked_id = x\'{}\' '.format(TableTypes.BID, bid_id.hex()) - q = self.engine.execute(query_str) + xmr_swap = None + offer = None + xmr_offer = None + events = [] - for row in q: - events.append({'at': row[0], 'desc': describeEventEntry(row[1], row[2])}) - return events + bid = session.query(Bid).filter_by(bid_id=bid_id).first() + if bid: + offer = session.query(Offer).filter_by(offer_id=bid.offer_id).first() + if offer and offer.swap_type == SwapTypes.XMR_SWAP: + xmr_swap = session.query(XmrSwap).filter_by(bid_id=bid.bid_id).first() + xmr_offer = session.query(XmrOffer).filter_by(offer_id=bid.offer_id).first() + self.loadBidTxns(bid, session) + if list_events: + events = self.list_bid_events(bid.bid_id, session) + else: + bid.initiate_tx = session.query(SwapTx).filter(sa.and_(SwapTx.bid_id == bid_id, SwapTx.tx_type == TxTypes.ITX)).first() + bid.participate_tx = session.query(SwapTx).filter(sa.and_(SwapTx.bid_id == bid_id, SwapTx.tx_type == TxTypes.PTX)).first() + + return bid, xmr_swap, offer, xmr_offer, events finally: session.close() session.remove() self.mxDB.release() + def list_bid_events(self, bid_id, session): + session = scoped_session(self.session_factory) + query_str = 'SELECT created_at, event_type, event_msg FROM eventlog ' + \ + 'WHERE linked_type = {} AND linked_id = x\'{}\' '.format(TableTypes.BID, bid_id.hex()) + q = self.engine.execute(query_str) + events = [] + for row in q: + events.append({'at': row[0], 'desc': describeEventEntry(row[1], row[2])}) + return events + def acceptBid(self, bid_id): self.log.info('Accepting bid %s', bid_id.hex()) @@ -4269,7 +4290,7 @@ class BasicSwap(BaseApp): xmr_swap.a_lock_spend_tx, xmr_swap.al_lock_spend_tx_esig, xmr_swap.pkal, xmr_swap.pkasf, 0, xmr_swap.a_lock_tx_script, bid.amount) assert(v), 'verifyTxOtVES failed' - except Exception as e: + except Exception as ex: if self.debug: traceback.print_exc() self.setBidError(bid_id, bid, str(ex)) @@ -4422,7 +4443,7 @@ class BasicSwap(BaseApp): else: self.log.debug('TODO - determine in-progress for manualBidUpdate') if offer.swap_type == SwapTypes.XMR_SWAP: - if bid.state and bid.state in (BidStates.XMR_SWAP_LOCK_RELEASED, BidStates.XMR_SWAP_NOSCRIPT_TX_REDEEMED): + if bid.state and bid.state in (BidStates.XMR_SWAP_SCRIPT_COIN_LOCKED, BidStates.XMR_SWAP_LOCK_RELEASED, BidStates.XMR_SWAP_NOSCRIPT_TX_REDEEMED): activate_bid = True if activate_bid: diff --git a/basicswap/chainparams.py b/basicswap/chainparams.py index 77e247f..27eee4b 100644 --- a/basicswap/chainparams.py +++ b/basicswap/chainparams.py @@ -7,7 +7,8 @@ from enum import IntEnum from .util import ( COIN, - format_amount + format_amount, + make_int ) XMR_COIN = 10 ** 12 @@ -202,7 +203,11 @@ class CoinInterface: def __init__(self): self._unknown_wallet_seed = True - def format_amount(self, amount_int): + def make_int(self, amount_in): + return make_int(amount_in, self.exp()) + + def format_amount(self, amount_in, conv_int=False): + amount_int = make_int(amount_in, self.exp()) if conv_int else amount_in return format_amount(amount_int, self.exp()) def coin_name(self): diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 814abc2..349a83e 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -526,6 +526,7 @@ class HttpHandler(BaseHTTPRequestHandler): messages = [] show_txns = False edit_bid = False + view_tx_ind = None form_data = self.checkForm(post_string, 'bid', messages) if form_data: if b'abandon_bid' in form_data: @@ -553,11 +554,14 @@ class HttpHandler(BaseHTTPRequestHandler): messages.append('Bid edited') except Exception as ex: messages.append('Edit failed ' + str(ex)) + elif b'view_tx_submit' in form_data: + show_txns = True + view_tx_ind = form_data[b'view_tx'][0].decode('utf-8') - bid, offer = swap_client.getBidAndOffer(bid_id) + bid, xmr_swap, offer, xmr_offer, events = swap_client.getXmrBidAndOffer(bid_id) assert(bid), 'Unknown bid ID' - data = describeBid(swap_client, bid, offer, edit_bid, show_txns) + data = describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, events, edit_bid, show_txns, view_tx_ind) old_states = [] num_states = len(bid.states) // 12 diff --git a/basicswap/interface_btc.py b/basicswap/interface_btc.py index 231c14c..5e9b193 100644 --- a/basicswap/interface_btc.py +++ b/basicswap/interface_btc.py @@ -48,15 +48,10 @@ from .contrib.test_framework.messages import ( from .contrib.test_framework.script import ( CScript, CScriptOp, - CScriptNum, OP_IF, OP_ELSE, OP_ENDIF, OP_0, OP_2, - OP_16, - OP_EQUALVERIFY, OP_CHECKSIG, - OP_SIZE, - OP_SHA256, OP_CHECKMULTISIG, OP_CHECKSEQUENCEVERIFY, OP_DROP, diff --git a/basicswap/js_server.py b/basicswap/js_server.py index 13cb75d..34bc910 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -127,12 +127,12 @@ def js_bids(self, url_split, post_string): if b'accept' in post_data: swap_client.acceptBid(bid_id) - bid, offer = swap_client.getBidAndOffer(bid_id) + bid, xmr_swap, offer, xmr_offer, events = swap_client.getXmrBidAndOffer(bid_id) assert(bid), 'Unknown bid ID' edit_bid = False show_txns = False - data = describeBid(swap_client, bid, offer, edit_bid, show_txns) + data = describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, events, edit_bid, show_txns) return bytes(json.dumps(data), 'UTF-8') diff --git a/basicswap/network.py b/basicswap/network.py index b2706cc..87701ce 100644 --- a/basicswap/network.py +++ b/basicswap/network.py @@ -38,5 +38,4 @@ class Network: readable, writable, errored = select.select([self._socket], [], []) for s in readable: client_socket, address = self._socket.accept() - read_list.append(client_socket) - logging.info('Connection from %s', address) + logging.info('Connection from %s', address) diff --git a/basicswap/script.py b/basicswap/script.py index 1beca9d..1418aac 100644 --- a/basicswap/script.py +++ b/basicswap/script.py @@ -11,6 +11,7 @@ class OpCodes(IntEnum): OP_0 = 0x00, OP_PUSHDATA1 = 0x4c, OP_1 = 0x51, + OP_16 = 0x60, OP_IF = 0x63, OP_ELSE = 0x67, OP_ENDIF = 0x68, diff --git a/basicswap/templates/bid_xmr.html b/basicswap/templates/bid_xmr.html index e361f38..dbb3412 100644 --- a/basicswap/templates/bid_xmr.html +++ b/basicswap/templates/bid_xmr.html @@ -21,16 +21,6 @@
Tx Type | Tx ID | Blocks Deep |
---|---|---|
{{ tx.type }} | {{ tx.txid }} | {{ tx.confirms }} |