Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Sourcery Starbot ⭐ refactored sambarnes/factom-core#19

Open
SourceryAI wants to merge 1 commit into
sambarnes:masterfrom
SourceryAI:master
Open

Sourcery Starbot ⭐ refactored sambarnes/factom-core#19
SourceryAI wants to merge 1 commit into
sambarnes:masterfrom
SourceryAI:master

Conversation

@SourceryAI

Copy link
Copy Markdown

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/factom-core master
git merge --ff-only FETCH_HEAD
git reset HEAD^

def __post_init__(self):
assert len(self.chain_id) == 32, "chain_id must be a bytes object of length 32"
assert self.hash_type == 0 or self.hash_type == 1, "hash_type must be 0 (p2pkh) or 1 (p2sh)"
assert self.hash_type in [0, 1], "hash_type must be 0 (p2pkh) or 1 (p2sh)"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function AddFederatedServerBitcoinAnchorKey.__post_init__ refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator

Comment on lines -91 to +109
for i in range(input_count):
for _ in range(input_count):
value, data = varint.decode(data)
fct_address, data = data[:32], data[32:]
inputs.append({"value": value, "fct_address": fct_address})

outputs = []
for i in range(output_count):
for _ in range(output_count):
value, data = varint.decode(data)
fct_address, data = data[:32], data[32:]
outputs.append({"value": value, "fct_address": fct_address})

ec_purchases = []
for i in range(ec_purchase_count):
for _ in range(ec_purchase_count):
value, data = varint.decode(data)
ec_public_key, data = data[:32], data[32:]
ec_purchases.append({"value": value, "ec_public_key": ec_public_key})

rcds = primitives.FullSignatureList()
for i in range(input_count):
for _ in range(input_count):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function FactoidTransaction.unmarshal_with_remainder refactored with the following changes:

  • Replace unused for index with underscore

v = 0
for b in h:
v += b
v = sum(h)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Blockchain.vm_for_hash refactored with the following changes:

  • Convert for loop into call to sum()
  • Simplify generator expression

data = raw
messages = []
for i in range(message_count):
for _ in range(message_count):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function AdminBlockBody.unmarshal_with_remainder refactored with the following changes:

  • Replace unused for index with underscore
  • Use previously assigned local variable

Comment on lines -243 to +242
for i in range(header.message_count):
for _ in range(header.message_count):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function AdminBlock.unmarshal_with_remainder refactored with the following changes:

  • Replace unused for index with underscore
  • Use previously assigned local variable

length, data = struct.unpack(">I", raw[:4])[0], raw[4:]
signatures = []
for i in range(length):
for _ in range(length):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function FullSignatureList.unmarshal refactored with the following changes:

  • Replace unused for index with underscore


def build_merkle_tree(hashes: list):
if len(hashes) == 0 or len(hashes) == 1:
if len(hashes) in [0, 1]:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function build_merkle_tree refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator

buf.append(b)

h = h << 7
h <<= 7

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function encode refactored with the following changes:

  • Replace assignment with augmented assignment

while True:
i, data = ord(data[:1]), data[1:]
result = result << 7
result <<= 7

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function decode refactored with the following changes:

  • Replace assignment with augmented assignment

Comment thread p2p/parcel.py
if not ParcelType.is_valid(parcel_type):
raise ValueError("Invalid parcel_type provided")
elif not type(address) is not str and address is not None:
elif type(address) is str and address is not None:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Parcel.__init__ refactored with the following changes:

  • Simplify logical expression

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant