Skip to content

Commit 111621e

Browse files
committed
refactor: remove static and class methods
1 parent ea551fb commit 111621e

File tree

8 files changed

+19
-24
lines changed

8 files changed

+19
-24
lines changed

hathor/stratum/stratum.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,10 @@ def handle_submit(self, params: dict, msgid: Optional[str]) -> None:
526526

527527
self.log.debug('share received', block=tx, block_base=block_base.hex(), block_base_hash=block_base_hash.hex())
528528

529+
verifier = VertexVerifier(settings=self._settings)
530+
529531
try:
530-
VertexVerifier.verify_pow(tx, override_weight=job.weight)
532+
verifier.verify_pow(tx, override_weight=job.weight)
531533
except PowError:
532534
self.log.error('bad share, discard', job_weight=job.weight, tx=tx)
533535
return self.send_error(INVALID_SOLUTION, msgid, {
@@ -543,7 +545,7 @@ def handle_submit(self, params: dict, msgid: Optional[str]) -> None:
543545
self.manager.reactor.callLater(0, self.job_request)
544546

545547
try:
546-
VertexVerifier.verify_pow(tx)
548+
verifier.verify_pow(tx)
547549
except PowError:
548550
# Transaction pow was not enough, but the share was succesfully submited
549551
self.log.info('high hash, keep mining', tx=tx)

hathor/verification/block_verifier.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,19 @@ def verify_without_storage(self, block: Block) -> None:
5454
"""
5555
block.verify_without_storage()
5656

57-
@staticmethod
58-
def verify_height(block: Block) -> None:
57+
def verify_height(self, block: Block) -> None:
5958
"""Validate that the block height is enough to confirm all transactions being confirmed."""
6059
block.verify_height()
6160

6261
def verify_weight(self, block: Block) -> None:
6362
"""Validate minimum block difficulty."""
6463
block.verify_weight()
6564

66-
@staticmethod
67-
def verify_reward(block: Block) -> None:
65+
def verify_reward(self, block: Block) -> None:
6866
"""Validate reward amount."""
6967
block.verify_reward()
7068

71-
@staticmethod
72-
def verify_no_inputs(block: Block) -> None:
69+
def verify_no_inputs(self, block: Block) -> None:
7370
block.verify_no_inputs()
7471

7572
def verify_outputs(self, block: BaseTransaction) -> None:

hathor/verification/merge_mined_block_verifier.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
class MergeMinedBlockVerifier(BlockVerifier):
2020
__slots__ = ()
2121

22-
@staticmethod
23-
def verify_aux_pow(block: MergeMinedBlock) -> None:
22+
def verify_aux_pow(self, block: MergeMinedBlock) -> None:
2423
""" Verify auxiliary proof-of-work (for merged mining).
2524
"""
2625
block.verify_aux_pow()

hathor/verification/transaction_verifier.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ def verify_unsigned_skip_pow(self, tx: Transaction) -> None:
6161
""" Same as .verify but skipping pow and signature verification."""
6262
tx.verify_unsigned_skip_pow()
6363

64-
@staticmethod
65-
def verify_parents_basic(tx: Transaction) -> None:
64+
def verify_parents_basic(self, tx: Transaction) -> None:
6665
"""Verify number and non-duplicity of parents."""
6766
tx.verify_parents_basic()
6867

@@ -84,8 +83,7 @@ def verify_inputs(self, tx: Transaction, *, skip_script: bool = False) -> None:
8483
"""Verify inputs signatures and ownership and all inputs actually exist"""
8584
tx.verify_inputs(skip_script=skip_script)
8685

87-
@staticmethod
88-
def verify_script(*, tx: Transaction, input_tx: TxInput, spent_tx: BaseTransaction) -> None:
86+
def verify_script(self, *, tx: Transaction, input_tx: TxInput, spent_tx: BaseTransaction) -> None:
8987
"""
9088
:type tx: Transaction
9189
:type input_tx: TxInput
@@ -104,8 +102,7 @@ def verify_sum(self, tx: Transaction) -> None:
104102
"""
105103
tx.verify_sum()
106104

107-
@staticmethod
108-
def verify_reward_locked(tx: Transaction) -> None:
105+
def verify_reward_locked(self, tx: Transaction) -> None:
109106
"""Will raise `RewardLocked` if any reward is spent before the best block height is enough, considering only
110107
the block rewards spent by this tx itself, and not the inherited `min_height`."""
111108
tx.verify_reward_locked()
@@ -121,8 +118,7 @@ def verify_outputs(self, tx: BaseTransaction) -> None:
121118
"""
122119
tx.verify_outputs()
123120

124-
@staticmethod
125-
def update_token_info_from_outputs(tx: Transaction, *, token_dict: dict[TokenUid, TokenInfo]) -> None:
121+
def update_token_info_from_outputs(self, tx: Transaction, *, token_dict: dict[TokenUid, TokenInfo]) -> None:
126122
"""Iterate over the outputs and add values to token info dict. Updates the dict in-place.
127123
128124
Also, checks if no token has authorities on the outputs not present on the inputs

hathor/verification/vertex_verifier.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def verify_parents(self, vertex: BaseTransaction) -> None:
3737
"""
3838
vertex.verify_parents()
3939

40-
@classmethod
41-
def verify_pow(cls, vertex: BaseTransaction, *, override_weight: Optional[float] = None) -> None:
40+
def verify_pow(self, vertex: BaseTransaction, *, override_weight: Optional[float] = None) -> None:
4241
"""Verify proof-of-work
4342
4443
:raises PowError: when the hash is equal or greater than the target

tests/simulation/test_simulator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_verify_pow(self):
1313
# just get one of the genesis, we don't really need to create any transaction
1414
tx = next(iter(manager1.tx_storage.get_all_genesis()))
1515
# optional argument must be valid, it just has to not raise any exception, there's no assert for that
16-
VertexVerifier.verify_pow(tx, override_weight=0.)
16+
VertexVerifier(settings=self._settings).verify_pow(tx, override_weight=0.)
1717

1818
def test_one_node(self):
1919
manager1 = self.create_peer()

tests/tx/test_genesis.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ def setUp(self):
3333
self.storage = TransactionMemoryStorage()
3434

3535
def test_pow(self):
36+
verifier = VertexVerifier(settings=self._settings)
3637
genesis = self.storage.get_all_genesis()
3738
for g in genesis:
3839
self.assertEqual(g.calculate_hash(), g.hash)
39-
self.assertIsNone(VertexVerifier.verify_pow(g))
40+
self.assertIsNone(verifier.verify_pow(g))
4041

4142
def test_verify(self):
4243
genesis = self.storage.get_all_genesis()

tests/wallet/test_wallet_hd.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def test_transaction_and_balance(self):
4343
out = WalletOutputInfo(decode_address(new_address2), self.TOKENS, timelock=None)
4444
tx1 = self.wallet.prepare_transaction_compute_inputs(Transaction, [out], self.tx_storage)
4545
tx1.update_hash()
46-
TransactionVerifier.verify_script(tx=tx1, input_tx=tx1.inputs[0], spent_tx=block)
46+
verifier = TransactionVerifier(settings=self._settings)
47+
verifier.verify_script(tx=tx1, input_tx=tx1.inputs[0], spent_tx=block)
4748
tx1.storage = self.tx_storage
4849
tx1.get_metadata().validation = ValidationState.FULL
4950
self.wallet.on_new_tx(tx1)
@@ -63,7 +64,7 @@ def test_transaction_and_balance(self):
6364
tx2.storage = self.tx_storage
6465
tx2.update_hash()
6566
tx2.storage = self.tx_storage
66-
TransactionVerifier.verify_script(tx=tx2, input_tx=tx2.inputs[0], spent_tx=tx1)
67+
verifier.verify_script(tx=tx2, input_tx=tx2.inputs[0], spent_tx=tx1)
6768
tx2.get_metadata().validation = ValidationState.FULL
6869
self.tx_storage.save_transaction(tx2)
6970
self.wallet.on_new_tx(tx2)

0 commit comments

Comments
 (0)