Add display for xmr bid tx hex.

This commit is contained in:
tecnovert 2020-12-12 14:45:30 +02:00
parent cb27fb6c4c
commit 9a182646f0
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
11 changed files with 96 additions and 40 deletions

View file

@ -1602,23 +1602,44 @@ class BasicSwap(BaseApp):
session.remove() session.remove()
self.mxDB.release() self.mxDB.release()
def list_bid_events(self, bid_id): def getXmrBidAndOffer(self, bid_id, list_events=True):
self.mxDB.acquire() self.mxDB.acquire()
events = []
try: try:
session = scoped_session(self.session_factory) session = scoped_session(self.session_factory)
query_str = 'SELECT created_at, event_type, event_msg FROM eventlog ' + \ xmr_swap = None
'WHERE linked_type = {} AND linked_id = x\'{}\' '.format(TableTypes.BID, bid_id.hex()) offer = None
q = self.engine.execute(query_str) xmr_offer = None
events = []
for row in q: bid = session.query(Bid).filter_by(bid_id=bid_id).first()
events.append({'at': row[0], 'desc': describeEventEntry(row[1], row[2])}) if bid:
return events 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: finally:
session.close() session.close()
session.remove() session.remove()
self.mxDB.release() 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): def acceptBid(self, bid_id):
self.log.info('Accepting bid %s', bid_id.hex()) 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.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) xmr_swap.pkal, xmr_swap.pkasf, 0, xmr_swap.a_lock_tx_script, bid.amount)
assert(v), 'verifyTxOtVES failed' assert(v), 'verifyTxOtVES failed'
except Exception as e: except Exception as ex:
if self.debug: if self.debug:
traceback.print_exc() traceback.print_exc()
self.setBidError(bid_id, bid, str(ex)) self.setBidError(bid_id, bid, str(ex))
@ -4422,7 +4443,7 @@ class BasicSwap(BaseApp):
else: else:
self.log.debug('TODO - determine in-progress for manualBidUpdate') self.log.debug('TODO - determine in-progress for manualBidUpdate')
if offer.swap_type == SwapTypes.XMR_SWAP: 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 activate_bid = True
if activate_bid: if activate_bid:

View file

@ -7,7 +7,8 @@
from enum import IntEnum from enum import IntEnum
from .util import ( from .util import (
COIN, COIN,
format_amount format_amount,
make_int
) )
XMR_COIN = 10 ** 12 XMR_COIN = 10 ** 12
@ -202,7 +203,11 @@ class CoinInterface:
def __init__(self): def __init__(self):
self._unknown_wallet_seed = True 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()) return format_amount(amount_int, self.exp())
def coin_name(self): def coin_name(self):

View file

@ -526,6 +526,7 @@ class HttpHandler(BaseHTTPRequestHandler):
messages = [] messages = []
show_txns = False show_txns = False
edit_bid = False edit_bid = False
view_tx_ind = None
form_data = self.checkForm(post_string, 'bid', messages) form_data = self.checkForm(post_string, 'bid', messages)
if form_data: if form_data:
if b'abandon_bid' in form_data: if b'abandon_bid' in form_data:
@ -553,11 +554,14 @@ class HttpHandler(BaseHTTPRequestHandler):
messages.append('Bid edited') messages.append('Bid edited')
except Exception as ex: except Exception as ex:
messages.append('Edit failed ' + str(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' 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 = [] old_states = []
num_states = len(bid.states) // 12 num_states = len(bid.states) // 12

View file

@ -48,15 +48,10 @@ from .contrib.test_framework.messages import (
from .contrib.test_framework.script import ( from .contrib.test_framework.script import (
CScript, CScript,
CScriptOp, CScriptOp,
CScriptNum,
OP_IF, OP_ELSE, OP_ENDIF, OP_IF, OP_ELSE, OP_ENDIF,
OP_0, OP_0,
OP_2, OP_2,
OP_16,
OP_EQUALVERIFY,
OP_CHECKSIG, OP_CHECKSIG,
OP_SIZE,
OP_SHA256,
OP_CHECKMULTISIG, OP_CHECKMULTISIG,
OP_CHECKSEQUENCEVERIFY, OP_CHECKSEQUENCEVERIFY,
OP_DROP, OP_DROP,

View file

@ -127,12 +127,12 @@ def js_bids(self, url_split, post_string):
if b'accept' in post_data: if b'accept' in post_data:
swap_client.acceptBid(bid_id) 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' assert(bid), 'Unknown bid ID'
edit_bid = False edit_bid = False
show_txns = 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') return bytes(json.dumps(data), 'UTF-8')

View file

@ -38,5 +38,4 @@ class Network:
readable, writable, errored = select.select([self._socket], [], []) readable, writable, errored = select.select([self._socket], [], [])
for s in readable: for s in readable:
client_socket, address = self._socket.accept() client_socket, address = self._socket.accept()
read_list.append(client_socket)
logging.info('Connection from %s', address) logging.info('Connection from %s', address)

View file

@ -11,6 +11,7 @@ class OpCodes(IntEnum):
OP_0 = 0x00, OP_0 = 0x00,
OP_PUSHDATA1 = 0x4c, OP_PUSHDATA1 = 0x4c,
OP_1 = 0x51, OP_1 = 0x51,
OP_16 = 0x60,
OP_IF = 0x63, OP_IF = 0x63,
OP_ELSE = 0x67, OP_ELSE = 0x67,
OP_ENDIF = 0x68, OP_ENDIF = 0x68,

View file

@ -21,16 +21,6 @@
<tr><td>Received</td><td>{{ data.was_received }}</td></tr> <tr><td>Received</td><td>{{ data.was_received }}</td></tr>
</table> </table>
{% if data.show_txns %}
<h4>Transactions</h4>
<table>
<tr><th>Tx Type</th><th>Tx ID</th><th>Blocks Deep</th></tr>
{% for tx in data.txns %}
<tr><td>{{ tx.type }}</td><td>{{ tx.txid }}</td><td>{{ tx.confirms }}</td></tr>
{% endfor %}
</table>
{% endif %}
<form method="post"> <form method="post">
{% if edit_bid %} {% if edit_bid %}
<h4>Edit Bid</h4> <h4>Edit Bid</h4>
@ -57,6 +47,29 @@
<input name="edit_bid" type="submit" value="Edit Bid"> <input name="edit_bid" type="submit" value="Edit Bid">
{% endif %} {% endif %}
<input type="hidden" name="formid" value="{{ form_id }}"> <input type="hidden" name="formid" value="{{ form_id }}">
{% if data.show_txns %}
<h4>Transactions</h4>
<table>
<tr><th>Tx Type</th><th>Tx ID</th><th>Blocks Deep</th></tr>
{% for tx in data.txns %}
<tr><td>{{ tx.type }}</td><td>{{ tx.txid }}</td><td>{{ tx.confirms }}</td></tr>
{% endfor %}
</table>
<table>
<tr><td>View Transaction</td><td>
<select name="view_tx">
{% for tx in data.txns %}
<option value="{{ tx.txid }}"{% if data.view_tx_ind==tx.txid %} selected{% endif %}>{{ tx.type }} {{ tx.txid }}</option>
{% endfor %}
</select></td></tr>
</table>
<input name="view_tx_submit" type="submit" value="View Tx">
{% if data.view_tx_hex %}
<p>{{ data.view_tx_hex }}</p>
{% endif %}
{% endif %}
</form> </form>

View file

@ -87,7 +87,7 @@ def listBidStates():
return rv return rv
def describeBid(swap_client, bid, offer, edit_bid, show_txns): def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_bid, show_txns, view_tx_ind=None):
ci_from = swap_client.ci(Coins(offer.coin_from)) ci_from = swap_client.ci(Coins(offer.coin_from))
ci_to = swap_client.ci(Coins(offer.coin_to)) ci_to = swap_client.ci(Coins(offer.coin_to))
ticker_from = ci_from.ticker() ticker_from = ci_from.ticker()
@ -165,7 +165,13 @@ def describeBid(swap_client, bid, offer, edit_bid, show_txns):
txns.append({'type': 'Chain B Lock', 'txid': bid.xmr_b_lock_tx.txid.hex(), 'confirms': confirms}) txns.append({'type': 'Chain B Lock', 'txid': bid.xmr_b_lock_tx.txid.hex(), 'confirms': confirms})
if bid.xmr_b_lock_tx and bid.xmr_b_lock_tx.spend_txid: if bid.xmr_b_lock_tx and bid.xmr_b_lock_tx.spend_txid:
txns.append({'type': 'Chain B Lock Spend', 'txid': bid.xmr_b_lock_tx.spend_txid.hex()}) txns.append({'type': 'Chain B Lock Spend', 'txid': bid.xmr_b_lock_tx.spend_txid.hex()})
if xmr_swap.a_lock_refund_tx:
txns.append({'type': strTxType(TxTypes.XMR_SWAP_A_LOCK_REFUND), 'txid': xmr_swap.a_lock_refund_tx_id.hex()})
if xmr_swap.a_lock_refund_spend_tx:
txns.append({'type': strTxType(TxTypes.XMR_SWAP_A_LOCK_REFUND_SPEND), 'txid': xmr_swap.a_lock_refund_spend_tx_id.hex()})
for tx_type, tx in bid.txns.items(): for tx_type, tx in bid.txns.items():
if tx_type in (TxTypes.XMR_SWAP_A_LOCK_REFUND, TxTypes.XMR_SWAP_A_LOCK_REFUND_SPEND):
continue
txns.append({'type': strTxType(tx_type), 'txid': tx.txid.hex()}) txns.append({'type': strTxType(tx_type), 'txid': tx.txid.hex()})
data['txns'] = txns data['txns'] = txns
else: else:
@ -175,6 +181,18 @@ def describeBid(swap_client, bid, offer, edit_bid, show_txns):
data['participate_tx_spend'] = getTxSpendHex(bid, TxTypes.PTX) data['participate_tx_spend'] = getTxSpendHex(bid, TxTypes.PTX)
if offer.swap_type == SwapTypes.XMR_SWAP: if offer.swap_type == SwapTypes.XMR_SWAP:
data['events'] = swap_client.list_bid_events(bid.bid_id) if view_tx_ind:
data['view_tx_ind'] = view_tx_ind
view_tx_id = bytes.fromhex(view_tx_ind)
if xmr_swap:
if view_tx_id == xmr_swap.a_lock_tx_id and xmr_swap.a_lock_tx:
data['view_tx_hex'] = xmr_swap.a_lock_tx.hex()
if view_tx_id == xmr_swap.a_lock_refund_tx_id and xmr_swap.a_lock_refund_tx:
data['view_tx_hex'] = xmr_swap.a_lock_refund_tx.hex()
if view_tx_id == xmr_swap.a_lock_refund_spend_tx_id and xmr_swap.a_lock_refund_spend_tx:
data['view_tx_hex'] = xmr_swap.a_lock_refund_spend_tx.hex()
data['events'] = bid_events
return data return data

View file

@ -7,10 +7,11 @@
import json import json
import decimal import decimal
import hashlib import hashlib
from .script import OpCodes
from .contrib.segwit_addr import bech32_decode, convertbits, bech32_encode from .contrib.segwit_addr import bech32_decode, convertbits, bech32_encode
OP_1 = 0x51
OP_16 = 0x60
COIN = 100000000 COIN = 100000000
@ -195,8 +196,8 @@ def DeserialiseNum(b, o=0):
def decodeScriptNum(script_bytes, o): def decodeScriptNum(script_bytes, o):
v = 0 v = 0
num_len = script_bytes[o] num_len = script_bytes[o]
if num_len >= OP_1 and num_len <= OP_16: if num_len >= OpCodes.OP_1 and num_len <= OpCodes.OP_16:
return((num_len - OP_1) + 1, 1) return((num_len - OpCodes.OP_1) + 1, 1)
if num_len > 4: if num_len > 4:
raise ValueError('Bad scriptnum length') # Max 4 bytes raise ValueError('Bad scriptnum length') # Max 4 bytes

View file

@ -205,7 +205,6 @@ class Test(unittest.TestCase):
assert(len(sig) == 64) assert(len(sig) == 64)
ci.verifyCompact(pk, 'test signing message', sig) ci.verifyCompact(pk, 'test signing message', sig)
def test_dleag(self): def test_dleag(self):
coin_settings = {'rpcport': 0, 'walletrpcport': 0, 'walletrpcauth': 'none', 'blocks_confirmed': 1, 'conf_target': 1} coin_settings = {'rpcport': 0, 'walletrpcport': 0, 'walletrpcauth': 'none', 'blocks_confirmed': 1, 'conf_target': 1}
ci = XMRInterface(coin_settings, 'regtest') ci = XMRInterface(coin_settings, 'regtest')