mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 22:45:44 +00:00
store and get utxo fixed
This commit is contained in:
parent
c84acc689a
commit
f65cb049e8
@ -64,7 +64,7 @@ keys:create_index('txid_search', {type = 'tree', unique=false, parts={'transacti
|
||||
keys:create_index('output_search', {type = 'tree', unique=false, parts={'output_id'}})
|
||||
|
||||
utxos = box.schema.space.create('utxos', {engine = 'memtx' , is_sync = false})
|
||||
utxos:format({{name='transaction_id' , type='string'}, {name='output_index' , type='integer'}})
|
||||
utxos:format({{name='transaction_id' , type='string'}, {name='output_index' , type='integer'}, {name='utxo_dict', type='string'}})
|
||||
utxos:create_index('id_search', {type='hash' , parts={'transaction_id', 'output_index'}})
|
||||
utxos:create_index('transaction_search', {type='tree', unique=false, parts={'transaction_id'}})
|
||||
utxos:create_index('index_search', {type='tree', unique=false, parts={'output_index'}})
|
||||
@ -9,11 +9,10 @@ from secrets import token_hex
|
||||
from operator import itemgetter
|
||||
|
||||
from planetmint.backend import query
|
||||
from planetmint.backend.exceptions import DuplicateKeyError
|
||||
from planetmint.backend.exceptions import OperationError
|
||||
from planetmint.backend.utils import module_dispatch_registrar
|
||||
from planetmint.backend.tarantool.connection import TarantoolDB
|
||||
from planetmint.backend.tarantool.transaction.tools import TransactionCompose, TransactionDecompose
|
||||
from json import dumps, loads
|
||||
|
||||
register_query = module_dispatch_registrar(query)
|
||||
|
||||
@ -337,7 +336,7 @@ def store_unspent_outputs(connection, *unspent_outputs: list):
|
||||
space = connection.space('utxos')
|
||||
if unspent_outputs:
|
||||
for utxo in unspent_outputs:
|
||||
space.insert((utxo['transaction_id'], utxo['output_index']))
|
||||
space.insert((utxo['transaction_id'], utxo['output_index'], dumps(utxo)))
|
||||
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
@ -349,9 +348,10 @@ def delete_unspent_outputs(connection, *unspent_outputs: list):
|
||||
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
def get_unspent_outputs(connection):
|
||||
def get_unspent_outputs(connection, query=None): # for now we don't have implementation for 'query'.
|
||||
space = connection.space('utxos')
|
||||
return space.select()
|
||||
_utxos = space.select([]).data
|
||||
return [loads(utx[2]) for utx in _utxos]
|
||||
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
|
||||
@ -540,8 +540,9 @@ def dummy_unspent_outputs():
|
||||
|
||||
@pytest.fixture
|
||||
def utxoset(dummy_unspent_outputs, utxo_collection):
|
||||
from json import dumps
|
||||
for utxo in dummy_unspent_outputs:
|
||||
res = utxo_collection.insert((utxo["transaction_id"], utxo["output_index"]))
|
||||
res = utxo_collection.insert((utxo["transaction_id"], utxo["output_index"], dumps(utxo)))
|
||||
assert res
|
||||
assert len(utxo_collection.select()) == 3
|
||||
return dummy_unspent_outputs, utxo_collection
|
||||
|
||||
@ -7,7 +7,6 @@ from operator import index
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
try:
|
||||
from hashlib import sha3_256
|
||||
except ImportError:
|
||||
@ -220,6 +219,7 @@ def test_store_transaction(mocker, b, signed_create_tx,
|
||||
@pytest.mark.bdb
|
||||
def test_store_bulk_transaction(mocker, b, signed_create_tx,
|
||||
signed_transfer_tx, db_context):
|
||||
from planetmint.backend.tarantool.connection import TarantoolDB
|
||||
mocked_store_assets = mocker.patch(
|
||||
'planetmint.backend.query.store_assets')
|
||||
mocked_store_metadata = mocker.patch(
|
||||
@ -233,9 +233,15 @@ def test_store_bulk_transaction(mocker, b, signed_create_tx,
|
||||
# utxo = utxoset.find_one()
|
||||
# assert utxo['transaction_id'] == signed_create_tx.id
|
||||
# assert utxo['output_index'] == 0
|
||||
if isinstance(b.connection, TarantoolDB):
|
||||
mocked_store_assets.assert_called_once_with(
|
||||
b.connection,
|
||||
[ ( signed_create_tx.asset['data'], signed_create_tx.id, signed_create_tx.id )],
|
||||
b.connection, # signed_create_tx.asset['data'] this was before
|
||||
[(signed_create_tx.asset, signed_create_tx.id, signed_create_tx.id)],
|
||||
)
|
||||
else:
|
||||
mocked_store_assets.assert_called_once_with(
|
||||
b.connection, # signed_create_tx.asset['data'] this was before
|
||||
[(signed_create_tx.asset["data"], signed_create_tx.id, signed_create_tx.id)],
|
||||
)
|
||||
mocked_store_metadata.assert_called_once_with(
|
||||
b.connection,
|
||||
@ -254,6 +260,7 @@ def test_store_bulk_transaction(mocker, b, signed_create_tx,
|
||||
# utxo = utxoset.find_one()
|
||||
# assert utxo['transaction_id'] == signed_transfer_tx.id
|
||||
# assert utxo['output_index'] == 0
|
||||
if not isinstance(b.connection, TarantoolDB):
|
||||
assert not mocked_store_assets.called
|
||||
mocked_store_metadata.asser_called_once_with(
|
||||
b.connection,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user