mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: store_transaction is deprecated
Solution: replace it with store_bulk_transaction
This commit is contained in:
parent
2bfcd76d17
commit
b20ad40908
@ -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')
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 = []
|
||||
|
||||
@ -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])
|
||||
|
||||
@ -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])
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user