From b20ad4090817e7828e665b3bd99ec36173231193 Mon Sep 17 00:00:00 2001 From: codegeschrei Date: Thu, 9 Aug 2018 14:19:25 +0200 Subject: [PATCH] Problem: store_transaction is deprecated Solution: replace it with store_bulk_transaction --- bigchaindb/backend/localmongodb/query.py | 10 ---------- bigchaindb/backend/query.py | 17 ++--------------- bigchaindb/lib.py | 20 -------------------- tests/tendermint/test_lib.py | 4 ++++ tests/web/test_block_tendermint.py | 5 +++++ 5 files changed, 11 insertions(+), 45 deletions(-) diff --git a/bigchaindb/backend/localmongodb/query.py b/bigchaindb/backend/localmongodb/query.py index 4f56dd73..85af8dcb 100644 --- a/bigchaindb/backend/localmongodb/query.py +++ b/bigchaindb/backend/localmongodb/query.py @@ -12,16 +12,6 @@ from bigchaindb.common.transaction import Transaction register_query = module_dispatch_registrar(backend.query) -@register_query(LocalMongoDBConnection) -def store_transaction(conn, signed_transaction): - try: - return conn.run( - conn.collection('transactions') - .insert_one(signed_transaction)) - except DuplicateKeyError: - pass - - @register_query(LocalMongoDBConnection) def store_transactions(conn, signed_transactions): return conn.run(conn.collection('transactions') diff --git a/bigchaindb/backend/query.py b/bigchaindb/backend/query.py index cd4646f5..5c738fb3 100644 --- a/bigchaindb/backend/query.py +++ b/bigchaindb/backend/query.py @@ -8,20 +8,6 @@ VALIDATOR_UPDATE_ID = 'a_unique_id_string' PRE_COMMIT_ID = 'a_unique_id_string' -@singledispatch -def store_transaction(connection, signed_transaction): - """Write a transaction to the backlog table. - - Args: - signed_transaction (dict): a signed transaction. - - Returns: - The result of the operation. - """ - - raise NotImplementedError - - @singledispatch def store_asset(connection, asset): """Write an asset to the asset table. @@ -364,6 +350,7 @@ def store_validator_set(conn, validator_update): @singledispatch def get_validator_set(conn, height): """Get validator set for a given `height`, if `height` is not specified - then return the latest validator set""" + then return the latest validator set + """ raise NotImplementedError diff --git a/bigchaindb/lib.py b/bigchaindb/lib.py index 12ab9dc8..bf4964ae 100644 --- a/bigchaindb/lib.py +++ b/bigchaindb/lib.py @@ -4,7 +4,6 @@ MongoDB. """ import logging from collections import namedtuple -from copy import deepcopy from uuid import uuid4 try: @@ -114,25 +113,6 @@ class BigchainDB(object): def process_status_code(self, status_code, failure_msg): return (202, '') if status_code == 0 else (500, failure_msg) - def store_transaction(self, transaction): - """Store a valid transaction to the transactions collection.""" - - # self.update_utxoset(transaction) - transaction = deepcopy(transaction.to_dict()) - if transaction['operation'] == 'CREATE': - asset = transaction.pop('asset') - asset['id'] = transaction['id'] - if asset['data']: - backend.query.store_asset(self.connection, asset) - - metadata = transaction.pop('metadata') - transaction_metadata = {'id': transaction['id'], - 'metadata': metadata} - - backend.query.store_metadatas(self.connection, [transaction_metadata]) - - return backend.query.store_transaction(self.connection, transaction) - def store_bulk_transactions(self, transactions): txns = [] assets = [] diff --git a/tests/tendermint/test_lib.py b/tests/tendermint/test_lib.py index bc5504a7..60bbff35 100644 --- a/tests/tendermint/test_lib.py +++ b/tests/tendermint/test_lib.py @@ -40,6 +40,10 @@ def test_asset_is_separated_from_transaciton(b): asset=asset)\ .sign([alice.private_key]) + # with store_bulk_transactions we use `insert_many` where PyMongo + # automatically adds an `_id` field to the tx, therefore we need the + # deepcopy, for more info see: + # https://api.mongodb.com/python/current/faq.html#writes-and-ids tx_dict = copy.deepcopy(tx.to_dict()) b.store_bulk_transactions([tx]) diff --git a/tests/web/test_block_tendermint.py b/tests/web/test_block_tendermint.py index 812d34b5..5592f319 100644 --- a/tests/web/test_block_tendermint.py +++ b/tests/web/test_block_tendermint.py @@ -15,6 +15,11 @@ def test_get_block_endpoint(tb, client, alice): b = tb tx = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset={'cycle': 'hero'}) tx = tx.sign([alice.private_key]) + + # with store_bulk_transactions we use `insert_many` where PyMongo + # automatically adds an `_id` field to the tx, therefore we need the + # deepcopy, for more info see: + # https://api.mongodb.com/python/current/faq.html#writes-and-ids tx_dict = copy.deepcopy(tx.to_dict()) b.store_bulk_transactions([tx])