mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +00:00
commit
65b9887a6d
23
planetmint/backend/tarantool/database.py
Normal file
23
planetmint/backend/tarantool/database.py
Normal file
@ -0,0 +1,23 @@
|
||||
import tarantool
|
||||
import os
|
||||
from planetmint.backend.tarantool.utils import run
|
||||
|
||||
|
||||
class TarantoolDB:
|
||||
def __init__(self , host , port , username , password):
|
||||
self.conn = tarantool.connect(host=host , port=port , user = username , password=password)
|
||||
|
||||
|
||||
def connect_to_sapce(self,spacename):
|
||||
self.conn.space(spacename)
|
||||
|
||||
|
||||
def init_tarantool():
|
||||
path = os.getcwd()
|
||||
run(["mkdir" , "tarantool"])
|
||||
run(["ln","-s",path +"/init.lua","init.lua"] , path+"/tarantool")
|
||||
run (["tarantool" , "init.lua"] ,path+ "/tarantool")
|
||||
|
||||
def drop_tarantool():
|
||||
#TODO drop tarantool
|
||||
pass
|
||||
19
planetmint/backend/tarantool/init.lua
Normal file
19
planetmint/backend/tarantool/init.lua
Normal file
@ -0,0 +1,19 @@
|
||||
box.cfg{listen=3301}
|
||||
|
||||
transactions = box.schema.space.create('transactions',{engine='memtx' , is_sync=false,if_not_exists = true})
|
||||
transactions:format({{name='transaction_id' , type='string'},{name='operation' , type='string'}, {name='version' ,type='string'}})
|
||||
transactions:create_index('id_search' , {type = 'hash' , parts={'transaction_id'},if_not_exists=true})
|
||||
|
||||
inputs = box.schema.space.create('inputs',{engine='memtx' , is_sync=false,if_not_exists = true})
|
||||
inputs:format({{name='transaction_id' , type='string'},{name='fullfilment' , type='string'},{name='owners_before' , type='array'}, {name='fulfills_transaction_id', type = 'string'}, {name='fulfills_output_index', type = 'string'}})
|
||||
inputs:create_index('spent_search' , {type = 'hash' , parts={'fulfills_transaction_id', 'fulfills_output_index'},if_not_exists=true})
|
||||
|
||||
outputs = box.schema.space.create('outputs',{engine='memtx' , is_sync=false,if_not_exists = true})
|
||||
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='string'}, {name = 'public_keys', type = 'array'}})
|
||||
outputs:create_index('id_search' ,{type='hash' , parts={'transaction_id'},if_not_exists=true})
|
||||
outputs:create_index('keys_search' ,{type='rtree' , parts={'public_keys'},if_not_exists=true})
|
||||
|
||||
keys = box.schema.space.create('keys',{engine='memtx' , is_sync=false,if_not_exists = true})
|
||||
keys:format({{name='transaction_id' , type='string'}, {name='public_keys' , type='array'}, {name = 'output_id', type = 'string'}})
|
||||
keys:create_index('id_search' ,{type='hash' , parts={'transaction_id', 'output_id'},if_not_exists=true})
|
||||
keys:create_index('keys_search', {type='rtree', parts={'public_keys'},if_not_exists=true})
|
||||
26
planetmint/backend/tarantool/utils.py
Normal file
26
planetmint/backend/tarantool/utils.py
Normal file
@ -0,0 +1,26 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def run(command , path=None):
|
||||
if path is not None:
|
||||
os.chdir(path)
|
||||
p=subprocess.Popen(
|
||||
command,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
|
||||
output , error = p.communicate()
|
||||
if p.returncode != 0:
|
||||
print(p.returncode + "\n" + output + "\n" +error)
|
||||
else:
|
||||
p=subprocess.run(
|
||||
command,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
|
||||
output , error = p.communicate()
|
||||
if p.returncode != 0:
|
||||
print(p.returncode + "\n" + output + "\n" +error)
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import argparse
|
||||
import copy
|
||||
import json
|
||||
import sys
|
||||
from planetmint.backend.tarantool.database import TarantoolDB, init_tarantool
|
||||
|
||||
from planetmint.core import rollback
|
||||
from planetmint.migrations.chain_migration_election import ChainMigrationElection
|
||||
@ -25,6 +26,7 @@ import planetmint
|
||||
from planetmint import (backend, ValidatorElection,
|
||||
Planetmint)
|
||||
from planetmint.backend import schema
|
||||
from planetmint.backend.tarantool import tarantool
|
||||
from planetmint.commands import utils
|
||||
from planetmint.commands.utils import (configure_planetmint,
|
||||
input_on_stderr)
|
||||
@ -241,9 +243,11 @@ def run_election_show(args, planet):
|
||||
|
||||
|
||||
def _run_init():
|
||||
bdb = planetmint.Planetmint()
|
||||
#bdb = planetmint.Planetmint()
|
||||
|
||||
schema.init_database(connection=bdb.connection)
|
||||
#schema.init_database(connection=bdb.connection)
|
||||
|
||||
init_tarantool()
|
||||
|
||||
|
||||
@configure_planetmint
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user