Skip to content
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

[v10.10.0] Code cleaning #2937

Merged
merged 40 commits into from
Jan 17, 2025
Merged

[v10.10.0] Code cleaning #2937

merged 40 commits into from
Jan 17, 2025

Conversation

ouziel-slama
Copy link
Contributor

@ouziel-slama ouziel-slama commented Jan 13, 2025

  • Remove counterparty-wallet
  • Split vector file
  • Move python tests from counterparty-rs to counterparty-core
  • Reorganize files and functions, split too big files, delete all unused functions
  • Remove globals in lib/util.py and ledger.py
  • Use yoyo migrations to update database

  • Double-check the spelling and grammar of all strings, code comments, etc.
  • Double-check that all code is deterministic that needs to be
  • Add tests to cover any new or revised logic
  • Ensure that the test suite passes
  • Update the project release notes
  • Update the project documentation, as appropriate, with a corresponding Pull Request in the Documentation repository

@ouziel-slama ouziel-slama marked this pull request as draft January 13, 2025 13:18
@ouziel-slama ouziel-slama changed the title Code cleaning [v10.10.0] Code cleaning Jan 13, 2025
Base automatically changed from fixes to develop January 13, 2025 14:02
@@ -13,6 +14,13 @@

ID = 60

MAINNET_BURNS = {}
CURR_DIR = os.path.dirname(os.path.realpath(__file__))
with open(CURR_DIR + "/data/mainnet_burns.csv", "r") as f:

Check warning

Code scanning / pylint

Using open without explicitly specifying an encoding. Warning

Using open without explicitly specifying an encoding.
# N-of-2
if len(asm) == 5 and asm[3] == 2 and asm[4] == OP_CHECKMULTISIG: # noqa: F405
pubkeys, signatures_required = asm[1:3], asm[0]
if all([type(pubkey) == bytes for pubkey in pubkeys]): # noqa: E721

Check warning

Code scanning / pylint

Use isinstance() rather than type() for a typecheck. Warning

Use isinstance() rather than type() for a typecheck.
# N-of-3
if len(asm) == 6 and asm[4] == 3 and asm[5] == OP_CHECKMULTISIG: # noqa: F405
pubkeys, signatures_required = asm[1:4], asm[0]
if all([type(pubkey) == bytes for pubkey in pubkeys]): # noqa: E721

Check warning

Code scanning / pylint

Use a generator instead 'all(type(pubkey) == bytes for pubkey in pubkeys)'. Warning

Use a generator instead 'all(type(pubkey) == bytes for pubkey in pubkeys)'.
# N-of-3
if len(asm) == 6 and asm[4] == 3 and asm[5] == OP_CHECKMULTISIG: # noqa: F405
pubkeys, signatures_required = asm[1:4], asm[0]
if all([type(pubkey) == bytes for pubkey in pubkeys]): # noqa: E721

Check warning

Code scanning / pylint

Use isinstance() rather than type() for a typecheck. Warning

Use isinstance() rather than type() for a typecheck.
# Sum data chunks to get data. (Can mix OP_RETURN and multi-sig.)
asm = script.script_to_asm(script_pub_key)
if len(asm) == 2 and asm[0] == OP_RETURN: # OP_RETURN # noqa: F405
if type(asm[1]) != bytes: # noqa: E721

Check warning

Code scanning / pylint

Use isinstance() rather than type() for a typecheck. Warning

Use isinstance() rather than type() for a typecheck.
elif (
len(asm) == 5 and asm[0] == 1 and asm[3] == 2 and asm[4] == OP_CHECKMULTISIG # noqa: F405
): # Multi-sig
if type(asm[2]) != bytes: # noqa: E721

Check warning

Code scanning / pylint

Use isinstance() rather than type() for a typecheck. Warning

Use isinstance() rather than type() for a typecheck.
pubkeyhash_encoding = True
data_chunk_length = data_pubkey[0] # No ord() necessary.
data_chunk = data_pubkey[1 : data_chunk_length + 1]
if data_chunk[-8:] == config.PREFIX:

Check warning

Code scanning / pylint

Unnecessary "else" after "break", remove the "else" and de-indent the code inside it. Warning

Unnecessary "else" after "break", remove the "else" and de-indent the code inside it.
fee += vout_value

address = get_address(script_pubkey, block_index)
if not address:

Check warning

Code scanning / pylint

Unnecessary "else" after "raise", remove the "else" and de-indent the code inside it. Warning

Unnecessary "else" after "raise", remove the "else" and de-indent the code inside it.
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pylint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

return block_count + blocks_behind


class BackendHeight(metaclass=helpers.SingletonMeta):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh man, this is great

if util.enabled("multiple_dispenses"):
outs = ledger.get_vouts(db, tx["tx_hash"])
if protocol.enabled("multiple_dispenses"):
outs = ledger.ledger.get_vouts(db, tx["tx_hash"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a real nitpick but I don't love x.x imports. feels redundant

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(but I'm totally fine with it!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah completely agree! I need to split ledger.py is several files.. will be ledger.balances.* ledger.transactions.* etc..

]
# no sql injection here
sql = (
"SELECT asset, SUM(total) AS total FROM (" # noqa: S608

Check warning

Code scanning / Bandit

Possible SQL injection vector through string-based query construction. Warning

Possible SQL injection vector through string-based query construction.
if protocol.enabled("utxo_support") and utxosinfo.is_utxo_format(address):
field_name = "utxo"

query = f"""

Check warning

Code scanning / Bandit

Possible SQL injection vector through string-based query construction. Warning

Possible SQL injection vector through string-based query construction.
if protocol.enabled("utxo_support") and utxosinfo.is_utxo_format(address):
field_name = "utxo"

query = f"""

Check warning

Code scanning / Bandit

Possible SQL injection vector through string-based query construction. Warning

Possible SQL injection vector through string-based query construction.
if protocol.enabled("utxo_support") and utxosinfo.is_utxo_format(address):
field_name = "utxo"

query = f"""

Check warning

Code scanning / Bandit

Possible SQL injection vector through string-based query construction. Warning

Possible SQL injection vector through string-based query construction.
if protocol.enabled("utxo_support") and utxosinfo.is_utxo_format(address):
field_name = "utxo"

query = f"""

Check warning

Code scanning / Bandit

Possible SQL injection vector through string-based query construction. Warning

Possible SQL injection vector through string-based query construction.
set_data.append("block_index = :block_index")
bindings["block_index"] = CurrentState().current_block_index()
set_data = ", ".join(set_data)
sql = f"""UPDATE orders SET {set_data} WHERE tx_hash = :tx_hash""" # noqa S608

Check warning

Code scanning / Bandit

Possible SQL injection vector through string-based query construction. Warning

Possible SQL injection vector through string-based query construction.
def insert_record(db, table_name, record, event, event_info={}): # noqa: B006
fields = list(record.keys())
placeholders = ", ".join(["?" for _ in fields])
query = f"INSERT INTO {table_name} ({', '.join(fields)}) VALUES ({placeholders})" # noqa: S608

Check warning

Code scanning / Bandit

Possible SQL injection vector through string-based query construction. Warning

Possible SQL injection vector through string-based query construction.
cursor.execute("SELECT last_insert_rowid() AS rowid")
inserted_rowid = cursor.fetchone()["rowid"]
new_record = cursor.execute(
f"SELECT * FROM {table_name} WHERE rowid = ?", # noqa: S608

Check warning

Code scanning / Bandit

Possible SQL injection vector through string-based query construction. Warning

Possible SQL injection vector through string-based query construction.
@ouziel-slama ouziel-slama marked this pull request as ready for review January 16, 2025 20:51
Copy link
Member

@adamkrellenstein adamkrellenstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️❤️❤️❤️❤️❤️

@ouziel-slama ouziel-slama merged commit 7a558cf into develop Jan 17, 2025
19 checks passed
@ouziel-slama ouziel-slama deleted the cleaning branch January 17, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants