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

Se elimina ACCOUNT_PASSWORD del settings por no ser más necesario

parent 68a0720d
No related branches found
No related tags found
No related merge requests found
......@@ -6,8 +6,8 @@ HOST_ADDRESS = 'http://10.23.10.71:8501'
#Contracts info
CONTRACTS = {
'01':{
'address': '0x5B063742464f4c81EAE6B597DceaEe619F46d5aE',
'abi': [{"constant":False,"inputs":[{"name":"hash","type":"uint256"}],"name":"put","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[{"name":"hash","type":"uint256"}],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":False,"stateMutability":"view","type":"function"}] ,
'address': '0x98e3b125f6FeA352c9f5F1594dBB241aC2E483DE',
'abi': [{"constant":False,"inputs":[{"name":"ots","type":"uint256"},{"name":"file_hash","type":"uint256"}],"name":"stamp","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[{"name":"ots","type":"uint256"},{"name":"file_hash","type":"uint256"}],"name":"verify","outputs":[{"name":"","type":"bool"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[{"name":"ots","type":"uint256"}],"name":"getBlockNumber","outputs":[{"name":"","type":"uint256"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[{"name":"ots","type":"uint256"}],"name":"getHash","outputs":[{"name":"","type":"uint256"}],"payable":False,"stateMutability":"view","type":"function"}] ,
},
}
......
......@@ -6,8 +6,8 @@ HOST_ADDRESS = 'http://10.23.10.71:8501'
#Contracts info
CONTRACTS = {
'01':{
'address': '0x5B063742464f4c81EAE6B597DceaEe619F46d5aE',
'abi': [{"constant":False,"inputs":[{"name":"hash","type":"uint256"}],"name":"put","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[{"name":"hash","type":"uint256"}],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":False,"stateMutability":"view","type":"function"}] ,
'address': '0x98e3b125f6FeA352c9f5F1594dBB241aC2E483DE',
'abi': [{"constant":False,"inputs":[{"name":"ots","type":"uint256"},{"name":"file_hash","type":"uint256"}],"name":"stamp","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[{"name":"ots","type":"uint256"},{"name":"file_hash","type":"uint256"}],"name":"verify","outputs":[{"name":"","type":"bool"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[{"name":"ots","type":"uint256"}],"name":"getBlockNumber","outputs":[{"name":"","type":"uint256"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[{"name":"ots","type":"uint256"}],"name":"getHash","outputs":[{"name":"","type":"uint256"}],"payable":False,"stateMutability":"view","type":"function"}] ,
},
}
......
......@@ -6,8 +6,8 @@ HOST_ADDRESS = 'http://10.23.10.71:8501'
#Contracts info
CONTRACTS = {
'01':{
'address': '0x5B063742464f4c81EAE6B597DceaEe619F46d5aE',
'abi': [{"constant":False,"inputs":[{"name":"hash","type":"uint256"}],"name":"put","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[{"name":"hash","type":"uint256"}],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":False,"stateMutability":"view","type":"function"}] ,
'address': '0x98e3b125f6FeA352c9f5F1594dBB241aC2E483DE',
'abi': [{"constant":False,"inputs":[{"name":"ots","type":"uint256"},{"name":"file_hash","type":"uint256"}],"name":"stamp","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[{"name":"ots","type":"uint256"},{"name":"file_hash","type":"uint256"}],"name":"verify","outputs":[{"name":"","type":"bool"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[{"name":"ots","type":"uint256"}],"name":"getBlockNumber","outputs":[{"name":"","type":"uint256"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[{"name":"ots","type":"uint256"}],"name":"getHash","outputs":[{"name":"","type":"uint256"}],"payable":False,"stateMutability":"view","type":"function"}] ,
},
}
......
......@@ -20,7 +20,8 @@ class Stamp(APIView):
[POST]
Permite realizar un stamp de un archivo
Parámetros recibidos JSON:
Parámetros recibidos:
[Content-Type:application/json]
- file_hash: El hash del archivo encodeado en sha256
......@@ -44,12 +45,10 @@ class Stamp(APIView):
timestamp_hash = hashlib.sha256(str(int(time.time())).encode('utf-8')).hexdigest()
proof_hash = hashlib.sha256(str(file_hash + timestamp_hash + account_hash).encode('utf-8')).hexdigest() + CURRENT_CONTRACT_VERSION
blockchain_hash = hashlib.sha256(str(file_hash + proof_hash).encode('utf-8')).hexdigest()
web3 = TimestampManager.get_provider()
contract = web3.eth.contract(abi=CONTRACTS[CURRENT_CONTRACT_VERSION]['abi'], address=Web3.toChecksumAddress(CONTRACTS[CURRENT_CONTRACT_VERSION]['address']))
tx_hash = contract.functions.put(uint256_from_str(blockchain_hash.encode('utf-8'))).transact({'from': Web3.toChecksumAddress(ACCOUNT_ADDRESS)})
tx_hash = 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)})
proof = proof_hash + '-' + tx_hash.hex()
......@@ -69,7 +68,8 @@ class Verify(APIView):
[POST]
Permite verificar que un archivo fue subido a la Blockchain
Parámetros recibidos JSON:
Parámetros recibidos:
[Content-Type:application/json]
- file_hash: El hash del archivo original encodeado en sha256
- proof: Proof recibido como prueba al momento de realizar el stamp
......@@ -105,11 +105,16 @@ class Verify(APIView):
contract = web3.eth.contract(abi=contract_info['abi'], address=Web3.toChecksumAddress(contract_info['address']))
hash = hashlib.sha256(str(file_hash+proof_hash).encode('utf-8')).hexdigest()
verified = contract.functions.verify(uint256_from_str(proof_hash.encode('utf-8')), uint256_from_str(file_hash.encode('utf-8'))).call()
if verified:
block_number = contract.functions.getBlockNumber(uint256_from_str(proof_hash.encode('utf-8'))).call()
block = web3.eth.getBlock(block_number)
block_number = contract.functions.get(uint256_from_str(hash.encode('utf-8'))).call()
date = datetime.datetime.fromtimestamp(block.timestamp).strftime('%d/%m/%Y %H:%M:%S')
if block_number == 0:
return Response({'status': _('success'),_('messages'): _('file_uploaded') % (file_hash, str(block.number), str(date))},status=status.HTTP_200_OK)
else:
try:
transaction = web3.eth.getTransaction(tx_hash)
if transaction and not transaction.blockNumber:
......@@ -118,15 +123,9 @@ class Verify(APIView):
pass
if pending:
return Response({'status': _('success'), _('messages'): _('transaction_pending')},status=status.HTTP_200_OK)
return Response({'status': _('pending'), _('messages'): _('transaction_pending')},status=status.HTTP_200_OK)
else:
return Response({'status': _('failure'), _('messages'): _('file_not_found')}, status=status.HTTP_404_NOT_FOUND)
block = web3.eth.getBlock(block_number)
date = datetime.datetime.fromtimestamp(block.timestamp).strftime('%d/%m/%Y %H:%M:%S')
return Response({'status': _('success'), _('messages'): _('file_uploaded') % (file_hash, str(block.number), str(date)) }, status=status.HTTP_200_OK)
return Response({'status': _('failure'), _('messages'): _('file_not_found')},status=status.HTTP_404_NOT_FOUND)
except ValidationError as e:
return Response({'status': _('failure'), _('messages'): _('parameter_missing') % e.message}, status=status.HTTP_400_BAD_REQUEST)
......
No preview for this file type
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-08-13 11:02-0300\n"
"POT-Creation-Date: 2018-08-14 16:05-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -17,48 +17,52 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: TsaApi/settings.py:111
#: TsaApi/settings.py:114
msgid "Spanish"
msgstr ""
#: app/views.py:60 app/views.py:126 app/views.py:134
#: app/views.py:57 app/views.py:118
msgid "success"
msgstr ""
#: app/views.py:60
#: app/views.py:57
msgid "proof"
msgstr ""
#: app/views.py:63 app/views.py:65 app/views.py:128 app/views.py:137
#: app/views.py:139 app/views.py:141
#: app/views.py:60 app/views.py:63 app/views.py:130 app/views.py:133
#: app/views.py:135 app/views.py:138
msgid "failure"
msgstr ""
#: app/views.py:63 app/views.py:65 app/views.py:126 app/views.py:128
#: app/views.py:134 app/views.py:137 app/views.py:139 app/views.py:141
#: app/views.py:60 app/views.py:63 app/views.py:118 app/views.py:128
#: app/views.py:130 app/views.py:133 app/views.py:135 app/views.py:138
msgid "messages"
msgstr ""
#: app/views.py:63 app/views.py:137
#: app/views.py:60 app/views.py:133
msgid "parameter_missing"
msgstr ""
#: app/views.py:65 app/views.py:141
#: app/views.py:63 app/views.py:138
msgid "operation_failed"
msgstr ""
#: app/views.py:126
msgid "transaction_pending"
#: app/views.py:118
msgid "file_uploaded"
msgstr ""
#: app/views.py:128
msgid "file_not_found"
msgid "pending"
msgstr ""
#: app/views.py:134
msgid "file_uploaded"
#: app/views.py:128
msgid "transaction_pending"
msgstr ""
#: app/views.py:130
msgid "file_not_found"
msgstr ""
#: app/views.py:139
#: app/views.py:135
msgid "could_not_connect"
msgstr ""
No preview for this file type
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-08-13 11:02-0300\n"
"POT-Creation-Date: 2018-08-14 16:05-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -18,48 +18,52 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: TsaApi/settings.py:111
#: TsaApi/settings.py:114
msgid "Spanish"
msgstr ""
#: app/views.py:60 app/views.py:126 app/views.py:134
#: app/views.py:57 app/views.py:118
msgid "success"
msgstr "success"
#: app/views.py:60
#: app/views.py:57
msgid "proof"
msgstr "proof"
#: app/views.py:63 app/views.py:65 app/views.py:128 app/views.py:137
#: app/views.py:139 app/views.py:141
#: app/views.py:60 app/views.py:63 app/views.py:130 app/views.py:133
#: app/views.py:135 app/views.py:138
msgid "failure"
msgstr "failure"
#: app/views.py:63 app/views.py:65 app/views.py:126 app/views.py:128
#: app/views.py:134 app/views.py:137 app/views.py:139 app/views.py:141
#: app/views.py:60 app/views.py:63 app/views.py:118 app/views.py:128
#: app/views.py:130 app/views.py:133 app/views.py:135 app/views.py:138
msgid "messages"
msgstr "messages"
#: app/views.py:63 app/views.py:137
#: app/views.py:60 app/views.py:133
msgid "parameter_missing"
msgstr "Parámetro faltante: %s"
#: app/views.py:65 app/views.py:141
#: app/views.py:63 app/views.py:138
msgid "operation_failed"
msgstr "No se pudo realizar la operación"
#: app/views.py:126
#: app/views.py:118
msgid "file_uploaded"
msgstr "El archivo %s fue ingresado en el bloque %s el %s"
#: app/views.py:128
msgid "pending"
msgstr "pending"
#: app/views.py:128
msgid "transaction_pending"
msgstr "La transacción se encuentra pendiente de subida a la Blockchain"
#: app/views.py:128
#: app/views.py:130
msgid "file_not_found"
msgstr "No se encontró el archivo"
#: app/views.py:134
msgid "file_uploaded"
msgstr "El archivo %s fue ingresado en el bloque %s el %s"
#: app/views.py:139
#: app/views.py:135
msgid "could_not_connect"
msgstr "No se pudo conectar a la Blockchain"
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