refactor: E275 missing whitespace after keyword

This commit is contained in:
tecnovert
2022-07-31 20:01:49 +02:00
parent 1601a57aed
commit 1c4f208d27
29 changed files with 295 additions and 295 deletions

View File

@@ -519,13 +519,13 @@ class BasicSwap(BaseApp):
with open(pidfilepath, 'rb') as fp:
datadir_pid = int(fp.read().decode('utf-8'))
assert(datadir_pid == cc['pid']), 'Mismatched pid'
assert(os.path.exists(authcookiepath))
assert (datadir_pid == cc['pid']), 'Mismatched pid'
assert (os.path.exists(authcookiepath))
except Exception:
self.delay_event.wait(0.5)
try:
if os.name != 'nt' or cc['core_version_group'] > 17: # Litecoin on windows doesn't write a pid file
assert(datadir_pid == cc['pid']), 'Mismatched pid'
assert (datadir_pid == cc['pid']), 'Mismatched pid'
with open(authcookiepath, 'rb') as fp:
cc['rpcauth'] = fp.read().decode('utf-8')
except Exception as e:
@@ -2074,7 +2074,7 @@ class BasicSwap(BaseApp):
else:
xmr_swap.kbsf_dleag = xmr_swap.pkbsf
xmr_swap.pkasf = xmr_swap.kbsf_dleag[0: 33]
assert(xmr_swap.pkasf == ci_from.getPubkey(kbsf))
assert (xmr_swap.pkasf == ci_from.getPubkey(kbsf))
msg_buf.pkaf = xmr_swap.pkaf
msg_buf.kbvf = kbvf
@@ -2432,7 +2432,7 @@ class BasicSwap(BaseApp):
amount_to = bid.amount_to
# Check required?
assert(amount_to == (bid.amount * bid.rate) // self.ci(offer.coin_from).COIN())
assert (amount_to == (bid.amount * bid.rate) // self.ci(offer.coin_from).COIN())
if bid.debug_ind == DebugTypes.MAKE_INVALID_PTX:
amount_to -= 1
@@ -2536,7 +2536,7 @@ class BasicSwap(BaseApp):
if addr_redeem_out is None:
addr_redeem_out = self.getReceiveAddressFromPool(coin_type, bid.bid_id, TxTypes.PTX_REDEEM if for_txn_type == 'participate' else TxTypes.ITX_REDEEM)
assert(addr_redeem_out is not None)
assert (addr_redeem_out is not None)
if self.coin_clients[coin_type]['use_segwit']:
# Change to btc hrp
@@ -3102,7 +3102,7 @@ class BasicSwap(BaseApp):
return rv
def checkBidState(self, bid_id, bid, offer):
# assert(self.mxDB.locked())
# assert (self.mxDB.locked())
# Return True to remove bid from in-progress list
state = BidStates(bid.state)
@@ -3484,7 +3484,7 @@ class BasicSwap(BaseApp):
self.initiateTxnSpent(watched_output.bid_id, spend_txid_hex, spend_n, spend_txn)
def checkForSpends(self, coin_type, c):
# assert(self.mxDB.locked())
# assert (self.mxDB.locked())
self.log.debug('checkForSpends %s', coin_type)
# TODO: Check for spends on watchonly txns where possible
@@ -3935,7 +3935,7 @@ class BasicSwap(BaseApp):
self.validateBidAmount(offer, bid_data.amount, bid_data.rate)
# TODO: Allow higher bids
# assert(bid_data.rate != offer['data'].rate), 'Bid rate mismatch'
# assert (bid_data.rate != offer['data'].rate), 'Bid rate mismatch'
coin_to = Coins(offer.coin_to)
ci_from = self.ci(offer.coin_from)
@@ -4641,7 +4641,7 @@ class BasicSwap(BaseApp):
xmr_swap.al_lock_spend_tx_sig = ci_from.extractLeaderSig(xmr_swap.a_lock_spend_tx)
kbsf = ci_from.recoverEncKey(xmr_swap.al_lock_spend_tx_esig, xmr_swap.al_lock_spend_tx_sig, xmr_swap.pkasf)
assert(kbsf is not None)
assert (kbsf is not None)
for_ed25519 = True if coin_to == Coins.XMR else False
kbsl = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KBSL, for_ed25519)
@@ -4697,7 +4697,7 @@ class BasicSwap(BaseApp):
af_lock_refund_spend_tx_sig = ci_from.extractFollowerSig(xmr_swap.a_lock_refund_spend_tx)
kbsl = ci_from.recoverEncKey(xmr_swap.af_lock_refund_spend_tx_esig, af_lock_refund_spend_tx_sig, xmr_swap.pkasl)
assert(kbsl is not None)
assert (kbsl is not None)
for_ed25519 = True if coin_to == Coins.XMR else False
kbsf = self.getPathKey(coin_from, coin_to, bid.created_at, xmr_swap.contract_count, KeyTypes.KBSF, for_ed25519)

View File

@@ -75,7 +75,7 @@ class ExplorerBitAps(Explorer):
# Can't get unspents return only if exactly one transaction exists
data = json.loads(self.readURL(self.base_url + '/address/transactions/' + address))
try:
assert(data['data']['list'] == 1)
assert data['data']['list'] == 1
except Exception as ex:
self.log.debug('Explorer error: {}'.format(str(ex)))
return None

View File

@@ -356,7 +356,7 @@ class HttpHandler(BaseHTTPRequestHandler):
ensure(len(url_split) > 2, 'Bid ID not specified')
try:
bid_id = bytes.fromhex(url_split[2])
assert(len(bid_id) == 28)
assert len(bid_id) == 28
except Exception:
raise ValueError('Bad bid ID')
swap_client = self.server.swap_client

View File

@@ -157,7 +157,7 @@ class BTCInterface(CoinInterface):
@staticmethod
def getExpectedSequence(lockType, lockVal):
assert(lockVal >= 1), 'Bad lockVal'
assert (lockVal >= 1), 'Bad lockVal'
if lockType == TxLockTypes.SEQUENCE_LOCK_BLOCKS:
return lockVal
if lockType == TxLockTypes.SEQUENCE_LOCK_TIME:
@@ -289,7 +289,7 @@ class BTCInterface(CoinInterface):
except Exception:
try:
fee_rate = self.rpc_callback('getwalletinfo')['paytxfee'], 'paytxfee'
assert(fee_rate > 0.0), '0 feerate'
assert (fee_rate > 0.0), '0 feerate'
return fee_rate
except Exception:
return self.rpc_callback('getnetworkinfo')['relayfee'], 'relayfee'
@@ -311,7 +311,7 @@ class BTCInterface(CoinInterface):
def pkh_to_address(self, pkh):
# pkh is hash160(pk)
assert(len(pkh) == 20)
assert (len(pkh) == 20)
prefix = self.chainparams_network()['pubkey_address']
data = bytes((prefix,)) + pkh
checksum = hashlib.sha256(hashlib.sha256(data).digest()).digest()
@@ -327,7 +327,7 @@ class BTCInterface(CoinInterface):
return pubkeyToAddress(self.chainparams_network()['script_address'], script)
def pubkey_to_address(self, pk):
assert(len(pk) == 33)
assert (len(pk) == 33)
return self.pkh_to_address(hash160(pk))
def getNewSecretKey(self):
@@ -342,7 +342,7 @@ class BTCInterface(CoinInterface):
def verifyKey(self, k):
i = b2i(k)
return(i < ep.o and i > 0)
return (i < ep.o and i > 0)
def verifyPubkey(self, pubkey_bytes):
return verify_secp256k1_point(pubkey_bytes)
@@ -629,7 +629,7 @@ class BTCInterface(CoinInterface):
for txo in tx.vout:
outputs_value += txo.nValue
fee_paid = inputs_value - outputs_value
assert(fee_paid > 0)
assert (fee_paid > 0)
vsize = self.getTxVSize(tx, add_bytes, add_witness_bytes)
fee_rate_paid = fee_paid * 1000 // vsize
@@ -677,7 +677,7 @@ class BTCInterface(CoinInterface):
ensure(C == Kaf, 'Bad script pubkey')
fee_paid = swap_value - locked_coin
assert(fee_paid > 0)
assert (fee_paid > 0)
dummy_witness_stack = self.getScriptLockTxDummyWitness(prevout_script)
witness_bytes = self.getWitnessStackSerialisedLength(dummy_witness_stack)
@@ -721,7 +721,7 @@ class BTCInterface(CoinInterface):
tx_value = tx.vout[0].nValue
fee_paid = prevout_value - tx_value
assert(fee_paid > 0)
assert (fee_paid > 0)
dummy_witness_stack = self.getScriptLockRefundSpendTxDummyWitness(prevout_script)
witness_bytes = self.getWitnessStackSerialisedLength(dummy_witness_stack)
@@ -768,7 +768,7 @@ class BTCInterface(CoinInterface):
# The value of the lock tx output should already be verified, if the fee is as expected the difference will be the correct amount
fee_paid = locked_coin - tx.vout[0].nValue
assert(fee_paid > 0)
assert (fee_paid > 0)
dummy_witness_stack = self.getScriptLockTxDummyWitness(lock_tx_script)
witness_bytes = self.getWitnessStackSerialisedLength(dummy_witness_stack)
@@ -1065,7 +1065,7 @@ class BTCInterface(CoinInterface):
message_hash = hashlib.sha256(bytes(message, 'utf-8')).digest()
pubkey = PublicKey(K)
rv = pubkey.verify_compact(sig, message_hash, hasher=None)
assert(rv is True)
assert (rv is True)
def verifyMessage(self, address, message, signature, message_magic=None) -> bool:
if message_magic is None:

View File

@@ -172,7 +172,7 @@ class PARTInterfaceBlind(PARTInterface):
# Nonce is derived from vkbv, ephemeral_key isn't used
ephemeral_key = i2b(self.getNewSecretKey())
ephemeral_pubkey = self.getPubkey(ephemeral_key)
assert(len(ephemeral_pubkey) == 33)
assert (len(ephemeral_pubkey) == 33)
nonce = self.getScriptLockTxNonce(vkbv)
p2wsh_addr = self.encode_p2wsh(getP2WSH(script))
inputs = []
@@ -192,7 +192,7 @@ class PARTInterfaceBlind(PARTInterface):
tx_obj = self.rpc_callback('decoderawtransaction', [tx_hex])
assert(len(tx_obj['vout']) == 1)
assert (len(tx_obj['vout']) == 1)
txo = tx_obj['vout'][0]
blinded_info = self.rpc_callback('rewindrangeproof', [txo['rangeproof'], txo['valueCommitment'], nonce.hex()])
@@ -207,11 +207,11 @@ class PARTInterfaceBlind(PARTInterface):
def createScriptLockRefundTx(self, tx_lock_bytes, script_lock, Kal, Kaf, lock1_value, csv_val, tx_fee_rate, vkbv):
lock_tx_obj = self.rpc_callback('decoderawtransaction', [tx_lock_bytes.hex()])
assert(self.getTxid(tx_lock_bytes).hex() == lock_tx_obj['txid'])
assert (self.getTxid(tx_lock_bytes).hex() == lock_tx_obj['txid'])
# Nonce is derived from vkbv, ephemeral_key isn't used
ephemeral_key = i2b(self.getNewSecretKey())
ephemeral_pubkey = self.getPubkey(ephemeral_key)
assert(len(ephemeral_pubkey) == 33)
assert (len(ephemeral_pubkey) == 33)
nonce = self.getScriptLockTxNonce(vkbv)
output_nonce = self.getScriptLockRefundTxNonce(vkbv)
@@ -675,7 +675,7 @@ class PARTInterfaceAnon(PARTInterface):
if len(txns) == 1:
tx = txns[0]
assert(tx['outputs'][0]['stealth_address'] == sx_addr) # Should not be possible
assert (tx['outputs'][0]['stealth_address'] == sx_addr) # Should not be possible
ensure(tx['outputs'][0]['type'] == 'anon', 'Output is not anon')
if make_int(tx['outputs'][0]['amount']) == cb_swap_value:

View File

@@ -199,7 +199,7 @@ class XMRInterface(CoinInterface):
def verifyKey(self, k):
i = b2i(k)
return(i < edf.l and i > 8)
return (i < edf.l and i > 8)
def verifyPubkey(self, pubkey_bytes):
# Calls ed25519_decode_check_point() in secp256k1

View File

@@ -143,18 +143,18 @@ def js_offers(self, url_split, post_string, is_json, sent=False):
if have_data_entry(post_data, 'sort_by'):
sort_by = get_data_entry(post_data, 'sort_by')
assert(sort_by in ['created_at', 'rate']), 'Invalid sort by'
assert (sort_by in ['created_at', 'rate']), 'Invalid sort by'
filters['sort_by'] = sort_by
if have_data_entry(post_data, 'sort_dir'):
sort_dir = get_data_entry(post_data, 'sort_dir')
assert(sort_dir in ['asc', 'desc']), 'Invalid sort dir'
assert (sort_dir in ['asc', 'desc']), 'Invalid sort dir'
filters['sort_dir'] = sort_dir
if b'offset' in post_data:
filters['offset'] = int(get_data_entry(post_data, 'offset'))
if b'limit' in post_data:
filters['limit'] = int(get_data_entry(post_data, 'limit'))
assert(filters['limit'] > 0 and filters['limit'] <= PAGE_LIMIT), 'Invalid limit'
assert (filters['limit'] > 0 and filters['limit'] <= PAGE_LIMIT), 'Invalid limit'
offers = self.server.swap_client.listOffers(sent, filters)
rv = []
@@ -194,10 +194,10 @@ def js_bids(self, url_split, post_string, is_json):
post_data = urllib.parse.parse_qs(post_string)
offer_id = bytes.fromhex(get_data_entry(post_data, 'offer_id'))
assert(len(offer_id) == 28)
assert (len(offer_id) == 28)
offer = swap_client.getOffer(offer_id)
assert(offer), 'Offer not found.'
assert (offer), 'Offer not found.'
ci_from = swap_client.ci(offer.coin_from)
ci_to = swap_client.ci(offer.coin_to)
@@ -236,7 +236,7 @@ def js_bids(self, url_split, post_string, is_json):
return bytes(json.dumps(rv), 'UTF-8')
bid_id = bytes.fromhex(url_split[3])
assert(len(bid_id) == 28)
assert (len(bid_id) == 28)
if post_string != '':
if is_json:
@@ -250,7 +250,7 @@ def js_bids(self, url_split, post_string, is_json):
swap_client.setBidDebugInd(bid_id, int(get_data_entry(post_data, 'debugind')))
bid, xmr_swap, offer, xmr_offer, events = swap_client.getXmrBidAndOffer(bid_id)
assert(bid), 'Unknown bid ID'
assert (bid), 'Unknown bid ID'
if post_string != '':
if have_data_entry(post_data, 'chainbkeysplit'):
@@ -290,7 +290,7 @@ def js_network(self, url_split, post_string, is_json):
def js_revokeoffer(self, url_split, post_string, is_json):
offer_id = bytes.fromhex(url_split[3])
assert(len(offer_id) == 28)
assert (len(offer_id) == 28)
self.server.swap_client.revokeOffer(offer_id)
return bytes(json.dumps({'revoked_offer': offer_id.hex()}), 'UTF-8')

View File

@@ -56,7 +56,7 @@ def SerialiseNum(n):
rv = bytearray()
neg = n < 0
absvalue = -n if neg else n
while(absvalue):
while (absvalue):
rv.append(absvalue & 0xff)
absvalue >>= 8
if rv[-1] & 0x80:

View File

@@ -114,7 +114,7 @@ def decodeAddress(address_str):
if b58_addr is not None:
address = b58_addr[:-4]
checksum = b58_addr[-4:]
assert(hashlib.sha256(hashlib.sha256(address).digest()).digest()[:4] == checksum), 'Checksum mismatch'
assert (hashlib.sha256(hashlib.sha256(address).digest()).digest()[:4] == checksum), 'Checksum mismatch'
return b58_addr[:-4]
return None

View File

@@ -171,18 +171,18 @@ def testEccUtils():
print('testEccUtils()')
G_enc = ToDER(G)
assert(G_enc.hex() == '0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8')
assert (G_enc.hex() == '0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8')
G_enc = pointToCPK(G)
assert(G_enc.hex() == '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')
assert (G_enc.hex() == '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')
G_dec = CPKToPoint(G_enc)
assert(G_dec == G)
assert (G_dec == G)
G_enc = pointToCPK2(G)
assert(G_enc.hex() == '0879be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')
assert (G_enc.hex() == '0879be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')
H = hashToCurve(ToDER(G))
assert(pointToCPK(H).hex() == '0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0')
assert (pointToCPK(H).hex() == '0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0')
print('Passed.')

View File

@@ -14,7 +14,7 @@ def rfc2440_hash_password(password, salt=None):
if salt is None:
salt = secrets.token_bytes(8)
assert(len(salt) == 8)
assert len(salt) == 8
hashbytes = salt + password.encode('utf-8')
len_hashbytes = len(hashbytes)

View File

@@ -13,7 +13,7 @@ def decodeScriptNum(script_bytes, o):
v = 0
num_len = script_bytes[o]
if num_len >= OpCodes.OP_1 and num_len <= OpCodes.OP_16:
return((num_len - OpCodes.OP_1) + 1, 1)
return ((num_len - OpCodes.OP_1) + 1, 1)
if num_len > 4:
raise ValueError('Bad scriptnum length') # Max 4 bytes
@@ -29,7 +29,7 @@ def decodeScriptNum(script_bytes, o):
v *= -1
else:
v += int(b) << 8 * i
return(v, 1 + num_len)
return (v, 1 + num_len)
def getP2SHScriptForHash(p2sh):