mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
renamed payload to metadata
This commit is contained in:
parent
475fd0b06b
commit
fd585188e2
@ -325,28 +325,27 @@ class Bigchain(object):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_tx_by_payload_uuid(self, payload_uuid):
|
def get_tx_by_metadata_id(self, metadata_id):
|
||||||
"""Retrieves transactions related to a digital asset.
|
"""Retrieves transactions related to a payload.
|
||||||
|
|
||||||
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 `metadata`. The metadata is a generic
|
||||||
dict that contains information about the digital asset.
|
dict that contains extra information that can be appended to the transaction.
|
||||||
|
|
||||||
To make it easy to query BigchainDB for that digital asset we create a UUID for the payload and
|
To make it easy to query the bigchain for that particular metadata we create a UUID for the metadata and
|
||||||
store it with the transaction. This makes it easy for developers to keep track of their digital
|
store it with the transaction.
|
||||||
assets in bigchain.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
payload_uuid (str): the UUID for this particular payload.
|
metadata_id (str): the id for this particular metadata.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A list of transactions containing that payload. If no transaction exists with that payload it
|
A list of transactions containing that metadata. If no transaction exists with that metadata it
|
||||||
returns an empty list `[]`
|
returns an empty list `[]`
|
||||||
"""
|
"""
|
||||||
cursor = self.connection.run(
|
cursor = r.table('bigchain', read_mode=self.read_mode) \
|
||||||
r.table('bigchain', read_mode=self.read_mode)
|
.get_all(metadata_id, index='metadata_id') \
|
||||||
.get_all(payload_uuid, index='payload_uuid')
|
.concat_map(lambda block: block['block']['transactions']) \
|
||||||
.concat_map(lambda block: block['block']['transactions'])
|
.filter(lambda transaction: transaction['transaction']['metadata']['id'] == metadata_id) \
|
||||||
.filter(lambda transaction: transaction['transaction']['data']['uuid'] == payload_uuid))
|
.run(self.conn)
|
||||||
|
|
||||||
transactions = list(cursor)
|
transactions = list(cursor)
|
||||||
return [Transaction.from_dict(tx) for tx in transactions]
|
return [Transaction.from_dict(tx) for tx in transactions]
|
||||||
@ -535,8 +534,10 @@ class Bigchain(object):
|
|||||||
def prepare_genesis_block(self):
|
def prepare_genesis_block(self):
|
||||||
"""Prepare a genesis block."""
|
"""Prepare a genesis block."""
|
||||||
|
|
||||||
payload = {'message': 'Hello World from the BigchainDB'}
|
metadata = {'message': 'Hello World from the BigchainDB'}
|
||||||
transaction = Transaction.create([self.me], [self.me], payload=payload)
|
# TODO: When updating the BDBC lib, change `payload` to `metadata`
|
||||||
|
transaction = Transaction.create([self.me], [self.me],
|
||||||
|
payload=metadata)
|
||||||
|
|
||||||
# NOTE: The transaction model doesn't expose an API to generate a
|
# NOTE: The transaction model doesn't expose an API to generate a
|
||||||
# GENESIS transaction, as this is literally the only usage.
|
# GENESIS transaction, as this is literally the only usage.
|
||||||
|
@ -105,8 +105,8 @@ def create_bigchain_secondary_index(conn, dbname):
|
|||||||
.run(conn)
|
.run(conn)
|
||||||
# secondary index for payload data by UUID
|
# secondary index for payload data by UUID
|
||||||
r.db(dbname).table('bigchain')\
|
r.db(dbname).table('bigchain')\
|
||||||
.index_create('payload_uuid',
|
.index_create('metadata_id',
|
||||||
r.row['block']['transactions']['transaction']['data']['uuid'], multi=True)\
|
r.row['block']['transactions']['transaction']['metadata']['id'], multi=True)\
|
||||||
.run(conn)
|
.run(conn)
|
||||||
|
|
||||||
# wait for rethinkdb to finish creating secondary indexes
|
# wait for rethinkdb to finish creating secondary indexes
|
||||||
|
@ -49,8 +49,8 @@ def setup_database(request, node_config):
|
|||||||
r.db(db_name).table('backlog').index_create('transaction_timestamp', r.row['transaction']['timestamp']).run()
|
r.db(db_name).table('backlog').index_create('transaction_timestamp', r.row['transaction']['timestamp']).run()
|
||||||
# to query by payload uuid
|
# to query by payload uuid
|
||||||
r.db(db_name).table('bigchain').index_create(
|
r.db(db_name).table('bigchain').index_create(
|
||||||
'payload_uuid',
|
'metadata_id',
|
||||||
r.row['block']['transactions']['transaction']['data']['uuid'],
|
r.row['block']['transactions']['transaction']['metadata']['id'],
|
||||||
multi=True,
|
multi=True,
|
||||||
).run()
|
).run()
|
||||||
# compound index to read transactions from the backlog per assignee
|
# compound index to read transactions from the backlog per assignee
|
||||||
|
@ -79,7 +79,7 @@ def test_create_bigchain_secondary_index():
|
|||||||
assert r.db(dbname).table('bigchain').index_list().contains(
|
assert r.db(dbname).table('bigchain').index_list().contains(
|
||||||
'transaction_id').run(conn) is True
|
'transaction_id').run(conn) is True
|
||||||
assert r.db(dbname).table('bigchain').index_list().contains(
|
assert r.db(dbname).table('bigchain').index_list().contains(
|
||||||
'payload_uuid').run(conn) is True
|
'metadata_id').run(conn) is True
|
||||||
|
|
||||||
|
|
||||||
def test_create_backlog_table():
|
def test_create_backlog_table():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user