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
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.route('/getmarkerlist')
def marker_list():
dblist = os.listdir("databases/")
@ -15,4 +19,5 @@ def marker_list():
return jsonify(dbdict)
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 import Column, Integer, Float, String, ForeignKey
Base = declarative_base()
ContractBase = declarative_base()
SystemBase = declarative_base()
LatestCacheBase = declarative_base()
class ActiveTable(Base):
__tablename__ = "activeTable"
@ -54,6 +55,8 @@ class TransactionHistory(Base):
transactionHash = Column('transactionHash', String)
blockchainReference = Column('blockchainReference', String)
jsonData = Column('jsonData', String)
transactionType = Column('transactionType', String)
parsedFloData = Column('parsedFloData', String)
class TokenContractAssociation(Base):
@ -69,7 +72,8 @@ class TokenContractAssociation(Base):
transactionHash = Column('transactionHash', String)
blockchainReference = Column('blockchainReference', String)
jsonData = Column('jsonData', String)
transactionType = Column('transactionType', String)
parsedFloData = Column('parsedFloData', String)
class ContractStructure(ContractBase):
@ -109,6 +113,7 @@ class ContractTransactionHistory(ContractBase):
transactionHash = Column('transactionHash', String)
blockchainReference = Column('blockchainReference', String)
jsonData = Column('jsonData', String)
parsedFloData = Column('parsedFloData', String)
class RejectedContractTransactionHistory(SystemBase):
@ -129,6 +134,8 @@ class RejectedContractTransactionHistory(SystemBase):
blockchainReference = Column('blockchainReference', String)
jsonData = Column('jsonData', String)
rejectComment = Column('rejectComment', String)
parsedFloData = Column('parsedFloData', String)
class RejectedTransactionHistory(SystemBase):
__tablename__ = "rejectedTransactionHistory"
@ -145,6 +152,8 @@ class RejectedTransactionHistory(SystemBase):
blockchainReference = Column('blockchainReference', String)
jsonData = Column('jsonData', String)
rejectComment = Column('rejectComment', String)
transactionType = Column('transactionType', String)
parsedFloData = Column('parsedFloData', String)
class ActiveContracts(SystemBase):
@ -171,6 +180,7 @@ class SystemData(SystemBase):
attribute = Column('attribute', String)
value = Column('value', String)
class ContractAddressMapping(SystemBase):
__tablename__ = "contractAddressMapping"
@ -184,6 +194,7 @@ class ContractAddressMapping(SystemBase):
blockNumber = Column('blockNumber', Integer)
blockHash = Column('blockHash', String)
class TokenAddressMapping(SystemBase):
__tablename__ = "tokenAddressMapping"
@ -194,6 +205,7 @@ class TokenAddressMapping(SystemBase):
blockNumber = Column('blockNumber', Integer)
blockHash = Column('blockHash', String)
class LatestTransactions(LatestCacheBase):
__tablename__ = "latestTransactions"
id = Column('id', Integer, primary_key=True)
@ -203,11 +215,10 @@ class LatestTransactions(LatestCacheBase):
transactionType = Column('transactionType', String)
parsedFloData = Column('parsedFloData', String)
class LatestBlocks(LatestCacheBase):
__tablename__ = "latestBlocks"
id = Column('id', Integer, primary_key=True)
blockNumber = Column('blockNumber', String)
blockHash = Column('blockHash', String)
jsonData = Column('jsonData', String)

View File

@ -1,6 +1,7 @@
import re
import arrow
import configparser
import re
import arrow
config = configparser.ConfigParser()
config.read('config.ini')
@ -10,22 +11,22 @@ operation = None
address = None
amount = None
months = { 'jan' : 1,
'feb' : 2,
'mar' : 3,
'apr' : 4,
'may' : 5,
'jun' : 6,
'jul' : 7,
'aug' : 8,
'sep' : 9,
'oct' : 10,
'nov' : 11,
'dec' : 12 }
months = {'jan': 1,
'feb': 2,
'mar': 3,
'apr': 4,
'may': 5,
'jun': 6,
'jul': 7,
'aug': 8,
'sep': 9,
'oct': 10,
'nov': 11,
'dec': 12}
def isTransfer(text):
wordlist = ['transfer','send','give'] # keep everything lowercase
wordlist = ['transfer', 'send', 'give'] # keep everything lowercase
textList = text.split(' ')
for word in wordlist:
if word in textList:
@ -34,7 +35,7 @@ def isTransfer(text):
def isIncorp(text):
wordlist = ['incorporate','create','start'] # keep everything lowercase
wordlist = ['incorporate', 'create', 'start'] # keep everything lowercase
textList = text.split(' ')
for word in wordlist:
if word in textList:
@ -62,7 +63,7 @@ def isSmartContractPay(text):
smartContractName = smartContractName[:-1]
if smartContractTrigger and smartContractName:
contractconditions = { 'smartContractTrigger':smartContractTrigger, 'smartContractName':smartContractName }
contractconditions = {'smartContractTrigger': smartContractTrigger, 'smartContractName': smartContractName}
return contractconditions
else:
return False
@ -98,11 +99,11 @@ def extractMarker(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(' ')
counter = 0
value = None
for idx,word in enumerate(textList):
for idx, word in enumerate(textList):
try:
result = float(word)
if textList[idx + 1] in base_units:
@ -114,9 +115,9 @@ def extractInitTokens(text):
except:
for unit in base_units:
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:
value = float(result[0])*base_units[unit]
value = float(result[0]) * base_units[unit]
counter = counter + 1
except:
continue
@ -152,7 +153,7 @@ def extractContractType(text):
def extractUserchoice(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("'")
else:
return None
@ -164,7 +165,7 @@ def brackets_toNumber(item):
def extractContractConditions(text, contracttype, marker, blocktime):
rulestext = re.split('contract-conditions:\s*', text)[-1]
#rulelist = re.split('\d\.\s*', rulestext)
# rulelist = re.split('\d\.\s*', rulestext)
rulelist = []
numberList = re.findall(r'\(\d\d*\)', rulestext)
@ -180,7 +181,7 @@ def extractContractConditions(text, contracttype, marker, blocktime):
break
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())
if contracttype == 'one-time-event*':
@ -194,11 +195,13 @@ def extractContractConditions(text, contracttype, marker, blocktime):
try:
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])
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 ')
print(
'Expirytime of the contract is earlier than the block it is incorporated in. This incorporation will be rejected ')
return None
extractedRules['expiryTime'] = expirytime
except:
@ -206,7 +209,7 @@ def extractContractConditions(text, contracttype, marker, blocktime):
return None
for rule in rulelist:
if rule=='':
if rule == '':
continue
elif rule[:14] == 'contractamount':
pattern = re.compile('[^contractamount\s*=\s*].*')
@ -245,8 +248,7 @@ def extractContractConditions(text, contracttype, marker, blocktime):
payeeAddress = searchResult.split(marker)[0]
extractedRules['payeeAddress'] = payeeAddress
if len(extractedRules)>1 and 'expiryTime' in extractedRules:
if len(extractedRules) > 1 and 'expiryTime' in extractedRules:
return extractedRules
else:
return None
@ -263,7 +265,6 @@ def extractTriggerCondition(text):
# Combine test
def parse_flodata(string, blockinfo, netvariable):
# todo Rule 20 - remove 'text:' from the start of flodata if it exists
if string[0:5] == 'text:':
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.a - If a transaction is rejected, it means parsed_data type is noise
# 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'}
# 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
incorporation = isIncorp(cleanstring)
transfer = isTransfer(cleanstring)
@ -336,7 +337,8 @@ def parse_flodata(string, blockinfo, netvariable):
elif incorporation and not transfer:
contracttype = extractContractType(cleanstring)
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 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
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
# todo Rule 37 - Extract the trigger condition given by the committee. If its missing, reject
triggerCondition = extractTriggerCondition(cleanstring)
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:
parsed_data = {'type': 'noise'}
else:

File diff suppressed because it is too large Load Diff