refactor: Add createRawSignedTransaction to interface

This commit is contained in:
tecnovert 2022-08-16 20:52:43 +02:00
parent b179667cc5
commit 48e5dcbcc9
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
3 changed files with 14 additions and 15 deletions

View file

@ -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)

View file

@ -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')

View file

@ -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