mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-06 02:38:11 +01:00
tests: Fix NMC tests.
This commit is contained in:
@@ -1942,7 +1942,7 @@ class BasicSwap(BaseApp):
|
||||
refund_txn = self.createRefundTxn(coin_from, txn, offer, bid, script)
|
||||
bid.initiate_txn_refund = bytes.fromhex(refund_txn)
|
||||
|
||||
txid = self.submitTxn(coin_from, txn)
|
||||
txid = ci_from.publishTx(bytes.fromhex(txn))
|
||||
self.log.debug('Submitted initiate txn %s to %s chain for bid %s', txid, ci_from.coin_name(), bid_id.hex())
|
||||
bid.initiate_tx = SwapTx(
|
||||
bid_id=bid_id,
|
||||
@@ -1955,7 +1955,7 @@ class BasicSwap(BaseApp):
|
||||
|
||||
# Check non-bip68 final
|
||||
try:
|
||||
txid = self.submitTxn(coin_from, bid.initiate_txn_refund.hex())
|
||||
txid = ci_from.publishTx(bid.initiate_txn_refund)
|
||||
self.log.error('Submit refund_txn unexpectedly worked: ' + txid)
|
||||
except Exception as ex:
|
||||
if 'non-BIP68-final' not in str(ex) and 'non-final' not in str(ex):
|
||||
@@ -2664,14 +2664,6 @@ class BasicSwap(BaseApp):
|
||||
|
||||
return refund_txn
|
||||
|
||||
def submitTxn(self, coin_type, txn):
|
||||
# self.log.debug('submitTxn %s', str(coin_type))
|
||||
if txn is None:
|
||||
return None
|
||||
if self.coin_clients[coin_type]['connection_type'] != 'rpc':
|
||||
return None
|
||||
return self.callcoinrpc(coin_type, 'sendrawtransaction', [txn])
|
||||
|
||||
def initiateTxnConfirmed(self, bid_id, bid, offer):
|
||||
self.log.debug('initiateTxnConfirmed for bid %s', bid_id.hex())
|
||||
bid.setState(BidStates.SWAP_INITIATED)
|
||||
@@ -2693,7 +2685,7 @@ class BasicSwap(BaseApp):
|
||||
|
||||
coin_to = Coins(offer.coin_to)
|
||||
txn = self.createParticipateTxn(bid_id, bid, offer, participate_script)
|
||||
txid = self.submitTxn(coin_to, txn)
|
||||
txid = self.ci(coin_to).publishTx(bytes.fromhex(txn))
|
||||
self.log.debug('Submitted participate txn %s to %s chain for bid %s', txid, chainparams[coin_to]['name'], bid_id.hex())
|
||||
bid.setPTxState(TxStates.TX_SENT)
|
||||
else:
|
||||
@@ -2745,10 +2737,10 @@ class BasicSwap(BaseApp):
|
||||
|
||||
# Seller redeems from participate txn
|
||||
if bid.was_received:
|
||||
coin_to = Coins(offer.coin_to)
|
||||
txn = self.createRedeemTxn(coin_to, bid)
|
||||
txid = self.submitTxn(coin_to, txn)
|
||||
self.log.debug('Submitted participate redeem txn %s to %s chain for bid %s', txid, chainparams[coin_to]['name'], bid_id.hex())
|
||||
ci_to = self.ci(offer.coin_to)
|
||||
txn = self.createRedeemTxn(ci_to.coin_type(), bid)
|
||||
txid = ci_to.publishTx(bytes.fromhex(txn))
|
||||
self.log.debug('Submitted participate redeem txn %s to %s chain for bid %s', txid, ci_to.coin_name(), bid_id.hex())
|
||||
# TX_REDEEMED will be set when spend is detected
|
||||
# TODO: Wait for depth?
|
||||
|
||||
@@ -3230,7 +3222,7 @@ class BasicSwap(BaseApp):
|
||||
if (bid.getITxState() == TxStates.TX_SENT or bid.getITxState() == TxStates.TX_CONFIRMED) \
|
||||
and bid.initiate_txn_refund is not None:
|
||||
try:
|
||||
txid = self.submitTxn(coin_from, bid.initiate_txn_refund.hex())
|
||||
txid = ci_from.publishTx(bid.initiate_txn_refund)
|
||||
self.log.debug('Submitted initiate refund txn %s to %s chain for bid %s', txid, chainparams[coin_from]['name'], bid_id.hex())
|
||||
# State will update when spend is detected
|
||||
except Exception as ex:
|
||||
@@ -3240,7 +3232,7 @@ class BasicSwap(BaseApp):
|
||||
if (bid.getPTxState() == TxStates.TX_SENT or bid.getPTxState() == TxStates.TX_CONFIRMED) \
|
||||
and bid.participate_txn_refund is not None:
|
||||
try:
|
||||
txid = self.submitTxn(coin_to, bid.participate_txn_refund.hex())
|
||||
txid = ci_to.publishTx(bid.participate_txn_refund)
|
||||
self.log.debug('Submitted participate refund txn %s to %s chain for bid %s', txid, chainparams[coin_to]['name'], bid_id.hex())
|
||||
# State will update when spend is detected
|
||||
except Exception as ex:
|
||||
|
||||
@@ -988,7 +988,7 @@ class BTCInterface(CoinInterface):
|
||||
if not addr_info['iswatchonly']:
|
||||
ro = self.rpc_callback('importaddress', [dest_address, 'bid', False])
|
||||
self._log.info('Imported watch-only addr: {}'.format(dest_address))
|
||||
self._log.info('Rescanning chain from height: {}'.format(rescan_from))
|
||||
self._log.info('Rescanning {} chain from height: {}'.format(self.coin_name(), rescan_from))
|
||||
self.rpc_callback('rescanblockchain', [rescan_from])
|
||||
|
||||
return_txid = True if txid is None else False
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2020-2021 tecnovert
|
||||
# Copyright (c) 2020-2022 tecnovert
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
from .interface_btc import BTCInterface
|
||||
from .chainparams import Coins
|
||||
from .util import (
|
||||
make_int,
|
||||
)
|
||||
|
||||
|
||||
class NMCInterface(BTCInterface):
|
||||
@@ -15,4 +18,25 @@ class NMCInterface(BTCInterface):
|
||||
return Coins.NMC
|
||||
|
||||
def getLockTxHeight(self, txid, dest_address, bid_amount, rescan_from, find_index=False):
|
||||
raise ValueError('TODO: Use scantxoutset')
|
||||
self._log.debug('[rm] scantxoutset start') # scantxoutset is slow
|
||||
ro = self.rpc_callback('scantxoutset', ['start', ['addr({})'.format(dest_address)]]) # TODO: Use combo(address) where possible
|
||||
self._log.debug('[rm] scantxoutset end')
|
||||
return_txid = True if txid is None else False
|
||||
for o in ro['unspents']:
|
||||
if txid and o['txid'] != txid.hex():
|
||||
continue
|
||||
# Verify amount
|
||||
if make_int(o['amount']) != int(bid_amount):
|
||||
self._log.warning('Found output to lock tx address of incorrect value: %s, %s', str(o['amount']), o['txid'])
|
||||
continue
|
||||
|
||||
rv = {
|
||||
'depth': 0,
|
||||
'height': o['height']}
|
||||
if o['height'] > 0:
|
||||
rv['depth'] = ro['height'] - o['height']
|
||||
if find_index:
|
||||
rv['index'] = o['vout']
|
||||
if return_txid:
|
||||
rv['txid'] = o['txid']
|
||||
return rv
|
||||
|
||||
@@ -667,7 +667,7 @@ class PARTInterfaceAnon(PARTInterface):
|
||||
wif_scan_key = toWIF(wif_prefix, kbv)
|
||||
self.rpc_callback('importstealthaddress', [wif_scan_key, Kbs.hex()])
|
||||
self._log.info('Imported watch-only sx_addr: {}'.format(sx_addr))
|
||||
self._log.info('Rescanning chain from height: {}'.format(restore_height))
|
||||
self._log.info('Rescanning {} chain from height: {}'.format(self.coin_name(), restore_height))
|
||||
self.rpc_callback('rescanblockchain', [restore_height])
|
||||
|
||||
params = [{'include_watchonly': True, 'search': sx_addr}]
|
||||
@@ -700,7 +700,7 @@ class PARTInterfaceAnon(PARTInterface):
|
||||
wif_spend_key = toWIF(wif_prefix, kbs)
|
||||
self.rpc_callback('importstealthaddress', [wif_scan_key, wif_spend_key])
|
||||
self._log.info('Imported spend key for sx_addr: {}'.format(sx_addr))
|
||||
self._log.info('Rescanning chain from height: {}'.format(restore_height))
|
||||
self._log.info('Rescanning {} chain from height: {}'.format(self.coin_name(), restore_height))
|
||||
self.rpc_callback('rescanblockchain', [restore_height])
|
||||
|
||||
autxos = self.rpc_callback('listunspentanon', [1, 9999999, [sx_addr]])
|
||||
|
||||
@@ -54,7 +54,7 @@ def redeemITx(self, bid_id, session):
|
||||
ci_from = self.ci(offer.coin_from)
|
||||
|
||||
txn = self.createRedeemTxn(ci_from.coin_type(), bid, for_txn_type='initiate')
|
||||
txid = self.submitTxn(ci_from.coin_type(), txn)
|
||||
txid = ci_from.publishTx(bytes.fromhex(txn))
|
||||
|
||||
bid.initiate_tx.spend_txid = bytes.fromhex(txid)
|
||||
self.log.debug('Submitted initiate redeem txn %s to %s chain for bid %s', txid, ci_from.coin_name(), bid_id.hex())
|
||||
|
||||
Reference in New Issue
Block a user