diff --git a/util_rebuild_withAPI.py b/util_rebuild_withAPI.py index 6aa716d..58c9481 100644 --- a/util_rebuild_withAPI.py +++ b/util_rebuild_withAPI.py @@ -81,7 +81,9 @@ logger.addHandler(stream_handler) parser = argparse.ArgumentParser(description='Script tracks RMT using FLO data on the FLO blockchain - https://flo.cash') parser.add_argument('-rb', '--toblocknumer', nargs='?', type=int, help='Forward to the specified block number') parser.add_argument('-r', '--blockcount', nargs='?', type=int, help='Forward to the specified block count') -args = parser.parse_args() +parser.add_argument('-to', '--to_blockNumber', nargs='?', type=int, help='Process until the specified block number') # New argument +args = parser.parse_args() + if (args.blockcount and args.toblocknumber): print("You can only specify one of the options -b or -c") @@ -196,6 +198,7 @@ for transaction in ltransactions: # Check if any internal action block lies between prev_block and current_block for internal_block in internal_action_blocks: + if prev_block < internal_block <= current_block: logger.info(f'Processing block {internal_block}') # Get block details @@ -216,6 +219,11 @@ for transaction in ltransactions: prev_block = current_block continue + # Check if the current block exceeds the specified "to_blockNumber" + if current_block >= args.to_blockNumber: + logger.info(f"Reached the specified block number {args.to_blockNumber}. Stopping processing.") + break + # copy the old block data old_latest_cache = create_database_connection('system_dbs', {'db_name':'latestCache1'}) old_latest_cache.execute("ATTACH DATABASE 'latestCache.db' AS new_db") diff --git a/util_reset_latest_block.py b/util_reset_latest_block.py new file mode 100644 index 0000000..d0deac3 --- /dev/null +++ b/util_reset_latest_block.py @@ -0,0 +1,111 @@ +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() \ No newline at end of file