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

[ECHOT-316] Optimize validators #13

Merged
merged 9 commits into from
Mar 13, 2020
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
16 changes: 12 additions & 4 deletions echopy/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from datetime import timezone, datetime
from calendar import timegm
import time
import string

from .echobase.crypto import Crypto

Expand Down Expand Up @@ -65,6 +64,14 @@ def __init__(self, api):
self._chain_id = None
self._crypto = Crypto

@staticmethod
def is_hex(s):
try:
int(s, 16)
return True
except ValueError:
return False

@staticmethod
def bytes_to_int(_bytes):
result = 0
Expand All @@ -90,7 +97,7 @@ def ref_block_prefix(self):

@ref_block_prefix.setter
def ref_block_prefix(self, value):
if isinstance(value, str) and all(symbol in string.hexdigits for symbol in set(value)):
if isinstance(value, str) and self.is_hex(value):
self._ref_block_prefix = self.bytes_to_int(bytes.fromhex(value)[:4])
return
if isinstance(value, int) and value > 0 and value < 2**32:
Expand All @@ -104,8 +111,7 @@ def chain_id(self):

@chain_id.setter
def chain_id(self, value):
if isinstance(value, str) and all(symbol in string.hexdigits for symbol in set(value))\
and len(value) == 64:
if isinstance(value, str) and self.is_hex(value) and len(value) == 64:
self._chain_id = value
return
raise Exception('invalid chain_id format or length')
Expand Down Expand Up @@ -321,6 +327,8 @@ def iso_to_seconds(iso):
now_seconds = iso_to_seconds(now_iso)
self.expiration = seconds_to_iso(now_seconds + 300)

self.check_finalized()

_transaction = TransactionType(
ref_block_num=self.ref_block_num,
ref_block_prefix=self.ref_block_prefix,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools import setup, find_packages

VERSION = "0.1.59"
VERSION = "0.1.60"
packages = find_packages()
packages.remove('test')

Expand Down