Further refactoring of code functions
This commit is contained in:
parent
a61d21817d
commit
23db3656aa
1038
input_classifier.py
1038
input_classifier.py
File diff suppressed because it is too large
Load Diff
53
parsing.py
53
parsing.py
@ -2,6 +2,7 @@ import pdb
|
||||
import re
|
||||
import arrow
|
||||
import pybtc
|
||||
import logging
|
||||
|
||||
"""
|
||||
Find make lists of #, *, @ words
|
||||
@ -293,7 +294,7 @@ def extract_contract_conditions(text, contract_type, marker=None, blocktime=None
|
||||
numberList = sorted(numberList)
|
||||
for idx, item in enumerate(numberList):
|
||||
if numberList[idx] + 1 != numberList[idx + 1]:
|
||||
print('Contract condition numbers are not in order')
|
||||
logger.info('Contract condition numbers are not in order')
|
||||
return None
|
||||
if idx == len(numberList) - 2:
|
||||
break
|
||||
@ -315,11 +316,11 @@ def extract_contract_conditions(text, contract_type, marker=None, blocktime=None
|
||||
expirytime_object = arrow.get(parse_string, 'YYYY/M/D HH:mm:ss').replace(tzinfo=expirytime_split[5])
|
||||
blocktime_object = arrow.get(blocktime)
|
||||
if expirytime_object < blocktime_object:
|
||||
print('Expirytime of the contract is earlier than the block it is incorporated in. This incorporation will be rejected ')
|
||||
logger.info('Expirytime of the contract is earlier than the block it is incorporated in. This incorporation will be rejected ')
|
||||
return False
|
||||
extractedRules['expiryTime'] = expirytime
|
||||
except:
|
||||
print('Error parsing expiry time')
|
||||
logger.info('Error parsing expiry time')
|
||||
return False
|
||||
|
||||
for rule in rulelist:
|
||||
@ -332,7 +333,7 @@ def extract_contract_conditions(text, contract_type, marker=None, blocktime=None
|
||||
try:
|
||||
extractedRules['contractAmount'] = float(contractamount)
|
||||
except:
|
||||
print("Contract amount entered is not a decimal")
|
||||
logger.info("Contract amount entered is not a decimal")
|
||||
elif rule[:11] == 'userchoices':
|
||||
pattern = re.compile('[^userchoices\s*=\s*].*')
|
||||
conditions = pattern.search(rule).group(0)
|
||||
@ -348,7 +349,7 @@ def extract_contract_conditions(text, contract_type, marker=None, blocktime=None
|
||||
extractedRules['minimumsubscriptionamount'] = float(
|
||||
minimumsubscriptionamount)
|
||||
except:
|
||||
print("Minimum subscription amount entered is not a decimal")
|
||||
logger.info("Minimum subscription amount entered is not a decimal")
|
||||
elif rule[:25] == 'maximumsubscriptionamount':
|
||||
pattern = re.compile('[^maximumsubscriptionamount\s*=\s*].*')
|
||||
searchResult = pattern.search(rule).group(0)
|
||||
@ -357,7 +358,7 @@ def extract_contract_conditions(text, contract_type, marker=None, blocktime=None
|
||||
extractedRules['maximumsubscriptionamount'] = float(
|
||||
maximumsubscriptionamount)
|
||||
except:
|
||||
print("Maximum subscription amount entered is not a decimal")
|
||||
logger.info("Maximum subscription amount entered is not a decimal")
|
||||
elif rule[:12] == 'payeeaddress':
|
||||
pattern = re.compile('[^payeeAddress\s*=\s*].*')
|
||||
searchResult = pattern.search(rule).group(0)
|
||||
@ -424,7 +425,7 @@ def extract_tokenswap_contract_conditions(processed_text, contract_type, contrac
|
||||
numberList = sorted(numberList)
|
||||
for idx, item in enumerate(numberList):
|
||||
if numberList[idx] + 1 != numberList[idx + 1]:
|
||||
print('Contract condition numbers are not in order')
|
||||
logger.info('Contract condition numbers are not in order')
|
||||
return None
|
||||
if idx == len(numberList) - 2:
|
||||
break
|
||||
@ -489,7 +490,7 @@ def extract_deposit_conditions(text, blocktime=None):
|
||||
numberList = sorted(numberList)
|
||||
for idx, item in enumerate(numberList):
|
||||
if len(numberList) > 1 and numberList[idx] + 1 != numberList[idx + 1]:
|
||||
print('Deposit condition numbers are not in order')
|
||||
logger.info('Deposit condition numbers are not in order')
|
||||
return None
|
||||
if idx == len(numberList) - 2:
|
||||
break
|
||||
@ -511,11 +512,11 @@ def extract_deposit_conditions(text, blocktime=None):
|
||||
expirytime_object = arrow.get(parse_string, 'YYYY/M/D HH:mm:ss').replace(tzinfo=expirytime_split[5])
|
||||
blocktime_object = arrow.get(blocktime)
|
||||
if expirytime_object < blocktime_object:
|
||||
print('Expirytime of the contract is earlier than the block it is incorporated in. This incorporation will be rejected ')
|
||||
logger.info('Expirytime of the contract is earlier than the block it is incorporated in. This incorporation will be rejected ')
|
||||
return False
|
||||
extractedRules['expiryTime'] = expirytime
|
||||
except:
|
||||
print('Error parsing expiry time')
|
||||
logger.info('Error parsing expiry time')
|
||||
return False
|
||||
|
||||
"""for rule in rulelist:
|
||||
@ -606,7 +607,7 @@ def extractAmount_rule(text):
|
||||
counter = 0
|
||||
value = None
|
||||
for idx, word in enumerate(textList):
|
||||
print(word)
|
||||
logger.info(word)
|
||||
try:
|
||||
result = float(word)
|
||||
if textList[idx + 1] in base_units:
|
||||
@ -618,7 +619,7 @@ def extractAmount_rule(text):
|
||||
except:
|
||||
for unit in base_units:
|
||||
result = word.split(unit)
|
||||
print(result)
|
||||
logger.info(result)
|
||||
if len(result) == 2 and result[1] == '' and result[0] != '':
|
||||
try:
|
||||
value = float(result[0]) * base_units[unit]
|
||||
@ -838,12 +839,30 @@ text_list1 = [
|
||||
'''Create Smart Contract with the name India-elections-2019@ of the type one-time-event* using the asset rmt# at the address F7osBpjDDV1mSSnMNrLudEQQ3cwDJ2dPR1$ with contract-conditions: (1) contractAmount=0.001rmt (2) userChoices=Narendra Modi wins| Narendra Modi loses (3) expiryTime= Wed May 22 2019 21:00:00 GMT+0530'''
|
||||
]
|
||||
|
||||
def parse_flodata(text, blockinfo, config['DEFAULT']['NET']):
|
||||
if config['DEFAULT']['NET'] == 'testnet':
|
||||
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)
|
||||
|
||||
def parse_flodata(text, blockinfo, net):
|
||||
if net == 'testnet':
|
||||
is_testnet = True
|
||||
else:
|
||||
is_testnet = False
|
||||
|
||||
if text == '':
|
||||
return outputreturn('noise')
|
||||
|
||||
clean_text, processed_text = text_preprocessing(text)
|
||||
first_classification = firstclassification_rawstring(processed_text)
|
||||
parsed_data = None
|
||||
@ -1031,8 +1050,4 @@ def parse_flodata(text, blockinfo, config['DEFAULT']['NET']):
|
||||
return outputreturn('noise')
|
||||
return outputreturn('continuos-event-token-swap-incorporation', f"{contract_token}", f"{contract_name}", f"{contract_address}", f"{clean_text}", f"{contract_conditions['subtype']}", f"{contract_conditions['accepting_token']}", f"{contract_conditions['selling_token']}", f"{contract_conditions['priceType']}", f"{contract_conditions['price']}")
|
||||
|
||||
return outputreturn('noise')
|
||||
|
||||
|
||||
for text in text_list1:
|
||||
print(parse_flodata(text))
|
||||
return outputreturn('noise')
|
||||
23
sqlite_tests.py
Normal file
23
sqlite_tests.py
Normal file
@ -0,0 +1,23 @@
|
||||
from sqlalchemy import create_engine, func
|
||||
import pdb
|
||||
import os
|
||||
|
||||
def create_database_connection(type, parameters):
|
||||
if type == 'token':
|
||||
engine = create_engine(f"sqlite:///tokens/{parameters['token_name']}.db", echo=True)
|
||||
connection = engine.connect()
|
||||
return connection
|
||||
if type == 'smart_contract':
|
||||
pass
|
||||
|
||||
|
||||
def check_database_existence(type, parameters):
|
||||
if type == 'token':
|
||||
return os.path.isfile(f"./tokens/{parameters['token_name']}.db")
|
||||
|
||||
if type == 'smart_contract':
|
||||
pass
|
||||
|
||||
|
||||
connection = create_database_connection('token', {'token_name':"rupee"})
|
||||
print(check_database_existence('token', {'token_name':"rupee"}))
|
||||
File diff suppressed because it is too large
Load Diff
@ -70,13 +70,13 @@ def processBlock(blockindex=None, blockhash=None):
|
||||
for transaction in blockinfo["tx"]:
|
||||
counter = counter + 1
|
||||
logger.info(f"Transaction {counter} {transaction}")
|
||||
|
||||
current_index = -1
|
||||
while(current_index == -1):
|
||||
transaction_data = newMultiRequest(f"tx/{transaction}")
|
||||
try:
|
||||
text = transaction_data["floData"]
|
||||
text = text.replace("\n", " \n ")
|
||||
text = "create 1000 rmt#"
|
||||
current_index = 2
|
||||
except:
|
||||
logger.info("The API has passed the Block height test but failed transaction_data['floData'] test")
|
||||
@ -557,8 +557,21 @@ def checkReturnDeposits(blockinfo):
|
||||
pass
|
||||
|
||||
|
||||
def check_database_existance(type, parameters):
|
||||
pass
|
||||
def check_database_existence(type, parameters):
|
||||
if type == 'token':
|
||||
return os.path.isfile(f"./tokens/{parameters['token_name']}.db")
|
||||
|
||||
if type == 'smart_contract':
|
||||
pass
|
||||
|
||||
|
||||
def create_database_connection(type, parameters):
|
||||
if type == 'token':
|
||||
engine = create_engine(f"sqlite:///tokens/{parameters['token_name']}.db", echo=True)
|
||||
connection = engine.connect()
|
||||
return connection
|
||||
if type == 'smart_contract':
|
||||
pass
|
||||
|
||||
|
||||
def processTransaction(transaction_data, parsed_data):
|
||||
@ -579,6 +592,8 @@ def processTransaction(transaction_data, parsed_data):
|
||||
|
||||
# todo Rule 39 - Create a list of vins for a given transaction id
|
||||
for obj in transaction_data["vin"]:
|
||||
if 'coinbase' in obj.keys():
|
||||
return 0
|
||||
querylist.append([obj["txid"], obj["vout"]])
|
||||
|
||||
totalinputval = 0
|
||||
@ -627,8 +642,7 @@ def processTransaction(transaction_data, parsed_data):
|
||||
if addresscounter == inputcounter:
|
||||
outputlist = [inputlist[0]]
|
||||
elif len(outputlist) != 1:
|
||||
logger.info(
|
||||
f"Transaction's change is not coming back to the input address. Transaction {transaction_data['txid']} is rejected")
|
||||
logger.info(f"Transaction's change is not coming back to the input address. Transaction {transaction_data['txid']} is rejected")
|
||||
return 0
|
||||
else:
|
||||
outputlist = outputlist[0]
|
||||
@ -646,10 +660,9 @@ def processTransaction(transaction_data, parsed_data):
|
||||
# todo Rule 45 - If the transfer type is token, then call the function transferToken to adjust the balances
|
||||
if parsed_data['transferType'] == 'token':
|
||||
# check if the token exists in the database
|
||||
if os.path.isfile(f"./tokens/{parsed_data['tokenIdentification']}.db"):
|
||||
if check_database_existence('token', {'token_name':f"{parsed_data['tokenIdentification']}"}):
|
||||
# Check if the transaction hash already exists in the token db
|
||||
engine = create_engine(f"sqlite:///tokens/{parsed_data['tokenIdentification']}.db", echo=True)
|
||||
connection = engine.connect()
|
||||
connection = create_database_connection('token', {'token_name':f"{create_database_connection}"})
|
||||
blockno_txhash = connection.execute('select blockNumber, transactionHash from transactionHistory').fetchall()
|
||||
connection.close()
|
||||
blockno_txhash_T = list(zip(*blockno_txhash))
|
||||
@ -825,8 +838,7 @@ def processTransaction(transaction_data, parsed_data):
|
||||
SystemBase.metadata.create_all(bind=engine)
|
||||
session = sessionmaker(bind=engine)()
|
||||
blockchainReference = neturl + 'tx/' + transaction_data['txid']
|
||||
session.add(
|
||||
RejectedContractTransactionHistory(transactionType='participation',
|
||||
session.add(RejectedContractTransactionHistory(transactionType='participation',
|
||||
contractName=parsed_data['contractName'],
|
||||
contractAddress=outputlist[0],
|
||||
sourceFloAddress=inputadd,
|
||||
@ -839,7 +851,6 @@ def processTransaction(transaction_data, parsed_data):
|
||||
blockchainReference=blockchainReference,
|
||||
jsonData=json.dumps(transaction_data),
|
||||
rejectComment=f"Transaction {transaction_data['txid']} rejected as Smart contract {parsed_data['contractName']}-{outputlist[0]} has expired and will not accept any user participation",
|
||||
|
||||
parsedFloData=json.dumps(parsed_data)
|
||||
))
|
||||
session.commit()
|
||||
@ -2589,7 +2600,7 @@ def scanBlockchain():
|
||||
break
|
||||
|
||||
for blockindex in range(startblock, current_index):
|
||||
processBlock(blockindex=blockindex)
|
||||
processBlock(blockindex=blockindex)
|
||||
|
||||
# At this point the script has updated to the latest block
|
||||
# Now we connect to flosight's websocket API to get information about the latest blocks
|
||||
|
||||
Loading…
Reference in New Issue
Block a user