Skip to content

refactor: make transaction methods protected #166

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crypto/transactions/types/abstract_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_public_key(self, compact_signature, hash_):
return public_key

def recover_sender(self):
signature_with_recid = self.get_signature()
signature_with_recid = self._get_signature()
if not signature_with_recid:
return False

Expand All @@ -51,7 +51,7 @@ def recover_sender(self):
self.data['senderAddress'] = Address.from_public_key(self.data['senderPublicKey'])

def verify(self) -> bool:
signature_with_recid = self.get_signature()
signature_with_recid = self._get_signature()
if not signature_with_recid:
return False

Expand Down Expand Up @@ -79,7 +79,7 @@ def to_json(self) -> str:
def hash(self, skip_signature: bool) -> str:
return TransactionUtils.to_hash(self.data, skip_signature=skip_signature)

def get_signature(self):
def _get_signature(self):
recover_id = int(self.data.get('v', 0)) - Constants.ETHEREUM_RECOVERY_ID_OFFSET.value
r = self.data.get('r')
s = self.data.get('s')
Expand All @@ -90,7 +90,7 @@ def get_signature(self):
return None

@staticmethod
def decode_payload(data: dict, abi_type: ContractAbiType = ContractAbiType.CONSENSUS) -> Optional[dict]:
def _decode_payload(data: dict, abi_type: ContractAbiType = ContractAbiType.CONSENSUS) -> Optional[dict]:
from crypto.transactions.deserializer import Deserializer

return Deserializer.decode_payload(data, abi_type)
2 changes: 1 addition & 1 deletion crypto/transactions/types/multipayment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Multipayment(AbstractTransaction):
def __init__(self, data: dict):
payload = self.decode_payload(data, ContractAbiType.MULTIPAYMENT)
payload = self._decode_payload(data, ContractAbiType.MULTIPAYMENT)
if payload:
data['pay'] = payload.get('args', [])

Expand Down
2 changes: 1 addition & 1 deletion crypto/transactions/types/username_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class UsernameRegistration(AbstractTransaction):
def __init__(self, data: dict):
payload = self.decode_payload(data, ContractAbiType.USERNAMES)
payload = self._decode_payload(data, ContractAbiType.USERNAMES)
if payload:
data['username'] = payload.get('args', [None])[0] if payload.get('args') else None

Expand Down
3 changes: 2 additions & 1 deletion crypto/transactions/types/validator_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

class ValidatorRegistration(AbstractTransaction):
def __init__(self, data: dict):
payload = self.decode_payload(data)
payload = self._decode_payload(data)
if payload:
data['validatorPublicKey'] = TransactionUtils.parse_hex_from_str(payload.get('args', [None])[0]) if payload.get('args') else None

super().__init__(data)

def get_payload(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion crypto/transactions/types/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Vote(AbstractTransaction):
def __init__(self, data: dict):
payload = self.decode_payload(data)
payload = self._decode_payload(data)
if payload:
data['vote'] = payload.get('args', [None])[0] if payload.get('args') else None

Expand Down