Switch to get_tx_by_payload_uuid

This commit is contained in:
Shaun Stanworth 2016-07-01 11:16:57 +01:00
parent 09e840faff
commit b0350c521b
2 changed files with 6 additions and 10 deletions

View File

@ -217,18 +217,18 @@ class Bigchain(object):
else:
return None
def get_tx_by_payload_hash(self, payload_hash):
def get_tx_by_payload_uuid(self, payload_uuid):
"""Retrieves transactions related to a digital asset.
When creating a transaction one of the optional arguments is the `payload`. The payload is a generic
dict that contains information about the digital asset.
To make it easy to query the bigchain for that digital asset we create a sha3-256 hash of the
serialized payload and store it with the transaction. This makes it easy for developers to keep track
of their digital assets in bigchain.
To make it easy to query the bigchain for that digital asset we create a UUID for the payload and
store it with the transaction. This makes it easy for developers to keep track of their digital
assets in bigchain.
Args:
payload_hash (str): sha3-256 hash of the serialized payload.
payload_uuid (str): the UUID for this particular payload.
Returns:
A list of transactions containing that payload. If no transaction exists with that payload it
@ -236,7 +236,7 @@ class Bigchain(object):
"""
cursor = r.table('bigchain') \
.get_all(payload_hash, index='payload_hash') \
.get_all(payload_uuid, index='payload_uuid') \
.run(self.conn)
transactions = list(cursor)

View File

@ -56,10 +56,6 @@ def init():
r.db(dbname).table('bigchain')\
.index_create('payload_uuid', r.row['block']['transactions']['transaction']['data']['uuid'], multi=True)\
.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)\
.run(conn)
# wait for rethinkdb to finish creating secondary indexes
r.db(dbname).table('backlog').index_wait().run(conn)