Update changes
This commit is contained in:
parent
43f3a91107
commit
f3918207be
@ -1,4 +1,4 @@
|
||||
from sqlalchemy import create_engine, func
|
||||
from sqlalchemy import create_engine, desc, func
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from models import SystemData, ActiveTable, ConsumedTable, TransferLogs, TransactionHistory, RejectedTransactionHistory, Base, ContractStructure, ContractBase, ContractParticipants, SystemBase, ActiveContracts, ContractAddressMapping, LatestCacheBase, ContractTransactionHistory, RejectedContractTransactionHistory, TokenContractAssociation, ContinuosContractBase, ContractStructure1, ContractParticipants1, ContractDeposits1, ContractTransactionHistory1, LatestTransactions, LatestBlocks, DatabaseTypeMapping
|
||||
import json
|
||||
@ -52,18 +52,6 @@ def create_database_session_orm(type, parameters, base):
|
||||
return session
|
||||
|
||||
|
||||
# rename all the old databases
|
||||
# system.db , latestCache.db, smartContracts, tokens
|
||||
if os.path.isfile('./system.db'):
|
||||
os.rename('system.db', 'system1.db')
|
||||
if os.path.isfile('./latestCache.db'):
|
||||
os.rename('latestCache.db', 'latestCache1.db')
|
||||
if os.path.isfile('./smartContracts'):
|
||||
os.rename('smartContracts', 'smartContracts1')
|
||||
if os.path.isfile('./tokens'):
|
||||
os.rename('tokens', 'tokens1')
|
||||
|
||||
|
||||
# MAIN EXECUTION STARTS
|
||||
# Configuration of required variables
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -91,8 +79,22 @@ logger.addHandler(stream_handler)
|
||||
|
||||
# Read command line arguments
|
||||
parser = argparse.ArgumentParser(description='Script tracks RMT using FLO data on the FLO blockchain - https://flo.cash')
|
||||
parser.add_argument('-r', '--reset', nargs='?', const=1, type=int, help='Purge existing db and rebuild it from scratch')
|
||||
parser.add_argument('-rb', '--rebuild', nargs='?', const=1, type=int, help='Rebuild it')
|
||||
parser.add_argument('-b', '--toblocknumer', nargs='?', type=int, help='Forward to the specified block number')
|
||||
parser.add_argument('-n', '--blockcount', nargs='?', type=int, help='Forward to the specified block count')
|
||||
args = parser.parse_args()
|
||||
|
||||
if (args.blockcount and args.toblocknumber):
|
||||
print("You can only specify one of the options -b or -c")
|
||||
sys.exit(0)
|
||||
elif args.blockcount:
|
||||
forward_block = lastscannedblock + args.blockcount
|
||||
elif args.toblocknumer:
|
||||
forward_block = args.toblocknumer
|
||||
else:
|
||||
latestCache_session = create_database_session_orm('system_dbs', {'db_name':'latestCache'}, LatestCacheBase)
|
||||
forward_block = int(latestCache_session.query(LatestBlocks.blockNumber).order_by(LatestBlocks.blockNumber.desc()).first())
|
||||
latestCache_session.close()
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
apppath = os.path.dirname(os.path.realpath(__file__))
|
||||
@ -103,6 +105,17 @@ dirpath = os.path.join(apppath, 'smartContracts')
|
||||
if not os.path.isdir(dirpath):
|
||||
os.mkdir(dirpath)
|
||||
|
||||
# rename all the old databases
|
||||
# system.db , latestCache.db, smartContracts, tokens
|
||||
if os.path.isfile('./system.db'):
|
||||
os.rename('system.db', 'system1.db')
|
||||
if os.path.isfile('./latestCache.db'):
|
||||
os.rename('latestCache.db', 'latestCache1.db')
|
||||
if os.path.isfile('./smartContracts'):
|
||||
os.rename('smartContracts', 'smartContracts1')
|
||||
if os.path.isfile('./tokens'):
|
||||
os.rename('tokens', 'tokens1')
|
||||
|
||||
# Read configuration
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
@ -190,4 +203,4 @@ if os.path.isfile('./tokens1'):
|
||||
# Update system.db's last scanned block
|
||||
connection = create_database_connection('system_dbs', {'db_name': "system"})
|
||||
connection.execute(f"UPDATE systemData SET value = {int(list(lblocks_dict.keys())[-1])} WHERE attribute = 'lastblockscanned';")
|
||||
connection.close()
|
||||
connection.close()
|
||||
@ -281,20 +281,32 @@ def perform_rollback(transaction):
|
||||
|
||||
|
||||
# Take input from user reg how many blocks to go back in the blockchain
|
||||
'''
|
||||
parser = argparse.ArgumentParser(description='Script tracks RMT using FLO data on the FLO blockchain - https://flo.cash')
|
||||
parser.add_argument('-rbk', '--rollback', nargs='?', const=1, type=int, help='Rollback the script')
|
||||
args = parser.parse_args()
|
||||
'''
|
||||
|
||||
number_blocks_to_rollback = 1754000
|
||||
parser = argparse.ArgumentParser(description='Script tracks RMT using FLO data on the FLO blockchain - https://flo.cash')
|
||||
parser.add_argument('-b', '--toblocknumer', nargs='?', type=int, help='Rollback the script to the specified block number')
|
||||
parser.add_argument('-n', '--blockcount', nargs='?', type=int, help='Rollback the script to the number of blocks specified')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
# Get all the transaction and blockdetails from latestCache reg the transactions in the block
|
||||
systemdb_session = create_database_session_orm('system_dbs', {'db_name': 'system'}, SystemBase)
|
||||
lastscannedblock = systemdb_session.query(SystemData.value).filter(SystemData.attribute=='lastblockscanned').first()
|
||||
systemdb_session.close()
|
||||
lastscannedblock = int(lastscannedblock.value)
|
||||
rollback_block = lastscannedblock - number_blocks_to_rollback
|
||||
|
||||
|
||||
#number_blocks_to_rollback = 1754000
|
||||
if (args.blockcount and args.toblocknumber):
|
||||
print("You can only specify one of the options -b or -c")
|
||||
sys.exit(0)
|
||||
elif args.blockcount:
|
||||
rollback_block = lastscannedblock - args.blockcount
|
||||
elif args.toblocknumer:
|
||||
rollback_block = args.toblocknumer
|
||||
else:
|
||||
print("Please specify the number of blocks to rollback")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
latestcache_session = create_database_session_orm('system_dbs', {'db_name': 'latestCache'}, LatestCacheBase)
|
||||
latestBlocks = latestcache_session.query(LatestBlocks).filter(LatestBlocks.blockNumber >= rollback_block).all()
|
||||
@ -368,13 +380,3 @@ for blockindex in blocknumber_list:
|
||||
systemdb_session.commit()
|
||||
latestcache_session.close()
|
||||
systemdb_session.close()
|
||||
|
||||
|
||||
'''
|
||||
latestcache_session = create_database_session_orm('system_dbs', {'db_name': 'latestCache'}, LatestCacheBase)
|
||||
latestTransactions = latestcache_session.query(LatestTransactions).filter(LatestTransactions.blockNumber >= rollback_block).order_by(LatestTransactions.id.desc()).all()
|
||||
latestBlocks = latestcache_session.query(LatestBlocks).filter(LatestBlocks.blockNumber >= rollback_block).all()
|
||||
|
||||
#for transaction in latestTransactions:
|
||||
perform_rollback(latestTransactions[0])
|
||||
'''
|
||||
@ -79,10 +79,21 @@ logger.addHandler(stream_handler)
|
||||
|
||||
# Read command line arguments
|
||||
parser = argparse.ArgumentParser(description='Script tracks RMT using FLO data on the FLO blockchain - https://flo.cash')
|
||||
parser.add_argument('-r', '--reset', nargs='?', const=1, type=int, help='Purge existing db and rebuild it from scratch')
|
||||
parser.add_argument('-rb', '--rebuild', nargs='?', const=1, type=int, help='Rebuild it')
|
||||
parser.add_argument('-f', '--forwardblock', nargs='?', type=int, help='Forward block number')
|
||||
args = parser.parse_args()
|
||||
parser.add_argument('-b', '--toblocknumer', nargs='?', type=int, help='Forward to the specified block number')
|
||||
parser.add_argument('-n', '--blockcount', nargs='?', type=int, help='Forward to the specified block count')
|
||||
args = parser.parse_args()
|
||||
|
||||
if (args.blockcount and args.toblocknumber):
|
||||
print("You can only specify one of the options -b or -c")
|
||||
sys.exit(0)
|
||||
elif args.blockcount:
|
||||
forward_block = lastscannedblock + args.blockcount
|
||||
elif args.toblocknumer:
|
||||
forward_block = args.toblocknumer
|
||||
else:
|
||||
print("Please specify the number of blocks to rollback")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
apppath = os.path.dirname(os.path.realpath(__file__))
|
||||
dirpath = os.path.join(apppath, 'tokens')
|
||||
@ -177,9 +188,8 @@ startblock = int(session.query(SystemData).filter_by(attribute='lastblockscanned
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
for blockindex in range(startblock, args.forwardblock):
|
||||
for blockindex in range(startblock, forward_block):
|
||||
processBlock(blockindex=blockindex)
|
||||
|
||||
# Update system.db's last scanned block
|
||||
connection = create_database_connection('system_dbs', {'db_name': "system"})
|
||||
connection.execute(f"UPDATE systemData SET value = {blockindex} WHERE attribute = 'lastblockscanned';")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user