-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exchange address support #53
Conversation
WalkthroughThe recent changes to Changes
Poem
Tip Early access features: disabledWe are currently testing the following features in early access:
Note:
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range and nitpick comments (11)
electrum_dash/constants.py (1)
Line range hint
44-44
: Avoid using bareexcept
statements.Using bare
except
can catch unexpected exceptions and obscure programming errors. Consider specifying the exception type or handling specific exceptions.- except: + except Exception as e: + # Handle or log the exception eAlso applies to: 55-55
electrum_dash/bitcoin.py (2)
Line range hint
26-26
: Remove unused imports.These imports are not used in the file and should be removed to clean up the code.
- import hashlib - from typing import List - from . import version - from .crypto import hmac_oneshotAlso applies to: 27-27, 32-32, 35-35
Line range hint
306-306
: Refactor to avoid multiple statements on one line.Multiple statements on a single line can reduce code readability. Consider refactoring to separate lines.
- if net is None: net = constants.net + if net is None: + net = constants.netAlso applies to: 372-372, 376-376, 380-380, 384-384, 388-388, 392-392, 403-403, 417-417, 443-443, 494-494, 667-667, 678-678
electrum_dash/plugins/ledger/ledger.py (1)
Line range hint
1-1
: Address unused imports and other static analysis findings.- from struct import pack, unpack - import sys - import traceback - from electrum_firo.transaction import PartialTransaction, PartialTxInput, PartialTxOutput - from electrum_firo.util import bh2u - import hid - from btchip.btchipComm import HIDDongleHIDAPI, DongleWait - from btchip.btchipUtils import compress_public_key, format_transaction, get_regular_input_script, get_p2sh_input_script - from btchip.btchipFirmwareWizard import checkFirmware, updateFirmware - indexOutput = 0 # This variable is assigned but never used - except: # Replace bare except with specific exceptions to handle + from btchip.btchipComm import HIDDongleHIDAPI + from btchip.btchipUtils import compress_public_key + from btchip.btchipFirmwareWizard import checkFirmwareThis change addresses multiple issues flagged by static analysis, including unused imports and a bare
except
statement. It's important to handle exceptions explicitly to avoid catching unexpected exceptions and to remove unused imports to keep the code clean and maintainable.Also applies to: 3-4, 16-16, 18-18, 37-41, 120-120, 683-683
electrum_dash/transaction.py (7)
Line range hint
31-31
: Remove unused import:traceback
.- import traceback
Tools
Ruff
45-45:
.util.profiler
imported but unused
49-49:
.bitcoin.push_script
imported but unused
50-50:
.bitcoin.add_number_to_script
imported but unused
Line range hint
32-32
: Remove unused import:sys
.- import sys
Tools
Ruff
45-45:
.util.profiler
imported but unused
49-49:
.bitcoin.push_script
imported but unused
50-50:
.bitcoin.add_number_to_script
imported but unused
Line range hint
35-35
: Remove unused import:typing.Iterable
.- from typing import (Sequence, Union, NamedTuple, Tuple, Optional, Iterable, + from typing import (Sequence, Union, NamedTuple, Tuple, Optional,Tools
Ruff
45-45:
.util.profiler
imported but unused
49-49:
.bitcoin.push_script
imported but unused
50-50:
.bitcoin.add_number_to_script
imported but unused
Line range hint
36-36
: Remove unused import:typing.Dict
.- from typing import (Sequence, Union, NamedTuple, Tuple, Optional, Iterable, - Callable, List, Dict, Set, TYPE_CHECKING) + from typing import (Sequence, Union, NamedTuple, Tuple, Optional, Iterable, + Callable, List, Set, TYPE_CHECKING)Tools
Ruff
45-45:
.util.profiler
imported but unused
49-49:
.bitcoin.push_script
imported but unused
50-50:
.bitcoin.add_number_to_script
imported but unused
Line range hint
384-384
: Refactor to avoid multiple statements on one line.- def read_boolean(self) -> bool: return self.read_bytes(1) != b'\x00' + def read_boolean(self) -> bool: + return self.read_bytes(1) != b'\x00'Also applies to: 385-385, 388-388, 389-389, 392-392, 393-393, 1017-1017, 1038-1038, 1057-1057, 1162-1162, 1168-1168, 1181-1181, 1192-1192, 1197-1197, 1356-1356, 1361-1361, 1451-1451, 1472-1472, 1494-1494, 1503-1503, 1507-1507
Tools
Ruff
45-45:
.util.profiler
imported but unused
49-49:
.bitcoin.push_script
imported but unused
50-50:
.bitcoin.add_number_to_script
imported but unused
Line range hint
928-928
: Replace bareexcept
with specific exceptions to avoid catching unexpected exceptions.- except: + except SpecificException:Also applies to: 933-933, 939-939
Tools
Ruff
45-45:
.util.profiler
imported but unused
49-49:
.bitcoin.push_script
imported but unused
50-50:
.bitcoin.add_number_to_script
imported but unused
Line range hint
1149-1149
: Remove f-strings without placeholders as they are unnecessary.- raise Exception(f"size {size} too large for compact_size") + raise Exception("size too large for compact_size")Also applies to: 1150-1150, 1154-1154, 1155-1155, 1459-1459, 1486-1486, 1589-1589, 1590-1590
Tools
Ruff
45-45:
.util.profiler
imported but unused
49-49:
.bitcoin.push_script
imported but unused
50-50:
.bitcoin.add_number_to_script
imported but unused
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- electrum_dash/bitcoin.py (8 hunks)
- electrum_dash/constants.py (4 hunks)
- electrum_dash/plugins/ledger/ledger.py (2 hunks)
- electrum_dash/transaction.py (8 hunks)
Additional context used
Ruff
electrum_dash/constants.py
44-44: Do not use bare
except
55-55: Do not use bare
except
electrum_dash/bitcoin.py
26-26:
hashlib
imported but unused
27-27:
typing.List
imported but unused
32-32:
.version
imported but unused
35-35:
.crypto.hmac_oneshot
imported but unused
306-306: Do not compare types, use
isinstance()
372-372: Multiple statements on one line (colon)
376-376: Multiple statements on one line (colon)
380-380: Multiple statements on one line (colon)
384-384: Multiple statements on one line (colon)
388-388: Multiple statements on one line (colon)
392-392: Multiple statements on one line (colon)
403-403: Multiple statements on one line (colon)
417-417: Multiple statements on one line (colon)
443-443: Multiple statements on one line (colon)
494-494: Multiple statements on one line (colon)
634-634: Local variable
e
is assigned to but never used
667-667: Multiple statements on one line (colon)
671-671: Local variable
e
is assigned to but never used
678-678: Multiple statements on one line (colon)
686-686: Local variable
e
is assigned to but never usedelectrum_dash/plugins/ledger/ledger.py
1-1:
struct.pack
imported but unused
1-1:
struct.unpack
imported but unused
3-3:
sys
imported but unused
4-4:
traceback
imported but unused
16-16:
electrum_firo.transaction.PartialTransaction
imported but unused
16-16:
electrum_firo.transaction.PartialTxInput
imported but unused
16-16:
electrum_firo.transaction.PartialTxOutput
imported but unused
18-18:
electrum_firo.util.bh2u
imported but unused
37-37:
btchip.btchipComm.DongleWait
imported but unused; consider usingimportlib.util.find_spec
to test for availability
39-39:
btchip.btchipUtils.format_transaction
imported but unused; consider usingimportlib.util.find_spec
to test for availability
39-39:
btchip.btchipUtils.get_regular_input_script
imported but unused; consider usingimportlib.util.find_spec
to test for availability
39-39:
btchip.btchipUtils.get_p2sh_input_script
imported but unused; consider usingimportlib.util.find_spec
to test for availability
41-41:
btchip.btchipFirmwareWizard.updateFirmware
imported but unused; consider usingimportlib.util.find_spec
to test for availability
120-120: Local variable
indexOutput
is assigned to but never used
683-683: Do not use bare
except
electrum_dash/transaction.py
31-31:
traceback
imported but unused
32-32:
sys
imported but unused
35-35:
typing.Iterable
imported but unused
36-36:
typing.Dict
imported but unused
45-45:
.util.profiler
imported but unused
49-49:
.bitcoin.push_script
imported but unused
50-50:
.bitcoin.add_number_to_script
imported but unused
384-384: Multiple statements on one line (colon)
385-385: Multiple statements on one line (colon)
388-388: Multiple statements on one line (colon)
389-389: Multiple statements on one line (colon)
392-392: Multiple statements on one line (colon)
393-393: Multiple statements on one line (colon)
928-928: Do not use bare
except
933-933: Do not use bare
except
939-939: Do not use bare
except
1017-1017: Multiple statements on one line (colon)
1038-1038: Multiple statements on one line (colon)
1057-1057: Multiple statements on one line (colon)
1149-1149: f-string without any placeholders
1150-1150: f-string without any placeholders
1154-1154: f-string without any placeholders
1155-1155: f-string without any placeholders
1162-1162: Multiple statements on one line (colon)
1168-1168: Multiple statements on one line (colon)
1181-1181: Multiple statements on one line (colon)
1192-1192: Multiple statements on one line (colon)
1197-1197: Multiple statements on one line (colon)
1356-1356: Multiple statements on one line (colon)
1361-1361: Multiple statements on one line (colon)
1451-1451: Multiple statements on one line (colon)
1459-1459: f-string without any placeholders
1472-1472: Multiple statements on one line (colon)
1486-1486: f-string without any placeholders
1494-1494: Multiple statements on one line (colon)
1503-1503: Multiple statements on one line (colon)
1507-1507: Multiple statements on one line (colon)
1589-1589: f-string without any placeholders
1590-1590: f-string without any placeholders
Additional comments not posted (15)
electrum_dash/constants.py (4)
79-79
: AddedADDRTYPE_EXP2PKH
toAbstractNet
class.This addition is consistent with the PR's objective to support the new
EXP2PKH
address type.
96-96
: AddedADDRTYPE_EXP2PKH
toBitcoinMainnet
class.This ensures that the mainnet configuration supports the new address type.
134-134
: AddedADDRTYPE_EXP2PKH
toBitcoinTestnet
class.This ensures that the testnet configuration supports the new address type.
172-172
: AddedADDRTYPE_EXP2PKH
toBitcoinRegtest
class.This ensures that the regtest configuration supports the new address type.
electrum_dash/bitcoin.py (9)
195-195
: AddedOP_EXCHANGEADDR
opcode.This addition is necessary for the new
EXP2PKH
address type operations.
363-369
: Updatedb58_address_to_hash160
to handle 21 and 23 byte addresses.This update is crucial for supporting the new
EXP2PKH
address type.
375-377
: Addedhash160_to_exp2pkh
function.This function is essential for converting hash160 to
EXP2PKH
addresses.Tools
Ruff
376-376: Multiple statements on one line (colon)
387-389
: Addedpublic_key_to_exp2pkh
function.This function supports converting public keys to
EXP2PKH
addresses, aligning with the new address type support.Tools
Ruff
388-388: Multiple statements on one line (colon)
395-396
: Updatedpubkey_to_address
to handleEXP2PKH
.This update ensures that the function can handle the new
EXP2PKH
address type.
423-424
: Updatedaddress_to_script
to handleEXP2PKH
.This update is necessary for script generation for
EXP2PKH
addresses.
437-437
: AddedEXP2PKH
toOnchainOutputType
.This addition is necessary for identifying
EXP2PKH
type outputs.
449-450
: Updatedaddress_to_hash
to handleEXP2PKH
.This update ensures that the function can correctly identify and handle
EXP2PKH
addresses.
477-485
: Addedpubkeyhash_to_exp2pkh_script
function.This function is essential for generating scripts for
EXP2PKH
addresses.electrum_dash/plugins/ledger/ledger.py (2)
300-300
: Ensure the new address typeEXP2PKH
is correctly integrated.This line correctly integrates the new
EXP2PKH
address type into thesetAlternateCoinVersions
function, aligning with the PR's objectives to support the new address type.
535-535
: Verify the handling of address types in the conditional logic.This verification is crucial to ensure that the handling of the new
EXP2PKH
address type is consistent and correct throughout the codebase.Verification successful
The handling of the
ADDRTYPE_EXP2PKH
address type appears to be consistent across the codebase. The search results show thatADDRTYPE_EXP2PKH
is used in relevant places alongsideADDRTYPE_P2PKH
, ensuring that the new address type is correctly integrated.
electrum_dash/transaction.py
electrum_dash/constants.py
electrum_dash/bitcoin.py
electrum_dash/plugins/ledger/ledger.py
These files include the necessary handling for
ADDRTYPE_EXP2PKH
, confirming that the integration is consistent.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the handling of address types in the conditional logic is correct and consistent across the codebase. # Test: Search for similar conditional logic handling address types. rg --type python $'if v == constants.net.ADDRTYPE_P2PKH or v == constants.net.ADDRTYPE_EXP2PKH'Length of output: 127
Script:
#!/bin/bash # Description: Verify that the handling of address types in the conditional logic is correct and consistent across the codebase. # Test: Search for similar conditional logic handling address types. rg --type py $'if v == constants.net.ADDRTYPE_P2PKH or v == constants.net.ADDRTYPE_EXP2PKH'Length of output: 232
Script:
#!/bin/bash # Description: Verify that the handling of address types is consistent across the codebase. # Test: Search for all instances where ADDRTYPE_P2PKH is used and check if ADDRTYPE_EXP2PKH is also handled. rg --type py 'ADDRTYPE_P2PKH'Length of output: 1299
Script:
#!/bin/bash # Description: Verify that the handling of ADDRTYPE_EXP2PKH is consistent across the codebase. # Test: Search for all instances where ADDRTYPE_EXP2PKH is used in the identified files. rg --type py 'ADDRTYPE_EXP2PKH'Length of output: 959
electrum_dash/transaction.py
Outdated
@@ -44,7 +44,7 @@ | |||
from .bip32 import BIP32Node | |||
from .util import profiler, to_bytes, bh2u, bfh, chunks, is_hex_str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import: .util.profiler
.
- from .util import profiler, to_bytes, bh2u, bfh, chunks, is_hex_str
+ from .util import to_bytes, bh2u, bfh, chunks, is_hex_str
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
from .util import profiler, to_bytes, bh2u, bfh, chunks, is_hex_str | |
from .util import to_bytes, bh2u, bfh, chunks, is_hex_str |
Tools
Ruff
45-45:
.util.profiler
imported but unused
electrum_dash/transaction.py
Outdated
int_to_hex, push_script, b58_address_to_hash160, | ||
opcodes, add_number_to_script, base_decode, base_encode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused imports: .bitcoin.push_script
and .bitcoin.add_number_to_script
.
- opcodes, add_number_to_script, base_decode, base_encode,
+ opcodes, base_decode, base_encode,
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
int_to_hex, push_script, b58_address_to_hash160, | |
opcodes, add_number_to_script, base_decode, base_encode, | |
int_to_hex, push_script, b58_address_to_hash160, | |
opcodes, base_decode, base_encode, |
Tools
Ruff
49-49:
.bitcoin.push_script
imported but unused
50-50:
.bitcoin.add_number_to_script
imported but unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- electrum_dash/bitcoin.py (9 hunks)
Additional context used
Ruff
electrum_dash/bitcoin.py
26-26:
hashlib
imported but unused (F401)
27-27:
typing.List
imported but unused (F401)
32-32:
.version
imported but unused (F401)
35-35:
.crypto.hmac_oneshot
imported but unused (F401)
306-306: Do not compare types, use
isinstance()
(E721)
377-377: Multiple statements on one line (colon) (E701)
381-381: Multiple statements on one line (colon) (E701)
385-385: Multiple statements on one line (colon) (E701)
389-389: Multiple statements on one line (colon) (E701)
393-393: Multiple statements on one line (colon) (E701)
397-397: Multiple statements on one line (colon) (E701)
408-408: Multiple statements on one line (colon) (E701)
422-422: Multiple statements on one line (colon) (E701)
448-448: Multiple statements on one line (colon) (E701)
499-499: Multiple statements on one line (colon) (E701)
639-639: Local variable
e
is assigned to but never used (F841)
672-672: Multiple statements on one line (colon) (E701)
676-676: Local variable
e
is assigned to but never used (F841)
683-683: Multiple statements on one line (colon) (E701)
691-691: Local variable
e
is assigned to but never used (F841)
Additional comments not posted (9)
electrum_dash/bitcoin.py (9)
195-196
: Added new opcodeOP_EXCHANGEADDR
forEXP2PKH
address type.This addition aligns with the PR's objective to support a new address type.
368-374
: Updatedb58_address_to_hash160
to handle addresses of 21 and 23 bytes.This update is necessary for supporting the new
EXP2PKH
address type.
380-383
: Introducedhash160_to_exp2pkh
function to convert hash160 toEXP2PKH
address.This function is essential for the new address type support.
Tools
Ruff
381-381: Multiple statements on one line (colon) (E701)
392-395
: Introducedpublic_key_to_exp2pkh
function to convert public key toEXP2PKH
address.This function is crucial for generating
EXP2PKH
addresses from public keys.Tools
Ruff
393-393: Multiple statements on one line (colon) (E701)
400-401
: Updatedpubkey_to_address
to supportEXP2PKH
address type.This update ensures that the function can handle the new address type.
428-429
: Updatedaddress_to_script
to handleEXP2PKH
address type.This update is necessary for script generation for the new address type.
442-442
: AddedEXP2PKH
toOnchainOutputType
.This addition is necessary to handle
EXP2PKH
outputs correctly.
454-455
: Updatedaddress_to_hash
to handleEXP2PKH
address type.This update ensures that the function can correctly identify and process
EXP2PKH
addresses.
482-490
: Introducedpubkeyhash_to_exp2pkh_script
function for generatingEXP2PKH
scripts.This function is essential for script generation for the new address type.
electrum_dash/bitcoin.py
Outdated
if addrtype == 185: | ||
first_byte = 1 | ||
third_byte = 187 | ||
s = first_byte.to_bytes(1, 'little') + bytes([addrtype]) + third_byte.to_bytes(1, 'little') + h160 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure consistent byte handling in hash160_to_b58_address
.
- first_byte = 1
- third_byte = 187
- s = first_byte.to_bytes(1, 'little') + bytes([addrtype]) + third_byte.to_bytes(1, 'little') + h160
+ s = bytes([1, addrtype, 187]) + h160
This change simplifies the byte handling and ensures that the bytes are correctly ordered.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if addrtype == 185: | |
first_byte = 1 | |
third_byte = 187 | |
s = first_byte.to_bytes(1, 'little') + bytes([addrtype]) + third_byte.to_bytes(1, 'little') + h160 | |
if addrtype == 185: | |
s = bytes([1, addrtype, 187]) + h160 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (13)
electrum_dash/bitcoin.py (6)
Line range hint
26-26
: Remove unused import:hashlib
.- import hashlib
Line range hint
27-27
: Remove unused import:typing.List
.- from typing import List
Line range hint
32-32
: Remove unused import:.version
.- from . import version
Line range hint
35-35
: Remove unused import:.crypto.hmac_oneshot
.- from .crypto import sha256d, sha256, hash_160, hmac_oneshot + from .crypto import sha256d, sha256, hash_160
Line range hint
210-210
: Convert to f-string for better readability and performance.- raise TypeError('{} instead of int'.format(i)) + raise TypeError(f'{i} instead of int') - raise OverflowError('cannot convert int {} to hex ({} bytes)'.format(i, length)) + raise OverflowError(f'cannot convert int {i} to hex ({length} bytes)') - raise ValueError('not supported base: {}'.format(base)) + raise ValueError(f'not supported base: {base}') - raise BitcoinException('unknown script type: {}'.format(txin_type)) + raise BitcoinException(f'unknown script type: {txin_type}') - raise BitcoinException(f'calculated {bh2u(csum_calculated)}, found {bh2u(csum_found)}') + raise BitcoinException(f'calculated {bh2u(csum_calculated)}, found {bh2u(csum_found)}') - raise BitcoinException('invalid prefix ({}) for WIF key (1)'.format(vch[0])) + raise BitcoinException(f'invalid prefix ({vch[0]}) for WIF key (1)') - raise BitcoinException('invalid prefix ({}) for WIF key (2)'.format(vch[0])) + raise BitcoinException(f'invalid prefix ({vch[0]}) for WIF key (2)') - raise BaseDecodeError(f"cannot deserialize privkey {neutered_privkey}") + raise BaseDecodeError(f"cannot deserialize privkey {neutered_privkey}") - raise BitcoinException('invalid WIF key. length suggests compressed pubkey, but last byte is {vch[33]} != 0x01') + raise BitcoinException(f'invalid WIF key. length suggests compressed pubkey, but last byte is {vch[33]} != 0x01')Also applies to: 213-213, 503-503, 537-537, 546-546, 613-613, 624-624, 637-637, 641-641, 644-644
Line range hint
636-636
: Remove assignment to unused variablee
.- except Exception as e: + except Exception:Also applies to: 673-673, 688-688
electrum_dash/transaction.py (7)
Line range hint
31-36
: Remove unused imports to clean up the codebase.- import traceback - import sys - from typing import Iterable, Dict
Line range hint
240-240
: Remove unnecessary inheritance fromobject
in Python 3.- class BCDataStream(object): + class BCDataStream:
Line range hint
384-393
: Useraise ... from None
to explicitly chain exceptions or suppress context.- except IndexError: raise MalformedBitcoinScript() + except IndexError: raise MalformedBitcoinScript() from None - except struct.error: raise MalformedBitcoinScript() + except struct.error: raise MalformedBitcoinScript() from None
Line range hint
928-939
: Avoid using bareexcept
statements. Specify exception types to catch specific errors.- except: + except Exception: - except: + except Exception: - except: + except Exception:
Line range hint
1147-1155
: Remove unnecessary f-string prefixes where no variables are being interpolated.- f"PSBT global xpub has mismatching depth ({bip32node.depth}) and derivation prefix len ({len(path)})" + "PSBT global xpub has mismatching depth ({}) and derivation prefix len ({})".format(bip32node.depth, len(path)) - f"PSBT global xpub has inconsistent child_number and derivation prefix" + "PSBT global xpub has inconsistent child_number and derivation prefix"
Line range hint
1352-1361
: Usecontextlib.suppress
instead oftry-except-pass
for cleaner exception handling when exceptions are to be ignored.from contextlib import suppress with suppress(ValueError): # your code here
Line range hint
1738-1738
: Convert.format()
to an f-string for consistency and readability.- "PSBT global xpub has mismatching depth ({}) and derivation prefix len ({})".format(bip32node.depth, len(path)) + f"PSBT global xpub has mismatching depth ({bip32node.depth}) and derivation prefix len ({len(path)})"
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- electrum_dash/bitcoin.py (9 hunks)
- electrum_dash/transaction.py (8 hunks)
Additional context used
Ruff
electrum_dash/bitcoin.py
1-1: UTF-8 encoding declaration is unnecessary (UP009)
Remove unnecessary coding comment
26-26:
hashlib
imported but unused (F401)Remove unused import:
hashlib
27-27:
typing.List
imported but unused (F401)Remove unused import:
typing.List
32-32:
.version
imported but unused (F401)Remove unused import:
.version
35-35:
.crypto.hmac_oneshot
imported but unused (F401)Remove unused import:
.crypto.hmac_oneshot
210-210: Use f-string instead of
format
call (UP032)Convert to f-string
213-213: Use f-string instead of
format
call (UP032)Convert to f-string
306-306: Do not compare types, use
isinstance()
(E721)
374-374: Multiple statements on one line (colon) (E701)
378-378: Multiple statements on one line (colon) (E701)
382-382: Multiple statements on one line (colon) (E701)
386-386: Multiple statements on one line (colon) (E701)
390-390: Multiple statements on one line (colon) (E701)
394-394: Multiple statements on one line (colon) (E701)
405-405: Multiple statements on one line (colon) (E701)
419-419: Multiple statements on one line (colon) (E701)
445-445: Multiple statements on one line (colon) (E701)
496-496: Multiple statements on one line (colon) (E701)
503-503: Use f-string instead of
format
call (UP032)Convert to f-string
537-537: Use f-string instead of
format
call (UP032)Convert to f-string
546-546: Use f-string instead of
format
call (UP032)Convert to f-string
613-613: Use f-string instead of
format
call (UP032)Convert to f-string
624-624: Use f-string instead of
format
call (UP032)Convert to f-string
636-636: Local variable
e
is assigned to but never used (F841)Remove assignment to unused variable
e
637-637: Use f-string instead of
format
call (UP032)Convert to f-string
641-641: Use f-string instead of
format
call (UP032)Convert to f-string
644-644: Use f-string instead of
format
call (UP032)Convert to f-string
669-669: Multiple statements on one line (colon) (E701)
673-673: Local variable
e
is assigned to but never used (F841)Remove assignment to unused variable
e
680-680: Multiple statements on one line (colon) (E701)
688-688: Local variable
e
is assigned to but never used (F841)Remove assignment to unused variable
e
electrum_dash/transaction.py
31-31:
traceback
imported but unused (F401)Remove unused import:
traceback
32-32:
sys
imported but unused (F401)Remove unused import:
sys
35-35:
typing.Iterable
imported but unused (F401)Remove unused import
36-36:
typing.Dict
imported but unused (F401)Remove unused import
240-240: Class
BCDataStream
inherits fromobject
(UP004)Remove
object
inheritance
384-384: Multiple statements on one line (colon) (E701)
385-385: Multiple statements on one line (colon) (E701)
385-385: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling (B904)
388-388: Multiple statements on one line (colon) (E701)
389-389: Multiple statements on one line (colon) (E701)
389-389: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling (B904)
392-392: Multiple statements on one line (colon) (E701)
393-393: Multiple statements on one line (colon) (E701)
393-393: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling (B904)
928-928: Do not use bare
except
(E722)
933-933: Do not use bare
except
(E722)
939-939: Do not use bare
except
(E722)
956-958: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling (B904)
1017-1017: Multiple statements on one line (colon) (E701)
1038-1038: Multiple statements on one line (colon) (E701)
1057-1057: Multiple statements on one line (colon) (E701)
1147-1148: Use a single
if
statement instead of nestedif
statements (SIM102)
1149-1149: f-string without any placeholders (F541)
Remove extraneous
f
prefix
1150-1150: f-string without any placeholders (F541)
Remove extraneous
f
prefix
1154-1154: f-string without any placeholders (F541)
Remove extraneous
f
prefix
1155-1155: f-string without any placeholders (F541)
Remove extraneous
f
prefix
1158-1161: Use
contextlib.suppress(ValueError)
instead oftry
-except
-pass
(SIM105)
1162-1162: Multiple statements on one line (colon) (E701)
1168-1168: Multiple statements on one line (colon) (E701)
1181-1181: Multiple statements on one line (colon) (E701)
1192-1192: Multiple statements on one line (colon) (E701)
1197-1197: Multiple statements on one line (colon) (E701)
1352-1355: Use
contextlib.suppress(ValueError)
instead oftry
-except
-pass
(SIM105)
1356-1356: Multiple statements on one line (colon) (E701)
1361-1361: Multiple statements on one line (colon) (E701)
1444-1447: Use
contextlib.suppress(ValueError)
instead oftry
-except
-pass
(SIM105)
1451-1451: Multiple statements on one line (colon) (E701)
1459-1459: f-string without any placeholders (F541)
Remove extraneous
f
prefix
1468-1471: Use
contextlib.suppress(ValueError)
instead oftry
-except
-pass
(SIM105)
1472-1472: Multiple statements on one line (colon) (E701)
1486-1486: f-string without any placeholders (F541)
Remove extraneous
f
prefix
1494-1494: Multiple statements on one line (colon) (E701)
1503-1503: Multiple statements on one line (colon) (E701)
1507-1507: Multiple statements on one line (colon) (E701)
1589-1589: f-string without any placeholders (F541)
Remove extraneous
f
prefix
1590-1590: f-string without any placeholders (F541)
Remove extraneous
f
prefix
1738-1738: Use f-string instead of
format
call (UP032)Convert to f-string
Additional comments not posted (2)
electrum_dash/bitcoin.py (2)
195-196
: Addition ofOP_EXCHANGEADDR
opcode.This new opcode is correctly defined and follows the existing pattern for opcode definitions.
355-356
: Enhancements to supportEXP2PKH
address type.The changes across these lines introduce and integrate the new
EXP2PKH
address type effectively, ensuring compatibility with existing functionalities and extending support as required.Also applies to: 365-371, 377-380, 389-392, 397-398, 425-426, 451-452, 479-487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
electrum_dash/plugins/trezor/trezor.py (1)
Line range hint
1-1
: Clean up code by addressing static analysis findings.Remove unused imports and improve code style by using f-strings and simplifying conditional structures.
- import traceback - import sys - from typing import NamedTuple, Any, Optional, Dict, Union, List, Tuple, TYPE_CHECKING - from electrum_firo.util import bfh, bh2u, versiontuple, UserCancelled, UserFacingException - from electrum_firo.bip32 import BIP32Node, convert_bip32_path_to_list_of_uint32 as parse_path - from electrum_firo.transaction import Transaction, PartialTransaction, PartialTxInput, PartialTxOutput + from electrum_firo.util import bfh, bh2u, UserCancelled, UserFacingException + from electrum_firo.bip32 import BIP32Node + from electrum_firo.transaction import Transaction, PartialTransaction, PartialTxInput - raise ValueError('unexpected txin type: {}'.format(electrum_txin_type)) + raise ValueError(f'unexpected txin type: {electrum_txin_type}') - if txin.script_sig.startswith(b"\xc4") and txin.nsequence == 0xffffffff: - prev_index = 1 - else: - prev_index = txin.nsequence + prev_index = 1 if txin.script_sig.startswith(b"\xc4") and txin.nsequence == 0xffffffff else txin.nsequenceAlso applies to: 2-2, 3-3, 5-5, 6-6, 11-11, 327-327, 334-334, 464-469
Tools
Ruff
327-327: Use f-string instead of
format
callConvert to f-string
(UP032)
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- electrum_dash/plugins/trezor/trezor.py (1 hunks)
Additional context used
Ruff
electrum_dash/plugins/trezor/trezor.py
1-1:
traceback
imported but unusedRemove unused import:
traceback
(F401)
2-2:
sys
imported but unusedRemove unused import:
sys
(F401)
3-3:
typing.Dict
imported but unusedRemove unused import
(F401)
3-3:
typing.Union
imported but unusedRemove unused import
(F401)
3-3:
typing.List
imported but unusedRemove unused import
(F401)
3-3:
typing.Tuple
imported but unusedRemove unused import
(F401)
3-3:
typing.TYPE_CHECKING
imported but unusedRemove unused import
(F401)
5-5:
electrum_firo.util.versiontuple
imported but unusedRemove unused import:
electrum_firo.util.versiontuple
(F401)
6-6:
electrum_firo.bip32.convert_bip32_path_to_list_of_uint32
imported but unusedRemove unused import:
electrum_firo.bip32.convert_bip32_path_to_list_of_uint32
(F401)
11-11:
electrum_firo.transaction.PartialTxOutput
imported but unusedRemove unused import:
electrum_firo.transaction.PartialTxOutput
(F401)
327-327: Use f-string instead of
format
callConvert to f-string
(UP032)
334-334: Use f-string instead of
format
callConvert to f-string
(UP032)
464-469: Use a single
if
statement instead of nestedif
statements(SIM102)
Additional comments not posted (2)
electrum_dash/plugins/trezor/trezor.py (2)
323-323
: Approved the addition ofexp2pkh
support in input script type handling.The update correctly extends the existing functionality to include the new address type, aligning with the PR objectives.
330-330
: Approved the addition ofexp2pkh
support in output script type handling.This change ensures that the new address type can be correctly processed during transaction outputs, maintaining consistency with the overall PR objectives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (3)
electrum_dash/plugins/ledger/ledger.py (3)
Line range hint
1-1
: Remove unused imports.Several imports are unused and should be removed to clean up the codebase:
struct.pack
,struct.unpack
sys
traceback
PartialTransaction
,PartialTxInput
,PartialTxOutput
fromelectrum_firo.transaction
bh2u
fromelectrum_firo.util
- Several from
btchip.btchipComm
,btchip.btchipUtils
, andbtchip.btchipFirmwareWizard
- from struct import pack, unpack - import sys - import traceback - from electrum_firo.transaction import Transaction, PartialTransaction, PartialTxInput, PartialTxOutput - from electrum_firo.util import bfh, bh2u, versiontuple, UserFacingException - from btchip.btchipComm import HIDDongleHIDAPI, DongleWait - from btchip.btchipUtils import compress_public_key, format_transaction, get_regular_input_script, get_p2sh_input_script - from btchip.btchipFirmwareWizard import checkFirmware, updateFirmwareAlso applies to: 3-4, 16-16, 18-18, 37-41
Line range hint
68-68
: Improve exception handling and formatting.
- Use
raise ... from e
for clearer exception chaining.- Replace percent formatting with
.format()
or f-strings for better readability and performance.- params = bytearray.fromhex("%.8x" % (index)) + params = bytearray.fromhex("{:08x}".format(index)) - raise UserFacingException(_('Your Ledger is locked. Please unlock it.')) + raise UserFacingException(_('Your Ledger is locked. Please unlock it.')) from eAlso applies to: 82-82, 304-310
Line range hint
120-120
: Code Quality Improvements: Unused Variables and Nested If Statements.
- Remove the unused variable
indexOutput
.- Simplify nested
if
statements for better readability.- indexOutput = 0 # Remove this line as it's unused - if client_electrum.is_hw1() and txout.address and not is_b58_address(txout.address): + if client_electrum.is_hw1() and txout.address and not is_b58_address(txout.address): - if v == constants.net.ADDRTYPE_P2PKH: + if v in [constants.net.ADDRTYPE_P2PKH, constants.net.ADDRTYPE_EXP2PKH]: + output = hash160_to_b58_address(h, 0 if v == constants.net.ADDRTYPE_P2PKH else 185)Also applies to: 189-192, 501-502
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- electrum_dash/plugins/ledger/ledger.py (2 hunks)
Additional context used
Ruff
electrum_dash/plugins/ledger/ledger.py
1-1:
struct.pack
imported but unusedRemove unused import
(F401)
1-1:
struct.unpack
imported but unusedRemove unused import
(F401)
3-3:
sys
imported but unusedRemove unused import:
sys
(F401)
4-4:
traceback
imported but unusedRemove unused import:
traceback
(F401)
16-16:
electrum_firo.transaction.PartialTransaction
imported but unusedRemove unused import
(F401)
16-16:
electrum_firo.transaction.PartialTxInput
imported but unusedRemove unused import
(F401)
16-16:
electrum_firo.transaction.PartialTxOutput
imported but unusedRemove unused import
(F401)
18-18:
electrum_firo.util.bh2u
imported but unusedRemove unused import:
electrum_firo.util.bh2u
(F401)
37-37:
btchip.btchipComm.DongleWait
imported but unused; consider usingimportlib.util.find_spec
to test for availability(F401)
39-39:
btchip.btchipUtils.format_transaction
imported but unused; consider usingimportlib.util.find_spec
to test for availability(F401)
39-39:
btchip.btchipUtils.get_regular_input_script
imported but unused; consider usingimportlib.util.find_spec
to test for availability(F401)
39-39:
btchip.btchipUtils.get_p2sh_input_script
imported but unused; consider usingimportlib.util.find_spec
to test for availability(F401)
41-41:
btchip.btchipFirmwareWizard.updateFirmware
imported but unused; consider usingimportlib.util.find_spec
to test for availability(F401)
68-68: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
82-82: Use format specifiers instead of percent format
Replace with format specifiers
(UP031)
120-120: Local variable
indexOutput
is assigned to but never usedRemove assignment to unused variable
indexOutput
(F841)
189-192: Use a single
if
statement instead of nestedif
statements(SIM102)
304-304: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
306-306: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
309-310: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
501-502: Use a single
if
statement instead of nestedif
statements(SIM102)
685-685: Do not use bare
except
(E722)
Additional comments not posted (1)
electrum_dash/plugins/ledger/ledger.py (1)
300-300
: Update to support EXP2PKH address type.The changes to the
perform_hw1_preflight
andsign_transaction
methods include support for the newEXP2PKH
address type by setting alternate coin versions and handling base58 address conversions. These are crucial updates for the functionality of the new address type.Also applies to: 537-538
Summary by CodeRabbit
New Features
EXP2PKH
.EXP2PKH
.Enhancements
EXP2PKH
type to Ledger and Trezor plugins for improved hardware wallet compatibility.EXP2PKH
type.Bug Fixes
These updates improve compatibility and support for a new address type, enhancing both usability and security.