-
Notifications
You must be signed in to change notification settings - Fork 2
Sourcery Starbot ⭐ refactored sambarnes/factom-core #19
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,25 +88,25 @@ def unmarshal_with_remainder(cls, raw: bytes): | |
| ec_purchase_count, data = ord(data[:1]), data[1:] | ||
|
|
||
| inputs = [] | ||
| 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): | ||
|
Comment on lines
-91
to
+109
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function FactoidTransaction.unmarshal_with_remainder refactored with the following changes:
|
||
| data = data[1:] # skip 1 byte version number, always 0x01 for now | ||
| signature, data = primitives.FullSignature.unmarshal(data[:96]), data[96:] | ||
| rcds.append(signature) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,9 +64,7 @@ def vm_for_hash(self, h: bytes) -> int: | |
| """ | ||
| if len(self.vms) == 0: | ||
| return 0 | ||
| v = 0 | ||
| for b in h: | ||
| v += b | ||
| v = sum(h) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function Blockchain.vm_for_hash refactored with the following changes:
|
||
| return v % len(self.vms) | ||
|
|
||
| def seal_minute(self) -> None: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,7 +93,7 @@ def unmarshal(cls, raw: bytes, message_count: int): | |
| def unmarshal_with_remainder(cls, raw: bytes, message_count: int): | ||
| data = raw | ||
| messages = [] | ||
| for i in range(message_count): | ||
| for _ in range(message_count): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function AdminBlockBody.unmarshal_with_remainder refactored with the following changes:
|
||
| admin_id, data = data[0], data[1:] | ||
| msg = None | ||
| if admin_id == MinuteNumber.ADMIN_ID: # Deprecated in M2 | ||
|
|
@@ -167,8 +167,7 @@ def unmarshal_with_remainder(cls, raw: bytes, message_count: int): | |
|
|
||
| elif admin_id <= 0x0E: | ||
| msg = admin_id | ||
| print(f"Unsupported admin message type {admin_id} found") | ||
|
|
||
| print(f'Unsupported admin message type {msg} found') | ||
| if msg is not None: | ||
| messages.append(msg) | ||
|
|
||
|
|
@@ -240,7 +239,7 @@ def unmarshal_with_remainder(cls, raw: bytes): | |
| header, data = AdminBlockHeader.unmarshal_with_remainder(raw) | ||
|
|
||
| messages = [] | ||
| for i in range(header.message_count): | ||
| for _ in range(header.message_count): | ||
|
Comment on lines
-243
to
+242
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function AdminBlock.unmarshal_with_remainder refactored with the following changes:
|
||
| admin_id, data = data[0], data[1:] | ||
| msg = None | ||
| if admin_id == MinuteNumber.ADMIN_ID: # Deprecated in M2 | ||
|
|
@@ -314,7 +313,11 @@ def unmarshal_with_remainder(cls, raw: bytes): | |
|
|
||
| elif admin_id <= 0x0E: | ||
| msg = admin_id | ||
| print("Unsupported admin message type {} found at Admin Block {}".format(admin_id, header.height)) | ||
| print( | ||
| "Unsupported admin message type {} found at Admin Block {}".format( | ||
| msg, header.height | ||
| ) | ||
| ) | ||
|
|
||
| if msg is not None: | ||
| messages.append(msg) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,7 +125,7 @@ def unmarshal_with_remainder(cls, raw: bytes, block_count: int): | |
| assert factoid_block_chain_id == factom_core.blocks.FactoidBlockHeader.CHAIN_ID | ||
| factoid_block_keymr, data = data[:32], data[32:] | ||
| entry_blocks = [] | ||
| for i in range(block_count - 3): | ||
| for _ in range(block_count - 3): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function DirectoryBlockBody.unmarshal_with_remainder refactored with the following changes:
|
||
| entry_block_chain_id, data = data[:32], data[32:] | ||
| entry_block_keymr, data = data[:32], data[32:] | ||
| entry_blocks.append({"chain_id": entry_block_chain_id, "keymr": entry_block_keymr}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,7 +101,7 @@ def unmarshal_with_remainder(cls, raw: bytes, entry_count: int): | |
| # Entry hashes are listed in order, with a minute marker following what minute those entries were in | ||
| entry_hashes = {} | ||
| current_minute_entries = [] | ||
| for i in range(entry_count): | ||
| for _ in range(entry_count): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function EntryBlockBody.unmarshal_with_remainder refactored with the following changes:
|
||
| entry_hash, data = data[:32], data[32:] | ||
| if entry_hash[:-1] == bytes(31) and entry_hash[-1] <= 10: | ||
| entry_hashes[entry_hash[-1]] = current_minute_entries | ||
|
|
@@ -118,9 +118,7 @@ def construct_header( | |
| Creates an returns an EntryBlockHeader for this body object, given the specified contextual | ||
| parameters. | ||
| """ | ||
| entry_count = 0 | ||
| for hashes in self.entry_hashes.values(): | ||
| entry_count += len(hashes) | ||
| entry_count = sum(len(hashes) for hashes in self.entry_hashes.values()) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function EntryBlockBody.construct_header refactored with the following changes:
|
||
| return EntryBlockHeader( | ||
| chain_id=chain_id, | ||
| body_mr=self.merkle_root, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,7 +123,7 @@ def unmarshal_with_remainder(cls, raw: bytes, object_count: int): | |
| data = raw | ||
| objects = {} # map of minute --> objects array | ||
| current_minute_objects = [] | ||
| for i in range(object_count): | ||
| for _ in range(object_count): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function EntryCreditBlockBody.unmarshal_with_remainder refactored with the following changes:
|
||
| ecid, data = data[0], data[1:] | ||
| if ecid == 0x00: | ||
| server_index, data = data[0], data[1:] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,8 +121,7 @@ def get_admin_block(self, **kwargs) -> Union[blocks.AdminBlock, None]: | |
| raw = sub_db.get(lookup_hash) | ||
| if raw is None: | ||
| return None | ||
| block = blocks.AdminBlock.unmarshal(raw) | ||
| return block | ||
| return blocks.AdminBlock.unmarshal(raw) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function FactomdLevelDB.get_admin_block refactored with the following changes:
|
||
|
|
||
| def get_admin_block_head(self) -> Union[blocks.AdminBlock, None]: | ||
| prev_hash = self.get_chain_head(blocks.AdminBlockHeader.CHAIN_ID) | ||
|
|
@@ -158,8 +157,7 @@ def get_factoid_block(self, **kwargs) -> Union[blocks.FactoidBlock, None]: | |
| raw = sub_db.get(keymr) | ||
| if raw is None: | ||
| return None | ||
| block = blocks.FactoidBlock.unmarshal(raw) | ||
| return block | ||
| return blocks.FactoidBlock.unmarshal(raw) | ||
|
Comment on lines
-161
to
+160
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function FactomdLevelDB.get_factoid_block refactored with the following changes:
|
||
|
|
||
| def get_factoid_block_head(self) -> Union[blocks.FactoidBlock, None]: | ||
| prev_keymr = self.get_chain_head(blocks.FactoidBlockHeader.CHAIN_ID) | ||
|
|
@@ -195,8 +193,7 @@ def get_entry_credit_block(self, **kwargs) -> Union[blocks.EntryCreditBlock, Non | |
| raw = sub_db.get(header_hash) | ||
| if raw is None: | ||
| return None | ||
| block = blocks.EntryCreditBlock.unmarshal(raw) | ||
| return block | ||
| return blocks.EntryCreditBlock.unmarshal(raw) | ||
|
Comment on lines
-198
to
+196
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function FactomdLevelDB.get_entry_credit_block refactored with the following changes:
|
||
|
|
||
| def get_entry_credit_block_head(self) -> Union[blocks.EntryCreditBlock, None]: | ||
| prev_hash = self.get_chain_head(blocks.EntryCreditBlockHeader.CHAIN_ID) | ||
|
|
@@ -223,8 +220,7 @@ def get_entry_block(self, keymr: bytes) -> Union[blocks.EntryBlock, None]: | |
| raw = sub_db.get(keymr) | ||
| if raw is None: | ||
| return None | ||
| block = blocks.EntryBlock.unmarshal(raw) | ||
| return block | ||
| return blocks.EntryBlock.unmarshal(raw) | ||
|
Comment on lines
-226
to
+223
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function FactomdLevelDB.get_entry_block refactored with the following changes:
|
||
|
|
||
| def get_entry_block_head(self, chain_id: bytes) -> Union[blocks.EntryBlock, None]: | ||
| prev_keymr = self.get_chain_head(chain_id) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,13 +94,13 @@ def unmarshal(cls, raw: bytes): | |
|
|
||
| entry_block_count, data = struct.unpack(">I", data[:4])[0], data[4:] | ||
| entry_blocks = [] | ||
| for i in range(entry_block_count): | ||
| for _ in range(entry_block_count): | ||
| entry_block, data = EntryBlock.unmarshal_with_remainder(data) | ||
| entry_blocks.append(entry_block) | ||
|
|
||
| entry_count, data = struct.unpack(">I", data[:4])[0], data[4:] | ||
| entries = [] | ||
| for i in range(entry_count): | ||
| for _ in range(entry_count): | ||
|
Comment on lines
-97
to
+103
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function DirectoryBlockState.unmarshal refactored with the following changes:
|
||
| entry_size, data = struct.unpack(">I", data[:4])[0], data[4:] | ||
| entry, data = Entry.unmarshal(data[:entry_size]), data[entry_size:] | ||
| entries.append(entry) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ def marshal(self) -> bytes: | |
| def unmarshal(cls, raw: bytes): | ||
| length, data = struct.unpack(">I", raw[:4])[0], raw[4:] | ||
| signatures = [] | ||
| for i in range(length): | ||
| for _ in range(length): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function FullSignatureList.unmarshal refactored with the following changes:
|
||
| signature, data = FullSignature.unmarshal(data[:96]), data[96:] | ||
| signatures.append(signature) | ||
| assert len(data) == 0, "Extra bytes remaining!" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ def get_merkle_root(hashes: list) -> bytes: | |
|
|
||
|
|
||
| def build_merkle_tree(hashes: list): | ||
| if len(hashes) == 0 or len(hashes) == 1: | ||
| if len(hashes) in [0, 1]: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function build_merkle_tree refactored with the following changes:
|
||
| return hashes | ||
|
|
||
| next_level = [] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ def encode(number: int): | |
| b = b if b < 256 else struct.pack(">Q", b)[-1] | ||
| buf.append(b) | ||
|
|
||
| h = h << 7 | ||
| h <<= 7 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function encode refactored with the following changes:
|
||
|
|
||
| return bytes(buf) | ||
|
|
||
|
|
@@ -34,7 +34,7 @@ def decode(raw: bytes): | |
| data = raw | ||
| while True: | ||
| i, data = ord(data[:1]), data[1:] | ||
| result = result << 7 | ||
| result <<= 7 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function decode refactored with the following changes:
|
||
| result += i & 0x7F | ||
| if i < 0x80: | ||
| break | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ def __init__(self, parcel_type: ParcelType, address: str, payload: bytes): | |
| """ | ||
| 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: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function Parcel.__init__ refactored with the following changes:
|
||
| raise ValueError("address must be a string or None") | ||
| elif type(payload) is not bytes or len(payload) == 0: | ||
| raise ValueError("payload must be a bytes object of non-zero length") | ||
|
|
||
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.
Function AddFederatedServerBitcoinAnchorKey.__post_init__ refactored with the following changes:
inoperator