mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +00:00
Merge pull request #146 from andreitricolici/planetmint-tarantool
Planetmint tarantool
This commit is contained in:
commit
fc52f86ccb
@ -5,6 +5,7 @@
|
||||
|
||||
"""Query implementation for Tarantool"""
|
||||
from secrets import token_hex
|
||||
from hashlib import sha256
|
||||
from operator import itemgetter
|
||||
|
||||
import tarantool.error
|
||||
@ -15,6 +16,7 @@ from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||
from planetmint.backend.tarantool.transaction.tools import TransactionCompose, TransactionDecompose
|
||||
from json import dumps, loads
|
||||
|
||||
|
||||
register_query = module_dispatch_registrar(query)
|
||||
|
||||
|
||||
@ -515,18 +517,23 @@ def get_asset_tokens_for_public_key(connection, asset_id: str,
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def store_abci_chain(connection, height: int, chain_id: str, is_synced: bool = True):
|
||||
connection.run(connection.space("abci_chains").delete(chain_id), only_data=False)
|
||||
connection.run(connection.space("abci_chains").insert((height, is_synced, chain_id)), only_data=False)
|
||||
hash_id_primarykey = sha256(dumps(obj={"height": height}).encode()).hexdigest()
|
||||
connection.run(
|
||||
connection.space("abci_chains").upsert((height, is_synced, chain_id, hash_id_primarykey),
|
||||
op_list=[
|
||||
('=', 0, height),
|
||||
('=', 1, is_synced),
|
||||
('=', 2, chain_id)
|
||||
]),
|
||||
only_data=False
|
||||
)
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def delete_abci_chain(connection, height: int):
|
||||
_chains = connection.run(
|
||||
connection.space("abci_chains").select(height, index="height_search")
|
||||
)
|
||||
for _chain in _chains:
|
||||
hash_id_primarykey = sha256(dumps(obj={"height": height}).encode()).hexdigest()
|
||||
connection.run(
|
||||
connection.space("abci_chains").delete(_chain[2]),
|
||||
connection.space("abci_chains").delete(hash_id_primarykey),
|
||||
only_data=False
|
||||
)
|
||||
|
||||
|
||||
@ -32,8 +32,8 @@ SPACE_COMMANDS = {
|
||||
INDEX_COMMANDS = {
|
||||
"abci_chains":
|
||||
{
|
||||
"id_search": "abci_chains:create_index('id_search' ,{type='hash', parts={'chain_id'}})",
|
||||
"height_search": "abci_chains:create_index('height_search' ,{type='tree',unique=false, parts={'height'}})"
|
||||
"id_search": "abci_chains:create_index('id_search' ,{type='hash', parts={'id'}})",
|
||||
"height_search": "abci_chains:create_index('height_search' ,{type='tree', unique=false, parts={'height'}})"
|
||||
},
|
||||
"assets":
|
||||
{
|
||||
@ -105,7 +105,7 @@ INDEX_COMMANDS = {
|
||||
|
||||
SCHEMA_COMMANDS = {
|
||||
"abci_chains":
|
||||
"abci_chains:format({{name='height' , type='integer'},{name='is_synched' , type='boolean'},{name='chain_id',type='string'}})",
|
||||
"abci_chains:format({{name='height' , type='integer'},{name='is_synched' , type='boolean'},{name='chain_id',type='string'}, {name='id', type='string'}})",
|
||||
"assets":
|
||||
"assets:format({{name='data' , type='any'}, {name='tx_id', type='string'}, {name='asset_id', type='string'}})",
|
||||
"blocks":
|
||||
|
||||
@ -39,7 +39,7 @@ def flush_tarantool_db(connection, dbname):
|
||||
for _id in _all_data:
|
||||
if "assets" == s:
|
||||
connection.run(connection.space(s).delete(_id[1]), only_data=False)
|
||||
elif s in ["blocks", "abci_chains"]:
|
||||
elif s == "blocks":
|
||||
connection.run(connection.space(s).delete(_id[2]), only_data=False)
|
||||
elif s == "inputs":
|
||||
connection.run(connection.space(s).delete(_id[-2]), only_data=False)
|
||||
@ -47,6 +47,8 @@ def flush_tarantool_db(connection, dbname):
|
||||
connection.run(connection.space(s).delete(_id[-4]), only_data=False)
|
||||
elif s == "utxos":
|
||||
connection.run(connection.space(s).delete([_id[0], _id[1]]), only_data=False)
|
||||
elif s == "abci_chains":
|
||||
connection.run(connection.space(s).delete(_id[-1]), only_data=False)
|
||||
else:
|
||||
connection.run(connection.space(s).delete(_id[0]), only_data=False)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user