From 48e5dcbcc97b6f7f27c750cef204d437a75005ec Mon Sep 17 00:00:00 2001 From: tecnovert Date: Tue, 16 Aug 2022 20:52:43 +0200 Subject: [PATCH] refactor: Add createRawSignedTransaction to interface --- basicswap/basicswap.py | 16 ++-------------- basicswap/interface/btc.py | 11 +++++++++++ tests/basicswap/common_xmr.py | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 28611ba..2d50dc9 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -2364,14 +2364,8 @@ class BasicSwap(BaseApp): else: addr_to = ci.encode_p2sh(initiate_script) self.log.debug('Create initiate txn for coin %s to %s for bid %s', str(coin_type), addr_to, bid_id.hex()) - txn = self.callcoinrpc(coin_type, 'createrawtransaction', [[], {addr_to: ci.format_amount(bid.amount)}]) - options = { - 'lockUnspents': True, - 'conf_target': self.coin_clients[coin_type]['conf_target'], - } - txn_funded = self.callcoinrpc(coin_type, 'fundrawtransaction', [txn, options])['hex'] - txn_signed = self.callcoinrpc(coin_type, 'signrawtransactionwithwallet', [txn_funded])['hex'] + txn_signed = ci.createRawSignedTransaction(addr_to, bid.amount) return txn_signed def deriveParticipateScript(self, bid_id, bid, offer): @@ -2448,13 +2442,7 @@ class BasicSwap(BaseApp): else: addr_to = ci.encode_p2sh(participate_script) - txn = self.callcoinrpc(coin_to, 'createrawtransaction', [[], {addr_to: ci.format_amount(amount_to)}]) - options = { - 'lockUnspents': True, - 'conf_target': self.coin_clients[coin_to]['conf_target'], - } - txn_funded = self.callcoinrpc(coin_to, 'fundrawtransaction', [txn, options])['hex'] - txn_signed = self.callcoinrpc(coin_to, 'signrawtransactionwithwallet', [txn_funded])['hex'] + txn_signed = ci.createRawSignedTransaction(addr_to, amount_to) refund_txn = self.createRefundTxn(coin_to, txn_signed, offer, bid, participate_script, tx_type=TxTypes.PTX_REFUND) bid.participate_txn_refund = bytes.fromhex(refund_txn) diff --git a/basicswap/interface/btc.py b/basicswap/interface/btc.py index 7ba205e..caa4a24 100644 --- a/basicswap/interface/btc.py +++ b/basicswap/interface/btc.py @@ -1150,6 +1150,17 @@ class BTCInterface(CoinInterface): address = self.getNewAddress(self._use_segwit, 'create_utxo') return self.withdrawCoin(self.format_amount(value_sats), address, False), address + def createRawSignedTransaction(self, addr_to, amount): + txn = self.rpc_callback('createrawtransaction', [[], {addr_to: self.format_amount(amount)}]) + + options = { + 'lockUnspents': True, + 'conf_target': self._conf_target, + } + txn_funded = self.rpc_callback('fundrawtransaction', [txn, options])['hex'] + txn_signed = self.rpc_callback('signrawtransactionwithwallet', [txn_funded])['hex'] + return txn_signed + def testBTCInterface(): print('testBTCInterface') diff --git a/tests/basicswap/common_xmr.py b/tests/basicswap/common_xmr.py index 75e8bba..271b8be 100644 --- a/tests/basicswap/common_xmr.py +++ b/tests/basicswap/common_xmr.py @@ -26,6 +26,7 @@ from tests.basicswap.common import ( waitForServer, BASE_PORT, BASE_RPC_PORT, BTC_BASE_PORT, BTC_BASE_RPC_PORT, + LTC_BASE_PORT, ) from basicswap.contrib.rpcauth import generate_salt, password_to_hmac @@ -44,7 +45,6 @@ XMR_BASE_P2P_PORT = 17792 XMR_BASE_RPC_PORT = 29798 XMR_BASE_WALLET_RPC_PORT = 29998 -LTC_BASE_PORT = 34792 LTC_BASE_RPC_PORT = 35792 LTC_BASE_ZMQ_PORT = 36792