mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Switch to get_tx_by_payload_uuid
This commit is contained in:
parent
09e840faff
commit
b0350c521b
@ -217,18 +217,18 @@ class Bigchain(object):
|
|||||||
else:
|
else:
|
||||||
return None
|
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.
|
"""Retrieves transactions related to a digital asset.
|
||||||
|
|
||||||
When creating a transaction one of the optional arguments is the `payload`. The payload is a generic
|
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.
|
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
|
To make it easy to query the bigchain for that digital asset we create a UUID for the payload and
|
||||||
serialized payload and store it with the transaction. This makes it easy for developers to keep track
|
store it with the transaction. This makes it easy for developers to keep track of their digital
|
||||||
of their digital assets in bigchain.
|
assets in bigchain.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
payload_hash (str): sha3-256 hash of the serialized payload.
|
payload_uuid (str): the UUID for this particular payload.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A list of transactions containing that payload. If no transaction exists with that payload it
|
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') \
|
cursor = r.table('bigchain') \
|
||||||
.get_all(payload_hash, index='payload_hash') \
|
.get_all(payload_uuid, index='payload_uuid') \
|
||||||
.run(self.conn)
|
.run(self.conn)
|
||||||
|
|
||||||
transactions = list(cursor)
|
transactions = list(cursor)
|
||||||
|
@ -56,10 +56,6 @@ def init():
|
|||||||
r.db(dbname).table('bigchain')\
|
r.db(dbname).table('bigchain')\
|
||||||
.index_create('payload_uuid', r.row['block']['transactions']['transaction']['data']['uuid'], multi=True)\
|
.index_create('payload_uuid', r.row['block']['transactions']['transaction']['data']['uuid'], multi=True)\
|
||||||
.run(conn)
|
.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
|
# wait for rethinkdb to finish creating secondary indexes
|
||||||
r.db(dbname).table('backlog').index_wait().run(conn)
|
r.db(dbname).table('backlog').index_wait().run(conn)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user