Skip to content
Snippets Groups Projects
Commit 391665d0 authored by Patricio Kumagae's avatar Patricio Kumagae
Browse files

Merge branch 'desarrollo'

parents 83d37373 fab6bf3c
No related branches found
No related tags found
No related merge requests found
...@@ -10,8 +10,8 @@ from bitcoin.core.serialize import uint256_from_str ...@@ -10,8 +10,8 @@ from bitcoin.core.serialize import uint256_from_str
class TimestampManager(models.Manager): class TimestampManager(models.Manager):
@classmethod @staticmethod
def get_provider(cls): def get_provider():
try: try:
...@@ -25,42 +25,42 @@ class TimestampManager(models.Manager): ...@@ -25,42 +25,42 @@ class TimestampManager(models.Manager):
except UnhandledRequest: except UnhandledRequest:
raise raise
@classmethod @staticmethod
def get_current_contract(cls): def get_current_contract():
return TimestampManager.get_contract(CURRENT_CONTRACT_VERSION) return TimestampManager.get_contract(CURRENT_CONTRACT_VERSION)
@classmethod @staticmethod
def get_contract(cls, contract_version): def get_contract(contract_version):
web3 = TimestampManager.get_provider() web3 = TimestampManager.get_provider()
return web3.eth.contract(abi=CONTRACTS[contract_version]['abi'], address=Web3.toChecksumAddress(CONTRACTS[contract_version]['address'])) return web3.eth.contract(abi=CONTRACTS[contract_version]['abi'], address=Web3.toChecksumAddress(CONTRACTS[contract_version]['address']))
@classmethod @staticmethod
def get_block(cls, block_number): def get_block(block_number):
web3 = TimestampManager.get_provider() web3 = TimestampManager.get_provider()
return web3.eth.getBlock(block_number) return web3.eth.getBlock(block_number)
@classmethod @staticmethod
def get_transaction(cls, tx_hash): def get_transaction(tx_hash):
web3 = TimestampManager.get_provider() web3 = TimestampManager.get_provider()
return web3.eth.getTransaction(tx_hash) return web3.eth.getTransaction(tx_hash)
@classmethod @staticmethod
def stamp(cls, proof_hash, file_hash): def stamp(proof_hash, file_hash):
contract = TimestampManager.get_current_contract() contract = TimestampManager.get_current_contract()
return contract.functions.stamp(uint256_from_str(proof_hash.encode('utf-8')), uint256_from_str(file_hash.encode('utf-8'))).transact({'from': Web3.toChecksumAddress(ACCOUNT_ADDRESS)}) return contract.functions.stamp(uint256_from_str(proof_hash.encode('utf-8')), uint256_from_str(file_hash.encode('utf-8'))).transact({'from': Web3.toChecksumAddress(ACCOUNT_ADDRESS)})
@classmethod @staticmethod
def verify(cls, contract_version, proof_hash, file_hash): def verify(contract_version, proof_hash, file_hash):
contract = TimestampManager.get_contract(contract_version) contract = TimestampManager.get_contract(contract_version)
return contract.functions.verify(uint256_from_str(proof_hash.encode('utf-8')),uint256_from_str(file_hash.encode('utf-8'))).call() return contract.functions.verify(uint256_from_str(proof_hash.encode('utf-8')),uint256_from_str(file_hash.encode('utf-8'))).call()
@classmethod @staticmethod
def get_block_number(cls, contract_version, proof_hash): def get_block_number(contract_version, proof_hash):
contract = TimestampManager.get_contract(contract_version) contract = TimestampManager.get_contract(contract_version)
return contract.functions.getBlockNumber(uint256_from_str(proof_hash.encode('utf-8'))).call() return contract.functions.getBlockNumber(uint256_from_str(proof_hash.encode('utf-8'))).call()
...@@ -5,14 +5,14 @@ from TsaApi.settings import ACCOUNT_ADDRESS, CURRENT_CONTRACT_VERSION ...@@ -5,14 +5,14 @@ from TsaApi.settings import ACCOUNT_ADDRESS, CURRENT_CONTRACT_VERSION
class Utils(): class Utils():
@classmethod @staticmethod
def sha256_encode(cls, string): def sha256_encode(string):
return hashlib.sha256(string.encode('utf-8')).hexdigest() return hashlib.sha256(string.encode('utf-8')).hexdigest()
@classmethod @staticmethod
def datetime_from_timestamp(cls, timestamp): def datetime_from_timestamp(timestamp):
return datetime.datetime.fromtimestamp(timestamp).strftime('%d/%m/%Y %H:%M:%S') return datetime.datetime.fromtimestamp(timestamp).strftime('%d/%m/%Y %H:%M:%S')
@classmethod @staticmethod
def get_proof_hash(cls, file_hash): def get_proof_hash(file_hash):
return Utils.sha256_encode(str(file_hash + Utils.sha256_encode(str(int(time.time()))) + Utils.sha256_encode(ACCOUNT_ADDRESS))) + CURRENT_CONTRACT_VERSION return Utils.sha256_encode(str(file_hash + Utils.sha256_encode(str(int(time.time()))) + Utils.sha256_encode(ACCOUNT_ADDRESS))) + CURRENT_CONTRACT_VERSION
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment