Skip to content

Commit

Permalink
[ECHOT-316] Optimize validators
Browse files Browse the repository at this point in the history
[ECHOT-316] Optimize validators
  • Loading branch information
Eugene Vasilev authored Mar 13, 2020
1 parent dd83dd2 commit 74163cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
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

0 comments on commit 74163cd

Please sign in to comment.