from sqlalchemy import create_engine, desc, func from sqlalchemy.orm import sessionmaker from models import SystemData, TokenBase, ActiveTable, ConsumedTable, TransferLogs, TransactionHistory, TokenContractAssociation, ContractBase, ContractStructure, ContractParticipants, ContractTransactionHistory, ContractDeposits, ConsumedInfo, ContractWinners, ContinuosContractBase, ContractStructure2, ContractParticipants2, ContractDeposits2, ContractTransactionHistory2, SystemBase, ActiveContracts, SystemData, ContractAddressMapping, TokenAddressMapping, DatabaseTypeMapping, TimeActions, RejectedContractTransactionHistory, RejectedTransactionHistory, LatestCacheBase, LatestTransactions, LatestBlocks import json from tracktokens_smartcontracts import processTransaction, checkLocal_expiry_trigger_deposit, newMultiRequest import os import logging import argparse import configparser import shutil import sys import pdb # helper functions def check_database_existence(type, parameters): if type == 'token': return os.path.isfile(f"./tokens/{parameters['token_name']}.db") if type == 'smart_contract': return os.path.isfile(f"./smartContracts/{parameters['contract_name']}-{parameters['contract_address']}.db") def create_database_connection(type, parameters): if type == 'token': engine = create_engine(f"sqlite:///tokens/{parameters['token_name']}.db", echo=True) elif type == 'smart_contract': engine = create_engine(f"sqlite:///smartContracts/{parameters['contract_name']}-{parameters['contract_address']}.db", echo=True) elif type == 'system_dbs': engine = create_engine(f"sqlite:///{parameters['db_name']}.db", echo=False) connection = engine.connect() return connection def create_database_session_orm(type, parameters, base): if type == 'token': engine = create_engine(f"sqlite:///tokens/{parameters['token_name']}.db", echo=True) base.metadata.create_all(bind=engine) session = sessionmaker(bind=engine)() elif type == 'smart_contract': engine = create_engine(f"sqlite:///smartContracts/{parameters['contract_name']}-{parameters['contract_address']}.db", echo=True) base.metadata.create_all(bind=engine) session = sessionmaker(bind=engine)() elif type == 'system_dbs': engine = create_engine(f"sqlite:///{parameters['db_name']}.db", echo=False) base.metadata.create_all(bind=engine) session = sessionmaker(bind=engine)() return session # MAIN EXECUTION STARTS # Configuration of required variables logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s:%(name)s:%(message)s') file_handler = logging.FileHandler('tracking.log') file_handler.setLevel(logging.INFO) file_handler.setFormatter(formatter) stream_handler = logging.StreamHandler() stream_handler.setFormatter(formatter) logger.addHandler(file_handler) logger.addHandler(stream_handler) # Rule 1 - Read command line arguments to reset the databases as blank # Rule 2 - Read config to set testnet/mainnet # Rule 3 - Set flo blockexplorer location depending on testnet or mainnet # Rule 4 - Set the local flo-cli path depending on testnet or mainnet ( removed this feature | Flosights are the only source ) # Rule 5 - Set the block number to scan from # Read command line arguments parser = argparse.ArgumentParser(description='Script tracks RMT using FLO data on the FLO blockchain - https://flo.cash') parser.add_argument('-rb', '--resetblocknumer', nargs='?', type=int, help='Forward to the specified block number') args = parser.parse_args() # Read configuration config = configparser.ConfigParser() config.read('config.ini') # todo - write all assertions to make sure default configs are right if (config['DEFAULT']['NET'] != 'mainnet') and (config['DEFAULT']['NET'] != 'testnet'): logger.error("NET parameter in config.ini invalid. Options are either 'mainnet' or 'testnet'. Script is exiting now") sys.exit(0) # Specify mainnet and testnet server list for API calls and websocket calls serverlist = None if config['DEFAULT']['NET'] == 'mainnet': serverlist = config['DEFAULT']['MAINNET_FLOSIGHT_SERVER_LIST'] elif config['DEFAULT']['NET'] == 'testnet': serverlist = config['DEFAULT']['TESTNET_FLOSIGHT_SERVER_LIST'] serverlist = serverlist.split(',') neturl = config['DEFAULT']['FLOSIGHT_NETURL'] tokenapi_sse_url = config['DEFAULT']['TOKENAPI_SSE_URL'] # Update system.db's last scanned block connection = create_database_connection('system_dbs', {'db_name': "system"}) print(f"UPDATE systemData SET value = {int(args.resetblocknumer)} WHERE attribute = 'lastblockscanned';") pdb.set_trace() connection.execute(f"UPDATE systemData SET value = {int(args.resetblocknumer)} WHERE attribute = 'lastblockscanned';") connection.close()