mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Round timestamp and add uuid to payload.
Timestamp is now returned in UTC with second precision. Payload hash is replaced by an uuid4. This allows us to distinguish between duplicated payloads. Removed a deprecated test related to the payload hash. Renamded secondary index payload_hash -> payload_uuid
This commit is contained in:
parent
a3b37f0984
commit
a694efd9dc
@ -54,7 +54,7 @@ def init():
|
||||
.run(conn)
|
||||
# secondary index for payload hash
|
||||
r.db(dbname).table('bigchain')\
|
||||
.index_create('payload_hash', r.row['block']['transactions']['transaction']['data']['hash'], multi=True)\
|
||||
.index_create('payload_uuid', r.row['block']['transactions']['transaction']['data']['uuid'], multi=True)\
|
||||
.run(conn)
|
||||
|
||||
# wait for rethinkdb to finish creating secondary indexes
|
||||
|
@ -4,7 +4,7 @@ import contextlib
|
||||
import threading
|
||||
import queue
|
||||
import multiprocessing as mp
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
import rapidjson
|
||||
|
||||
@ -127,14 +127,13 @@ def deserialize(data):
|
||||
|
||||
|
||||
def timestamp():
|
||||
"""Calculate a UTC timestamp with microsecond precision.
|
||||
"""Calculate a UTC timestamp with second precision.
|
||||
|
||||
Returns:
|
||||
str: UTC timestamp.
|
||||
|
||||
"""
|
||||
dt = datetime.utcnow()
|
||||
return "{0:.6f}".format(time.mktime(dt.timetuple()) + dt.microsecond / 1e6)
|
||||
return str(round(time.time()))
|
||||
|
||||
|
||||
# TODO: Consider remove the operation (if there are no inputs CREATE else TRANSFER)
|
||||
@ -224,9 +223,8 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None):
|
||||
data = None
|
||||
if payload is not None:
|
||||
if isinstance(payload, dict):
|
||||
hash_payload = crypto.hash_data(serialize(payload))
|
||||
data = {
|
||||
'hash': hash_payload,
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'payload': payload
|
||||
}
|
||||
else:
|
||||
|
@ -48,24 +48,6 @@ class TestBigchainApi(object):
|
||||
assert b.validate_fulfillments(tx) == False
|
||||
assert b.validate_fulfillments(tx_signed) == True
|
||||
|
||||
def test_transaction_hash(self, b, user_vk):
|
||||
payload = {'cats': 'are awesome'}
|
||||
tx = b.create_transaction(user_vk, user_vk, None, 'CREATE', payload)
|
||||
tx_calculated = {
|
||||
'conditions': [{'cid': 0,
|
||||
'condition': tx['transaction']['conditions'][0]['condition'],
|
||||
'new_owners': [user_vk]}],
|
||||
'data': {'hash': crypto.hash_data(util.serialize(payload)),
|
||||
'payload': payload},
|
||||
'fulfillments': [{'current_owners': [user_vk],
|
||||
'fid': 0,
|
||||
'fulfillment': None,
|
||||
'input': None}],
|
||||
'operation': 'CREATE',
|
||||
'timestamp': tx['transaction']['timestamp']
|
||||
}
|
||||
assert tx['transaction']['data'] == tx_calculated['data']
|
||||
# assert tx_hash == tx_calculated_hash
|
||||
|
||||
def test_transaction_signature(self, b, user_sk, user_vk):
|
||||
tx = b.create_transaction(user_vk, user_vk, None, 'CREATE')
|
||||
|
Loading…
x
Reference in New Issue
Block a user