From b4eb882b1e084a34ca124d938b7641e420ee3825 Mon Sep 17 00:00:00 2001 From: Lorenz Herzberger Date: Mon, 28 Nov 2022 13:08:38 +0100 Subject: [PATCH] refactored init.lua Signed-off-by: Lorenz Herzberger --- planetmint/backend/tarantool/init.lua | 155 ++++++++++++++++---------- 1 file changed, 94 insertions(+), 61 deletions(-) diff --git a/planetmint/backend/tarantool/init.lua b/planetmint/backend/tarantool/init.lua index 46344d9..a97e802 100644 --- a/planetmint/backend/tarantool/init.lua +++ b/planetmint/backend/tarantool/init.lua @@ -1,74 +1,107 @@ -abci_chains = box.schema.space.create('abci_chains', {engine='memtx', is_sync = false}) -abci_chains:format({{name='height' , type='integer'},{name='is_synched' , type='boolean'},{name='chain_id',type='string'}}) -abci_chains:create_index('id_search' ,{type='hash', parts={'chain_id'}}) -abci_chains:create_index('height_search' ,{type='tree',unique=false, parts={'height'}}) +box.cfg{listen = 3303} -assets = box.schema.space.create('assets' , {engine='memtx' , is_sync=false}) -assets:format({{name='data' , type='any'}, {name='tx_id', type='string'}, {name='asset_id', type='string'}}) -assets:create_index('txid_search', {type='hash', parts={'tx_id'}}) -assets:create_index('assetid_search', {type='tree',unique=false, parts={'asset_id', 'tx_id'}}) -assets:create_index('only_asset_search', {type='tree', unique=false, parts={'asset_id'}}) +abci_chains = box.schema.create_space('abci_chains', { if_not_exists = true }) +abci_chains:format({ + { name = 'id', type = 'string' }, + { name = 'height', type = 'unsigned' }, + { name = 'is_synced', type = 'boolean' } +}) +abci_chains:create_index('id', { parts = {'id'}}) +abci_chains:create_index('height', { parts = {'height'}}) -blocks = box.schema.space.create('blocks' , {engine='memtx' , is_sync=false}) -blocks:format{{name='app_hash',type='string'},{name='height' , type='integer'},{name='block_id' , type='string'}} -blocks:create_index('id_search' , {type='hash' , parts={'block_id'}}) -blocks:create_index('block_search' , {type='tree', unique = false, parts={'height'}}) -blocks:create_index('block_id_search', {type = 'hash', parts ={'block_id'}}) -blocks_tx = box.schema.space.create('blocks_tx') -blocks_tx:format{{name='transaction_id', type = 'string'}, {name = 'block_id', type = 'string'}} -blocks_tx:create_index('id_search',{ type = 'hash', parts={'transaction_id'}}) -blocks_tx:create_index('block_search', {type = 'tree',unique=false, parts={'block_id'}}) +-- Transactions +transactions = box.schema.create_space('transactions', { if_not_exists = true }) +transactions:format({ + { name = 'id', type = 'string' }, + { name = 'operation', type = 'string' }, + { name = 'version', type = 'string' }, + { name = 'metadata', type = 'string' }, + { name = 'assets', type = 'array' }, + { name = 'inputs', type = 'array', is_nullable = true }, + { name = 'scripts', type = 'map', is_nullable = true } +}) +transactions:create_index('id', { parts = {{ field = 'id', type = 'string' }}}) +transactions:create_index('transactions_by_asset', { parts = { + { field = 'assets[*].id', type = 'string', is_nullable = true }, + { field = 'assets[*].data', type = 'string', is_nullable = true } +}}) +transactions:create_index('spending_transaction_by_id_and_output_index', { parts = { + { field = 'inputs[*].fulfills["transaction_id"]', type = 'string' }, + { field = 'inputs[*].fulfills["output_index"]', type = 'unsigned' } +}}) -elections = box.schema.space.create('elections',{engine = 'memtx' , is_sync = false}) -elections:format({{name='election_id' , type='string'},{name='height' , type='integer'}, {name='is_concluded' , type='boolean'}}) -elections:create_index('id_search' , {type='hash', parts={'election_id'}}) -elections:create_index('height_search' , {type='tree',unique=false, parts={'height'}}) -elections:create_index('update_search', {type='tree', unique=false, parts={'election_id', 'height'}}) -meta_datas = box.schema.space.create('meta_data',{engine = 'memtx' , is_sync = false}) -meta_datas:format({{name='transaction_id' , type='string'}, {name='meta_data' , type='any'}}) -meta_datas:create_index('id_search', { type='hash' , parts={'transaction_id'}}) +-- Outputs +outputs = box.schema.create_space('outputs', { if_not_exists = true }) +outputs:format({ + { name = 'id', type = 'string' }, + { name = 'amount' , type='unsigned' }, + { name = 'public_keys', type='array' }, + { name = 'condition', type = 'map' }, + { name = 'output_index', type='number' }, + { name = 'transaction_id' , foreign_key = { space = 'transactions', field = 'id' }} +}) +outputs:create_index('id', { parts = {{ field = 'id', type = 'string' }}}) +outputs:create_index('transaction_id', { parts = {{ field = 'id', type = 'string' }}}) +outputs:create_index('public_keys', { unique = false, parts = {{field = 'public_keys[*]', type = 'string' }}}) -pre_commits = box.schema.space.create('pre_commits' , {engine='memtx' , is_sync=false}) -pre_commits:format({{name='commit_id', type='string'}, {name='height',type='integer'}, {name='transactions',type=any}}) -pre_commits:create_index('id_search', {type ='hash' , parts={'commit_id'}}) -pre_commits:create_index('height_search', {type ='tree',unique=true, parts={'height'}}) -validators = box.schema.space.create('validators' , {engine = 'memtx' , is_sync = false}) -validators:format({{name='validator_id' , type='string'},{name='height',type='integer'},{name='validators' , type='any'}}) -validators:create_index('id_search' , {type='hash' , parts={'validator_id'}}) -validators:create_index('height_search' , {type='tree', unique=true, parts={'height'}}) +-- Precommits +pre_commits = box.schema.create_space('pre_commits', { if_not_exists = true }) +pre_commits:format({ + { name = 'id', type = 'string' }, + { name = 'height', type = 'unsigned' }, + { name = 'transaction_ids', type = 'array'} +}) +pre_commits:create_index('id', { parts = {{ field = 'id', type = 'string' }}}) +pre_commits:create_index('height', { parts = {{ field = 'height', type = 'unsigned' }}}) -transactions = box.schema.space.create('transactions',{engine='memtx' , is_sync=false}) -transactions:format({{name='transaction_id' , type='string'}, {name='operation' , type='string'}, {name='version' ,type='string'}, {name='dict_map', type='any'}}) -transactions:create_index('id_search' , {type = 'hash' , parts={'transaction_id'}}) -transactions:create_index('transaction_search' , {type = 'tree',unique=false, parts={'operation', 'transaction_id'}}) -inputs = box.schema.space.create('inputs') -inputs:format({{name='transaction_id' , type='string'}, {name='fulfillment' , type='any'}, {name='owners_before' , type='array'}, {name='fulfills_transaction_id', type = 'string'}, {name='fulfills_output_index', type = 'string'}, {name='input_id', type='string'}, {name='input_index', type='number'}}) -inputs:create_index('delete_search' , {type = 'hash', parts={'input_id'}}) -inputs:create_index('spent_search' , {type = 'tree', unique=false, parts={'fulfills_transaction_id', 'fulfills_output_index'}}) -inputs:create_index('id_search', {type = 'tree', unique=false, parts = {'transaction_id'}}) +-- Blocks +blocks = box.schema.create_space('blocks', { if_not_exists = true }) +blocks:format({ + { name = 'id', type = 'string' }, + { name = 'app_hash', type = 'string' }, + { name = 'height', type = 'unsigned' }, + { name = 'transaction_ids', type = 'array' } +}) +blocks:create_index('id', { parts = {{ field = 'id', type = 'string' }}}) +blocks:create_index('height', { parts = {{ field = 'height', type = 'unsigned' }}}) +blocks:create_index('block_by_transaction_id', { parts = {{ field = 'transaction_ids[*]', type = 'string' }}}) -outputs = box.schema.space.create('outputs') -outputs:format({{name='transaction_id' , type='string'}, {name='amount' , type='string'}, {name='uri', type='string'}, {name='details_type', type='string'}, {name='details_public_key', type='any'}, {name = 'output_id', type = 'string'}, {name='treshold', type='any'}, {name='subconditions', type='any'}, {name='output_index', type='number'}}) -outputs:create_index('unique_search' ,{type='hash', parts={'output_id'}}) -outputs:create_index('id_search' ,{type='tree', unique=false, parts={'transaction_id'}}) -keys = box.schema.space.create('keys') -keys:format({{name = 'id', type='string'}, {name = 'transaction_id', type = 'string'} ,{name = 'output_id', type = 'string'}, {name = 'public_key', type = 'string'}, {name = 'key_index', type = 'integer'}}) -keys:create_index('id_search', {type = 'hash', parts={'id'}}) -keys:create_index('keys_search', {type = 'tree', unique=false, parts={'public_key'}}) -keys:create_index('txid_search', {type = 'tree', unique=false, parts={'transaction_id'}}) -keys:create_index('output_search', {type = 'tree', unique=false, parts={'output_id'}}) +-- UTXO +utxos = box.schema.create_space('utxos', { if_not_exists = true }) +utxos:format({ + { name = 'id', type = 'string' }, + { name = 'transaction_id', foreign_key = { space = 'transactions', field = 'id' } }, + { name = 'output_index', type = 'unsigned' }, + { name = 'utxo', type = 'map' } +}) +utxos:create_index('id', { parts = {{ field = 'id', type = 'string' }}}) +utxos:create_index('utxo_by_transaction_id_and_output_index', { parts = { + { field = 'transaction_id', type = 'string' }, + { field = 'output_index', type = 'unsigned' } +}}) -utxos = box.schema.space.create('utxos', {engine = 'memtx' , is_sync = false}) -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'}}) -scripts = box.schema.space.create('scripts' , {engine='memtx' , is_sync=false}) -scripts:format({{name='transaction_id', type='string'},{name='script' , type='any'}}) -scripts:create_index('txid_search', {type='hash', parts={'transaction_id'}}) +-- Elections +elections = box.schema.create_space('elections', { if_not_exists = true }) +elections:format({ + { name = 'id', type = 'string' }, + { name = 'height', type = 'unsigned' }, + { name = 'is_concluded', type = 'boolean' } +}) +elections:create_index('id', { parts = {{ field = 'id', type = 'string' }}}) +elections:create_index('height', { parts = {{ field = 'height', type = 'unsigned' }}}) + + +-- Validators +validator_sets = box.schema.create_space('validator_sets', { if_not_exists = true }) +validator_sets:format({ + { name = 'id', type = 'string' }, + { name = 'height', type = 'unsigned' }, + { name = 'set', type = 'array' } +}) +validator_sets:create_index('id', { parts = {{ field = 'id', type = 'string' }}}) \ No newline at end of file