mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Revert "revert get_tx_by_payload_hash"
This reverts commit fb2cd532a9462ae4fc3c50056f01b37467816848.
This commit is contained in:
parent
fb2cd532a9
commit
5bc66a28c1
@ -177,24 +177,36 @@ class Bigchain(object):
|
|||||||
|
|
||||||
def get_tx_by_payload_hash(self, payload_hash):
|
def get_tx_by_payload_hash(self, payload_hash):
|
||||||
"""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 sha3-256 hash of the
|
||||||
serialized payload and store it with the transaction. This makes it easy for developers to keep track
|
serialized payload and store it with the transaction. This makes it easy for developers to keep track
|
||||||
of their digital assets in bigchain.
|
of their digital assets in bigchain.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
payload_hash (str): sha3-256 hash of the serialized payload.
|
payload_hash (str): sha3-256 hash of the serialized 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
|
||||||
returns an empty list `[]`
|
returns an empty list `[]`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cursor = r.table('bigchain') \
|
# First, get information on all blocks which contain this hash
|
||||||
.get_all(payload_hash, index='payload_hash') \
|
blocks = self.search_block_election_on_index(payload_hash, 'payload_hash')
|
||||||
.run(self.conn)
|
if blocks:
|
||||||
|
validity = {block['id']: self.block_election_status(block) for block in blocks}
|
||||||
|
|
||||||
transactions = list(cursor)
|
# disregard invalid blocks
|
||||||
return transactions
|
validity = {_id: status for _id, status in validity.items() if status != 'invalid'}
|
||||||
|
cursor = r.table('bigchain').get_all(*list(validity.keys()))\
|
||||||
|
.get_all(payload_hash, index='payload_hash')\
|
||||||
|
.run(self.conn)
|
||||||
|
|
||||||
|
return list(cursor)
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
def get_spent(self, tx_input):
|
def get_spent(self, tx_input):
|
||||||
"""Check if a `txid` was already used as an input.
|
"""Check if a `txid` was already used as an input.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user