mirror of
https://github.com/basicswap/basicswap.git
synced 2024-12-22 19:49:20 +00:00
Lint
This commit is contained in:
parent
ec1671911b
commit
32df813731
7 changed files with 25 additions and 82 deletions
|
@ -6,7 +6,7 @@ lint_task:
|
||||||
- pip install flake8 codespell
|
- pip install flake8 codespell
|
||||||
script:
|
script:
|
||||||
- flake8 --version
|
- flake8 --version
|
||||||
- PYTHONWARNINGS="ignore" flake8 --ignore=E501,F841,W503 --exclude=basicswap/contrib,basicswap/interface/contrib,messages_pb2.py,.eggs,.tox,bin/install_certifi.py
|
- PYTHONWARNINGS="ignore" flake8 --ignore=E501,F841,W503,E702,E131 --exclude=basicswap/contrib,basicswap/interface/contrib,messages_pb2.py,.eggs,.tox,bin/install_certifi.py
|
||||||
- codespell --check-filenames --disable-colors --quiet-level=7 --ignore-words=tests/lint/spelling.ignore-words.txt -S .git,.eggs,.tox,pgp,*.pyc,*basicswap/contrib,*basicswap/interface/contrib,*mnemonics.py,bin/install_certifi.py,*basicswap/static
|
- codespell --check-filenames --disable-colors --quiet-level=7 --ignore-words=tests/lint/spelling.ignore-words.txt -S .git,.eggs,.tox,pgp,*.pyc,*basicswap/contrib,*basicswap/interface/contrib,*mnemonics.py,bin/install_certifi.py,*basicswap/static
|
||||||
|
|
||||||
test_task:
|
test_task:
|
||||||
|
|
|
@ -47,7 +47,6 @@ from .util import (
|
||||||
DeserialiseNum,
|
DeserialiseNum,
|
||||||
h2b,
|
h2b,
|
||||||
i2b,
|
i2b,
|
||||||
i2h,
|
|
||||||
zeroIfNone,
|
zeroIfNone,
|
||||||
make_int,
|
make_int,
|
||||||
ensure,
|
ensure,
|
||||||
|
@ -3009,7 +3008,6 @@ class BasicSwap(BaseApp):
|
||||||
lockExtraArgs['public_key'] = xmr_swap.pkal
|
lockExtraArgs['public_key'] = xmr_swap.pkal
|
||||||
lockExtraArgs['timelock'] = xmr_offer.lock_time_1
|
lockExtraArgs['timelock'] = xmr_offer.lock_time_1
|
||||||
|
|
||||||
|
|
||||||
xmr_swap.a_lock_tx_script = pi.genScriptLockTxScript(ci_from, xmr_swap.pkal, xmr_swap.pkaf, **lockExtraArgs)
|
xmr_swap.a_lock_tx_script = pi.genScriptLockTxScript(ci_from, xmr_swap.pkal, xmr_swap.pkaf, **lockExtraArgs)
|
||||||
prefunded_tx = self.getPreFundedTx(Concepts.OFFER, bid.offer_id, TxTypes.ITX_PRE_FUNDED, session=use_session)
|
prefunded_tx = self.getPreFundedTx(Concepts.OFFER, bid.offer_id, TxTypes.ITX_PRE_FUNDED, session=use_session)
|
||||||
if prefunded_tx:
|
if prefunded_tx:
|
||||||
|
|
|
@ -57,6 +57,7 @@ from coincurve.ecdsaotves import (
|
||||||
ecdsaotves_rec_enc_key,
|
ecdsaotves_rec_enc_key,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BCHInterface(BTCInterface):
|
class BCHInterface(BTCInterface):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def coin_type():
|
def coin_type():
|
||||||
|
@ -130,14 +131,6 @@ class BCHInterface(BTCInterface):
|
||||||
# Return P2PKH
|
# Return P2PKH
|
||||||
return CScript([OP_DUP, OP_HASH160, pkh, OP_EQUALVERIFY, OP_CHECKSIG])
|
return CScript([OP_DUP, OP_HASH160, pkh, OP_EQUALVERIFY, OP_CHECKSIG])
|
||||||
|
|
||||||
# def getScriptDest(self, script: bytearray) -> bytearray:
|
|
||||||
# # P2SH
|
|
||||||
|
|
||||||
# script_hash = hash160(script)
|
|
||||||
# assert len(script_hash) == 20
|
|
||||||
|
|
||||||
# return CScript([OP_HASH160, script_hash, OP_EQUAL])
|
|
||||||
|
|
||||||
def encodeScriptDest(self, script_dest: bytes) -> str:
|
def encodeScriptDest(self, script_dest: bytes) -> str:
|
||||||
# Extract hash from script
|
# Extract hash from script
|
||||||
script_hash = script_dest[2:-1]
|
script_hash = script_dest[2:-1]
|
||||||
|
@ -165,9 +158,6 @@ class BCHInterface(BTCInterface):
|
||||||
params = [addr_to, value, '', '', subfee, 0, False]
|
params = [addr_to, value, '', '', subfee, 0, False]
|
||||||
return self.rpc_wallet('sendtoaddress', params)
|
return self.rpc_wallet('sendtoaddress', params)
|
||||||
|
|
||||||
def getSpendableBalance(self) -> int:
|
|
||||||
return self.make_int(self.rpc('getwalletinfo')['unconfirmed_balance'])
|
|
||||||
|
|
||||||
def getBLockSpendTxFee(self, tx, fee_rate: int) -> int:
|
def getBLockSpendTxFee(self, tx, fee_rate: int) -> int:
|
||||||
add_bytes = 107
|
add_bytes = 107
|
||||||
size = len(tx.serialize_with_witness()) + add_bytes
|
size = len(tx.serialize_with_witness()) + add_bytes
|
||||||
|
@ -305,7 +295,7 @@ class BCHInterface(BTCInterface):
|
||||||
|
|
||||||
# // Refund will become available when timelock expires, and it would
|
# // Refund will become available when timelock expires, and it would
|
||||||
# // expire because Alice didn't collect on time, either of her own accord
|
# // expire because Alice didn't collect on time, either of her own accord
|
||||||
# // or because Bob bailed out and witheld the encrypted signature.
|
# // or because Bob bailed out and withheld the encrypted signature.
|
||||||
OP_ELSE,
|
OP_ELSE,
|
||||||
# // int timelock_0
|
# // int timelock_0
|
||||||
timelock,
|
timelock,
|
||||||
|
@ -360,15 +350,6 @@ class BCHInterface(BTCInterface):
|
||||||
tx.vout.append(self.txoType()(value, self.getScriptDest(script)))
|
tx.vout.append(self.txoType()(value, self.getScriptDest(script)))
|
||||||
return tx.serialize_without_witness()
|
return tx.serialize_without_witness()
|
||||||
|
|
||||||
def getScriptForPubkeyHash(self, pkh: bytes) -> CScript:
|
|
||||||
return CScript([
|
|
||||||
OP_DUP,
|
|
||||||
OP_HASH160,
|
|
||||||
pkh,
|
|
||||||
OP_EQUALVERIFY,
|
|
||||||
OP_CHECKSIG,
|
|
||||||
])
|
|
||||||
|
|
||||||
def getTxSize(self, tx: CTransaction) -> int:
|
def getTxSize(self, tx: CTransaction) -> int:
|
||||||
return len(tx.serialize_without_witness())
|
return len(tx.serialize_without_witness())
|
||||||
|
|
||||||
|
@ -505,37 +486,6 @@ class BCHInterface(BTCInterface):
|
||||||
def setTxSignature(self, tx_bytes: bytes, stack) -> bytes:
|
def setTxSignature(self, tx_bytes: bytes, stack) -> bytes:
|
||||||
return tx_bytes
|
return tx_bytes
|
||||||
|
|
||||||
def verifySCLockTx(self, tx_bytes, script_out,
|
|
||||||
swap_value,
|
|
||||||
Kal, Kaf,
|
|
||||||
feerate,
|
|
||||||
check_lock_tx_inputs, vkbv=None):
|
|
||||||
# Verify:
|
|
||||||
#
|
|
||||||
|
|
||||||
# Not necessary to check the lock txn is mineable, as protocol will wait for it to confirm
|
|
||||||
# However by checking early we can avoid wasting time processing unmineable txns
|
|
||||||
# Check fee is reasonable
|
|
||||||
|
|
||||||
tx = self.loadTx(tx_bytes)
|
|
||||||
txid = self.getTxid(tx)
|
|
||||||
self._log.info('Verifying lock tx: {}.'.format(b2h(txid)))
|
|
||||||
|
|
||||||
ensure(tx.nVersion == self.txVersion(), 'Bad version')
|
|
||||||
ensure(tx.nLockTime == 0, 'Bad nLockTime') # TODO match txns created by cores
|
|
||||||
|
|
||||||
script_pk = self.getScriptDest(script_out)
|
|
||||||
locked_n = findOutput(tx, script_pk)
|
|
||||||
ensure(locked_n is not None, 'Output not found in tx')
|
|
||||||
locked_coin = tx.vout[locked_n].nValue
|
|
||||||
|
|
||||||
# Check value
|
|
||||||
ensure(locked_coin == swap_value, 'Bad locked value')
|
|
||||||
|
|
||||||
# TODO: better script matching, see interfaces/btc.py
|
|
||||||
|
|
||||||
return txid, locked_n
|
|
||||||
|
|
||||||
def extractScriptLockScriptValuesFromScriptSig(self, script_bytes):
|
def extractScriptLockScriptValuesFromScriptSig(self, script_bytes):
|
||||||
signature, nb = decodePushData(script_bytes, 0)
|
signature, nb = decodePushData(script_bytes, 0)
|
||||||
if nb == len(script_bytes):
|
if nb == len(script_bytes):
|
||||||
|
@ -708,7 +658,6 @@ class BCHInterface(BTCInterface):
|
||||||
ensure(public_key == _public_key, 'public_key mismatch')
|
ensure(public_key == _public_key, 'public_key mismatch')
|
||||||
ensure(timelock == _timelock, 'timelock mismatch')
|
ensure(timelock == _timelock, 'timelock mismatch')
|
||||||
|
|
||||||
|
|
||||||
fee_paid = locked_coin - mining_fee
|
fee_paid = locked_coin - mining_fee
|
||||||
assert (fee_paid > 0)
|
assert (fee_paid > 0)
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ def decodeScriptNum(script_bytes, o):
|
||||||
v += int(b) << 8 * i
|
v += int(b) << 8 * i
|
||||||
return (v, 1 + num_len)
|
return (v, 1 + num_len)
|
||||||
|
|
||||||
|
|
||||||
def decodePushData(script_bytes, o):
|
def decodePushData(script_bytes, o):
|
||||||
datasize = None
|
datasize = None
|
||||||
pushdata_type = None
|
pushdata_type = None
|
||||||
|
@ -76,6 +77,7 @@ def decodePushData(script_bytes, o):
|
||||||
# return data and the number of bytes to skip forward
|
# return data and the number of bytes to skip forward
|
||||||
return (data, i + datasize - o)
|
return (data, i + datasize - o)
|
||||||
|
|
||||||
|
|
||||||
def getP2SHScriptForHash(p2sh):
|
def getP2SHScriptForHash(p2sh):
|
||||||
return bytes((OpCodes.OP_HASH160, 0x14)) \
|
return bytes((OpCodes.OP_HASH160, 0x14)) \
|
||||||
+ p2sh \
|
+ p2sh \
|
||||||
|
|
|
@ -11,15 +11,8 @@ bch_lock_swipe_script = '4c8fc3519dc4519d02e80300c600cc949d00ce00d18800cf00d2880
|
||||||
|
|
||||||
coin_settings = {'rpcport': 0, 'rpcauth': 'none', 'blocks_confirmed': 1, 'conf_target': 1, 'use_segwit': False, 'connection_type': 'rpc'}
|
coin_settings = {'rpcport': 0, 'rpcauth': 'none', 'blocks_confirmed': 1, 'conf_target': 1, 'use_segwit': False, 'connection_type': 'rpc'}
|
||||||
|
|
||||||
|
|
||||||
class TestXmrBchSwapInterface(unittest.TestCase):
|
class TestXmrBchSwapInterface(unittest.TestCase):
|
||||||
# def test_generate_script(self):
|
|
||||||
# out_1 = bytes.fromhex('a9147171b53baf87efc9c78ffc0e37a78859cebaae4a87')
|
|
||||||
# out_2 = bytes.fromhex('a9147171b53baf87efc9c78ffc0e37a78859cebaae4a87')
|
|
||||||
# public_key = bytes.fromhex('03fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556')
|
|
||||||
|
|
||||||
# ci = BCHInterface(coin_settings, "regtest")
|
|
||||||
# print(ci.genScriptLockTxScript(None, 1000, out_1, out_2, public_key, 2).hex())
|
|
||||||
|
|
||||||
def test_extractScriptLockScriptValues(self):
|
def test_extractScriptLockScriptValues(self):
|
||||||
ci = BCHInterface(coin_settings, "regtest")
|
ci = BCHInterface(coin_settings, "regtest")
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,6 @@ class TestFunctions(BaseTest):
|
||||||
extra_wait_time = 0
|
extra_wait_time = 0
|
||||||
test_coin_from = Coins.BCH
|
test_coin_from = Coins.BCH
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def callnoderpc(self, method, params=[], wallet=None, node_id=0):
|
def callnoderpc(self, method, params=[], wallet=None, node_id=0):
|
||||||
return callnoderpc(node_id, method, params, wallet, self.base_rpc_port)
|
return callnoderpc(node_id, method, params, wallet, self.base_rpc_port)
|
||||||
|
|
||||||
|
@ -86,6 +84,7 @@ class TestFunctions(BaseTest):
|
||||||
|
|
||||||
swap_clients[1].ci(Coins.XMR).setFeePriority(0)
|
swap_clients[1].ci(Coins.XMR).setFeePriority(0)
|
||||||
|
|
||||||
|
|
||||||
class TestBCH(BasicSwapTest):
|
class TestBCH(BasicSwapTest):
|
||||||
__test__ = True
|
__test__ = True
|
||||||
test_coin_from = Coins.BCH
|
test_coin_from = Coins.BCH
|
||||||
|
|
|
@ -241,9 +241,11 @@ def prepare_swapclient_dir(datadir, node_id, network_key, network_pubkey, with_c
|
||||||
def btcCli(cmd, node_id=0):
|
def btcCli(cmd, node_id=0):
|
||||||
return callrpc_cli(cfg.BITCOIN_BINDIR, os.path.join(TEST_DIR, 'btc_' + str(node_id)), 'regtest', cmd, cfg.BITCOIN_CLI)
|
return callrpc_cli(cfg.BITCOIN_BINDIR, os.path.join(TEST_DIR, 'btc_' + str(node_id)), 'regtest', cmd, cfg.BITCOIN_CLI)
|
||||||
|
|
||||||
|
|
||||||
def bchCli(cmd, node_id=0):
|
def bchCli(cmd, node_id=0):
|
||||||
return callrpc_cli(cfg.BITCOINCASH_BINDIR, os.path.join(TEST_DIR, 'bch_' + str(node_id)), 'regtest', cmd, cfg.BITCOINCASH_CLI)
|
return callrpc_cli(cfg.BITCOINCASH_BINDIR, os.path.join(TEST_DIR, 'bch_' + str(node_id)), 'regtest', cmd, cfg.BITCOINCASH_CLI)
|
||||||
|
|
||||||
|
|
||||||
def ltcCli(cmd, node_id=0):
|
def ltcCli(cmd, node_id=0):
|
||||||
return callrpc_cli(cfg.LITECOIN_BINDIR, os.path.join(TEST_DIR, 'ltc_' + str(node_id)), 'regtest', cmd, cfg.LITECOIN_CLI)
|
return callrpc_cli(cfg.LITECOIN_BINDIR, os.path.join(TEST_DIR, 'ltc_' + str(node_id)), 'regtest', cmd, cfg.LITECOIN_CLI)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue