latest changes

This commit is contained in:
Vivek Teega 2020-01-29 23:19:20 +00:00
parent 3464a81a2d
commit ea5010fc4e
4 changed files with 413 additions and 240 deletions

7
app.py
View File

@ -1,11 +1,15 @@
from flask import Flask, render_template, jsonify
import os import os
from flask import Flask, jsonify
app = Flask(__name__) app = Flask(__name__)
@app.route('/') @app.route('/')
def hello_world(): def hello_world():
return 'Hello, World!' return 'Hello, World!'
@app.route('/getmarkerlist') @app.route('/getmarkerlist')
def marker_list(): def marker_list():
dblist = os.listdir("databases/") dblist = os.listdir("databases/")
@ -15,4 +19,5 @@ def marker_list():
return jsonify(dbdict) return jsonify(dbdict)
app.run(debug=True) app.run(debug=True)

View File

@ -1,11 +1,12 @@
from sqlalchemy import Column, Integer, Float, String
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, Float, String, ForeignKey
Base = declarative_base() Base = declarative_base()
ContractBase = declarative_base() ContractBase = declarative_base()
SystemBase = declarative_base() SystemBase = declarative_base()
LatestCacheBase = declarative_base() LatestCacheBase = declarative_base()
class ActiveTable(Base): class ActiveTable(Base):
__tablename__ = "activeTable" __tablename__ = "activeTable"
@ -54,6 +55,8 @@ class TransactionHistory(Base):
transactionHash = Column('transactionHash', String) transactionHash = Column('transactionHash', String)
blockchainReference = Column('blockchainReference', String) blockchainReference = Column('blockchainReference', String)
jsonData = Column('jsonData', String) jsonData = Column('jsonData', String)
transactionType = Column('transactionType', String)
parsedFloData = Column('parsedFloData', String)
class TokenContractAssociation(Base): class TokenContractAssociation(Base):
@ -69,7 +72,8 @@ class TokenContractAssociation(Base):
transactionHash = Column('transactionHash', String) transactionHash = Column('transactionHash', String)
blockchainReference = Column('blockchainReference', String) blockchainReference = Column('blockchainReference', String)
jsonData = Column('jsonData', String) jsonData = Column('jsonData', String)
transactionType = Column('transactionType', String)
parsedFloData = Column('parsedFloData', String)
class ContractStructure(ContractBase): class ContractStructure(ContractBase):
@ -109,6 +113,7 @@ class ContractTransactionHistory(ContractBase):
transactionHash = Column('transactionHash', String) transactionHash = Column('transactionHash', String)
blockchainReference = Column('blockchainReference', String) blockchainReference = Column('blockchainReference', String)
jsonData = Column('jsonData', String) jsonData = Column('jsonData', String)
parsedFloData = Column('parsedFloData', String)
class RejectedContractTransactionHistory(SystemBase): class RejectedContractTransactionHistory(SystemBase):
@ -129,6 +134,8 @@ class RejectedContractTransactionHistory(SystemBase):
blockchainReference = Column('blockchainReference', String) blockchainReference = Column('blockchainReference', String)
jsonData = Column('jsonData', String) jsonData = Column('jsonData', String)
rejectComment = Column('rejectComment', String) rejectComment = Column('rejectComment', String)
parsedFloData = Column('parsedFloData', String)
class RejectedTransactionHistory(SystemBase): class RejectedTransactionHistory(SystemBase):
__tablename__ = "rejectedTransactionHistory" __tablename__ = "rejectedTransactionHistory"
@ -145,6 +152,8 @@ class RejectedTransactionHistory(SystemBase):
blockchainReference = Column('blockchainReference', String) blockchainReference = Column('blockchainReference', String)
jsonData = Column('jsonData', String) jsonData = Column('jsonData', String)
rejectComment = Column('rejectComment', String) rejectComment = Column('rejectComment', String)
transactionType = Column('transactionType', String)
parsedFloData = Column('parsedFloData', String)
class ActiveContracts(SystemBase): class ActiveContracts(SystemBase):
@ -171,6 +180,7 @@ class SystemData(SystemBase):
attribute = Column('attribute', String) attribute = Column('attribute', String)
value = Column('value', String) value = Column('value', String)
class ContractAddressMapping(SystemBase): class ContractAddressMapping(SystemBase):
__tablename__ = "contractAddressMapping" __tablename__ = "contractAddressMapping"
@ -184,6 +194,7 @@ class ContractAddressMapping(SystemBase):
blockNumber = Column('blockNumber', Integer) blockNumber = Column('blockNumber', Integer)
blockHash = Column('blockHash', String) blockHash = Column('blockHash', String)
class TokenAddressMapping(SystemBase): class TokenAddressMapping(SystemBase):
__tablename__ = "tokenAddressMapping" __tablename__ = "tokenAddressMapping"
@ -194,6 +205,7 @@ class TokenAddressMapping(SystemBase):
blockNumber = Column('blockNumber', Integer) blockNumber = Column('blockNumber', Integer)
blockHash = Column('blockHash', String) blockHash = Column('blockHash', String)
class LatestTransactions(LatestCacheBase): class LatestTransactions(LatestCacheBase):
__tablename__ = "latestTransactions" __tablename__ = "latestTransactions"
id = Column('id', Integer, primary_key=True) id = Column('id', Integer, primary_key=True)
@ -203,11 +215,10 @@ class LatestTransactions(LatestCacheBase):
transactionType = Column('transactionType', String) transactionType = Column('transactionType', String)
parsedFloData = Column('parsedFloData', String) parsedFloData = Column('parsedFloData', String)
class LatestBlocks(LatestCacheBase): class LatestBlocks(LatestCacheBase):
__tablename__ = "latestBlocks" __tablename__ = "latestBlocks"
id = Column('id', Integer, primary_key=True) id = Column('id', Integer, primary_key=True)
blockNumber = Column('blockNumber', String) blockNumber = Column('blockNumber', String)
blockHash = Column('blockHash', String) blockHash = Column('blockHash', String)
jsonData = Column('jsonData', String) jsonData = Column('jsonData', String)

View File

@ -1,6 +1,7 @@
import re
import arrow
import configparser import configparser
import re
import arrow
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read('config.ini') config.read('config.ini')
@ -10,22 +11,22 @@ operation = None
address = None address = None
amount = None amount = None
months = { 'jan' : 1, months = {'jan': 1,
'feb' : 2, 'feb': 2,
'mar' : 3, 'mar': 3,
'apr' : 4, 'apr': 4,
'may' : 5, 'may': 5,
'jun' : 6, 'jun': 6,
'jul' : 7, 'jul': 7,
'aug' : 8, 'aug': 8,
'sep' : 9, 'sep': 9,
'oct' : 10, 'oct': 10,
'nov' : 11, 'nov': 11,
'dec' : 12 } 'dec': 12}
def isTransfer(text): def isTransfer(text):
wordlist = ['transfer','send','give'] # keep everything lowercase wordlist = ['transfer', 'send', 'give'] # keep everything lowercase
textList = text.split(' ') textList = text.split(' ')
for word in wordlist: for word in wordlist:
if word in textList: if word in textList:
@ -34,7 +35,7 @@ def isTransfer(text):
def isIncorp(text): def isIncorp(text):
wordlist = ['incorporate','create','start'] # keep everything lowercase wordlist = ['incorporate', 'create', 'start'] # keep everything lowercase
textList = text.split(' ') textList = text.split(' ')
for word in wordlist: for word in wordlist:
if word in textList: if word in textList:
@ -62,7 +63,7 @@ def isSmartContractPay(text):
smartContractName = smartContractName[:-1] smartContractName = smartContractName[:-1]
if smartContractTrigger and smartContractName: if smartContractTrigger and smartContractName:
contractconditions = { 'smartContractTrigger':smartContractTrigger, 'smartContractName':smartContractName } contractconditions = {'smartContractTrigger': smartContractTrigger, 'smartContractName': smartContractName}
return contractconditions return contractconditions
else: else:
return False return False
@ -98,11 +99,11 @@ def extractMarker(text):
def extractInitTokens(text): def extractInitTokens(text):
base_units = {'thousand':10**3 , 'million':10**6 ,'billion':10**9, 'trillion':10**12} base_units = {'thousand': 10 ** 3, 'million': 10 ** 6, 'billion': 10 ** 9, 'trillion': 10 ** 12}
textList = text.split(' ') textList = text.split(' ')
counter = 0 counter = 0
value = None value = None
for idx,word in enumerate(textList): for idx, word in enumerate(textList):
try: try:
result = float(word) result = float(word)
if textList[idx + 1] in base_units: if textList[idx + 1] in base_units:
@ -114,9 +115,9 @@ def extractInitTokens(text):
except: except:
for unit in base_units: for unit in base_units:
result = word.split(unit) result = word.split(unit)
if len(result) == 2 and result[1]=='' and result[0]!='': if len(result) == 2 and result[1] == '' and result[0] != '':
try: try:
value = float(result[0])*base_units[unit] value = float(result[0]) * base_units[unit]
counter = counter + 1 counter = counter + 1
except: except:
continue continue
@ -152,7 +153,7 @@ def extractContractType(text):
def extractUserchoice(text): def extractUserchoice(text):
result = re.split('userchoice:\s*', text) result = re.split('userchoice:\s*', text)
if len(result) != 1 and result[1]!='': if len(result) != 1 and result[1] != '':
return result[1].strip().strip('"').strip("'") return result[1].strip().strip('"').strip("'")
else: else:
return None return None
@ -164,7 +165,7 @@ def brackets_toNumber(item):
def extractContractConditions(text, contracttype, marker, blocktime): def extractContractConditions(text, contracttype, marker, blocktime):
rulestext = re.split('contract-conditions:\s*', text)[-1] rulestext = re.split('contract-conditions:\s*', text)[-1]
#rulelist = re.split('\d\.\s*', rulestext) # rulelist = re.split('\d\.\s*', rulestext)
rulelist = [] rulelist = []
numberList = re.findall(r'\(\d\d*\)', rulestext) numberList = re.findall(r'\(\d\d*\)', rulestext)
@ -180,7 +181,7 @@ def extractContractConditions(text, contracttype, marker, blocktime):
break break
for i in range(len(numberList)): for i in range(len(numberList)):
rule = rulestext.split('({})'.format(i+1))[1].split('({})'.format(i+2))[0] rule = rulestext.split('({})'.format(i + 1))[1].split('({})'.format(i + 2))[0]
rulelist.append(rule.strip()) rulelist.append(rule.strip())
if contracttype == 'one-time-event*': if contracttype == 'one-time-event*':
@ -194,11 +195,13 @@ def extractContractConditions(text, contracttype, marker, blocktime):
try: try:
expirytime_split = expirytime.split(' ') expirytime_split = expirytime.split(' ')
parse_string = '{}/{}/{} {}'.format(expirytime_split[3], months[expirytime_split[1]], expirytime_split[2], expirytime_split[4]) parse_string = '{}/{}/{} {}'.format(expirytime_split[3], months[expirytime_split[1]],
expirytime_split[2], expirytime_split[4])
expirytime_object = arrow.get(parse_string, 'YYYY/M/D HH:mm:ss').replace(tzinfo=expirytime_split[5]) expirytime_object = arrow.get(parse_string, 'YYYY/M/D HH:mm:ss').replace(tzinfo=expirytime_split[5])
blocktime_object = arrow.get(blocktime) blocktime_object = arrow.get(blocktime)
if expirytime_object < blocktime_object: if expirytime_object < blocktime_object:
print('Expirytime of the contract is earlier than the block it is incorporated in. This incorporation will be rejected ') print(
'Expirytime of the contract is earlier than the block it is incorporated in. This incorporation will be rejected ')
return None return None
extractedRules['expiryTime'] = expirytime extractedRules['expiryTime'] = expirytime
except: except:
@ -206,7 +209,7 @@ def extractContractConditions(text, contracttype, marker, blocktime):
return None return None
for rule in rulelist: for rule in rulelist:
if rule=='': if rule == '':
continue continue
elif rule[:14] == 'contractamount': elif rule[:14] == 'contractamount':
pattern = re.compile('[^contractamount\s*=\s*].*') pattern = re.compile('[^contractamount\s*=\s*].*')
@ -245,8 +248,7 @@ def extractContractConditions(text, contracttype, marker, blocktime):
payeeAddress = searchResult.split(marker)[0] payeeAddress = searchResult.split(marker)[0]
extractedRules['payeeAddress'] = payeeAddress extractedRules['payeeAddress'] = payeeAddress
if len(extractedRules) > 1 and 'expiryTime' in extractedRules:
if len(extractedRules)>1 and 'expiryTime' in extractedRules:
return extractedRules return extractedRules
else: else:
return None return None
@ -263,7 +265,6 @@ def extractTriggerCondition(text):
# Combine test # Combine test
def parse_flodata(string, blockinfo, netvariable): def parse_flodata(string, blockinfo, netvariable):
# todo Rule 20 - remove 'text:' from the start of flodata if it exists # todo Rule 20 - remove 'text:' from the start of flodata if it exists
if string[0:5] == 'text:': if string[0:5] == 'text:':
string = string.split('text:')[1] string = string.split('text:')[1]
@ -287,12 +288,12 @@ def parse_flodata(string, blockinfo, netvariable):
# todo Rule 25 - If number of # or number of @ is greater than 1, reject # todo Rule 25 - If number of # or number of @ is greater than 1, reject
# todo Rule 25.a - If a transaction is rejected, it means parsed_data type is noise # todo Rule 25.a - If a transaction is rejected, it means parsed_data type is noise
# Filter noise first - check if the words end with either @ or # # Filter noise first - check if the words end with either @ or #
if (len(atList)==0 and len(hashList)==0) or len(atList)>1 or len(hashList)>1: if (len(atList) == 0 and len(hashList) == 0) or len(atList) > 1 or len(hashList) > 1:
parsed_data = {'type': 'noise'} parsed_data = {'type': 'noise'}
# todo Rule 26 - if number of # is 1 and number of @ is 0, then check if its token creation or token transfer transaction # todo Rule 26 - if number of # is 1 and number of @ is 0, then check if its token creation or token transfer transaction
elif len(hashList)==1 and len(atList)==0: elif len(hashList) == 1 and len(atList) == 0:
# Passing the above check means token creation or transfer # Passing the above check means token creation or transfer
incorporation = isIncorp(cleanstring) incorporation = isIncorp(cleanstring)
transfer = isTransfer(cleanstring) transfer = isTransfer(cleanstring)
@ -336,7 +337,8 @@ def parse_flodata(string, blockinfo, netvariable):
elif incorporation and not transfer: elif incorporation and not transfer:
contracttype = extractContractType(cleanstring) contracttype = extractContractType(cleanstring)
contractaddress = extractAddress(nospacestring) contractaddress = extractAddress(nospacestring)
contractconditions = extractContractConditions(cleanstring, contracttype, marker=hashList[0][:-1], blocktime=blockinfo['time']) contractconditions = extractContractConditions(cleanstring, contracttype, marker=hashList[0][:-1],
blocktime=blockinfo['time'])
if config['DEFAULT']['NET'] == 'mainnet' and blockinfo['height'] < 3454510: if config['DEFAULT']['NET'] == 'mainnet' and blockinfo['height'] < 3454510:
if None not in [contracttype, contractconditions]: if None not in [contracttype, contractconditions]:
@ -373,12 +375,13 @@ def parse_flodata(string, blockinfo, netvariable):
# todo Rule 36 - Check for only a single @ and the substring "smart contract system says" in flodata, else reject # todo Rule 36 - Check for only a single @ and the substring "smart contract system says" in flodata, else reject
elif (len(hashList)==0 and len(atList)==1): elif (len(hashList) == 0 and len(atList) == 1):
# Passing the above check means Smart Contract pays | exitcondition triggered from the committee # Passing the above check means Smart Contract pays | exitcondition triggered from the committee
# todo Rule 37 - Extract the trigger condition given by the committee. If its missing, reject # todo Rule 37 - Extract the trigger condition given by the committee. If its missing, reject
triggerCondition = extractTriggerCondition(cleanstring) triggerCondition = extractTriggerCondition(cleanstring)
if triggerCondition is not None: if triggerCondition is not None:
parsed_data = {'type': 'smartContractPays', 'contractName': atList[0][:-1], 'triggerCondition': triggerCondition.group().strip()[1:-1]} parsed_data = {'type': 'smartContractPays', 'contractName': atList[0][:-1],
'triggerCondition': triggerCondition.group().strip()[1:-1]}
else: else:
parsed_data = {'type': 'noise'} parsed_data = {'type': 'noise'}
else: else:

File diff suppressed because it is too large Load Diff