From fd585188e200acccca159fc5b39b7a8823e515b4 Mon Sep 17 00:00:00 2001 From: Rodolphe Marques Date: Tue, 23 Aug 2016 17:21:20 +0200 Subject: [PATCH] renamed payload to metadata --- bigchaindb/core.py | 33 +++++++++++++++++---------------- bigchaindb/db/utils.py | 4 ++-- tests/db/conftest.py | 4 ++-- tests/db/test_utils.py | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/bigchaindb/core.py b/bigchaindb/core.py index e8e673ce..86ccfea8 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -325,28 +325,27 @@ class Bigchain(object): else: return None - def get_tx_by_payload_uuid(self, payload_uuid): - """Retrieves transactions related to a digital asset. + def get_tx_by_metadata_id(self, metadata_id): + """Retrieves transactions related to a payload. - 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. + When creating a transaction one of the optional arguments is the `metadata`. The metadata is a generic + 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 - 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 particular metadata we create a UUID for the metadata and + store it with the transaction. Args: - payload_uuid (str): the UUID for this particular payload. + metadata_id (str): the id for this particular metadata. 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 `[]` """ - cursor = self.connection.run( - r.table('bigchain', read_mode=self.read_mode) - .get_all(payload_uuid, index='payload_uuid') - .concat_map(lambda block: block['block']['transactions']) - .filter(lambda transaction: transaction['transaction']['data']['uuid'] == payload_uuid)) + cursor = r.table('bigchain', read_mode=self.read_mode) \ + .get_all(metadata_id, index='metadata_id') \ + .concat_map(lambda block: block['block']['transactions']) \ + .filter(lambda transaction: transaction['transaction']['metadata']['id'] == metadata_id) \ + .run(self.conn) transactions = list(cursor) return [Transaction.from_dict(tx) for tx in transactions] @@ -535,8 +534,10 @@ class Bigchain(object): def prepare_genesis_block(self): """Prepare a genesis block.""" - payload = {'message': 'Hello World from the BigchainDB'} - transaction = Transaction.create([self.me], [self.me], payload=payload) + metadata = {'message': 'Hello World from the BigchainDB'} + # 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 # GENESIS transaction, as this is literally the only usage. diff --git a/bigchaindb/db/utils.py b/bigchaindb/db/utils.py index 0ed74471..73236dc1 100644 --- a/bigchaindb/db/utils.py +++ b/bigchaindb/db/utils.py @@ -105,8 +105,8 @@ def create_bigchain_secondary_index(conn, dbname): .run(conn) # secondary index for payload data by UUID r.db(dbname).table('bigchain')\ - .index_create('payload_uuid', - r.row['block']['transactions']['transaction']['data']['uuid'], multi=True)\ + .index_create('metadata_id', + r.row['block']['transactions']['transaction']['metadata']['id'], multi=True)\ .run(conn) # wait for rethinkdb to finish creating secondary indexes diff --git a/tests/db/conftest.py b/tests/db/conftest.py index c6bcbe44..4268f51b 100644 --- a/tests/db/conftest.py +++ b/tests/db/conftest.py @@ -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() # to query by payload uuid r.db(db_name).table('bigchain').index_create( - 'payload_uuid', - r.row['block']['transactions']['transaction']['data']['uuid'], + 'metadata_id', + r.row['block']['transactions']['transaction']['metadata']['id'], multi=True, ).run() # compound index to read transactions from the backlog per assignee diff --git a/tests/db/test_utils.py b/tests/db/test_utils.py index f22bcd04..56f09ac5 100644 --- a/tests/db/test_utils.py +++ b/tests/db/test_utils.py @@ -79,7 +79,7 @@ def test_create_bigchain_secondary_index(): assert r.db(dbname).table('bigchain').index_list().contains( 'transaction_id').run(conn) is True 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():