Renaming of Smart Contract Incorporation variables
This commit is contained in:
parent
f0a13d39ae
commit
e80f5923b3
42
parsing.py
42
parsing.py
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
import arrow
|
||||||
|
|
||||||
marker = None
|
marker = None
|
||||||
operation = None
|
operation = None
|
||||||
@ -120,7 +121,7 @@ def extractAddress(text):
|
|||||||
|
|
||||||
|
|
||||||
def extractContractType(text):
|
def extractContractType(text):
|
||||||
operationList = ['betting*'] # keep everything lowercase
|
operationList = ['one-time-event*'] # keep everything lowercase
|
||||||
count = 0
|
count = 0
|
||||||
returnval = None
|
returnval = None
|
||||||
for operation in operationList:
|
for operation in operationList:
|
||||||
@ -143,30 +144,33 @@ def extractContractCondition(text):
|
|||||||
def extractContractConditions(text, contracttype, marker):
|
def extractContractConditions(text, contracttype, marker):
|
||||||
rulestext = re.split('contractconditions:\s*', text)[-1]
|
rulestext = re.split('contractconditions:\s*', text)[-1]
|
||||||
rulelist = re.split('\d\.\s*', rulestext)
|
rulelist = re.split('\d\.\s*', rulestext)
|
||||||
if contracttype == 'betting*':
|
if contracttype == 'one-time-event*':
|
||||||
extractedRules = {}
|
extractedRules = {}
|
||||||
for rule in rulelist:
|
for rule in rulelist:
|
||||||
if rule=='':
|
if rule=='':
|
||||||
continue
|
continue
|
||||||
elif rule[:19]=='userassetcommitment':
|
elif rule[:14]=='contractamount':
|
||||||
pattern = re.compile('[^userassetcommitment="].*[^"]')
|
pattern = re.compile('[^contractamount=].*')
|
||||||
searchResult = pattern.search(rule).group(0)
|
searchResult = pattern.search(rule).group(0)
|
||||||
extractedRules['userassetcommitment'] = searchResult.split(marker)[0]
|
contractamount = searchResult.split(marker)[0]
|
||||||
elif rule[:17]=='smartcontractpays':
|
try:
|
||||||
conditions = rule.split('smartcontractpays=')[1]
|
extractedRules['contractamount'] = float(contractamount)
|
||||||
if conditions[0]=='"' or conditions[0]=="'" or conditions[-1]=='"' or conditions[-1]=="'":
|
except:
|
||||||
conditionlist = conditions[1:-1].split('|')
|
print("something is wrong with userchoices conditions")
|
||||||
extractedRules['smartcontractpays'] = {}
|
elif rule[:11]=='userchoices':
|
||||||
for idx, condition in enumerate(conditionlist):
|
conditions = rule.split('userchoices=')[1]
|
||||||
extractedRules['smartcontractpays'][idx] = condition.strip()
|
conditionlist = conditions.split('|')
|
||||||
|
extractedRules['userchoices'] = {}
|
||||||
|
for idx, condition in enumerate(conditionlist):
|
||||||
|
extractedRules['userchoices'][idx] = condition.strip()
|
||||||
else:
|
else:
|
||||||
print("something is wrong with smartcontractpays conditions")
|
print("something is wrong with userchoices conditions")
|
||||||
elif rule[:10]=='expirytime':
|
elif rule[:10]=='expirytime':
|
||||||
pattern = re.compile('[^expirytime="].*[^"]')
|
pattern = re.compile('[^expirytime=].*')
|
||||||
searchResult = pattern.search(rule).group(0)
|
searchResult = pattern.search(rule).group(0)
|
||||||
extractedRules['expirytime'] = searchResult
|
extractedRules['expirytime'] = searchResult
|
||||||
|
|
||||||
if 'userassetcommitment' in extractedRules and 'smartcontractpays' in extractedRules:
|
if 'contractamount' in extractedRules and 'userchoices' in extractedRules and 'expirytime' in extractedRules:
|
||||||
return extractedRules
|
return extractedRules
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
@ -256,7 +260,7 @@ def parse_flodata(string):
|
|||||||
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, 'betting*', marker)
|
contractconditions = extractContractConditions(cleanstring, 'one-time-event*', marker=hashList[0][:-1])
|
||||||
|
|
||||||
if None not in [contracttype, contractaddress, contractconditions]:
|
if None not in [contracttype, contractaddress, contractconditions]:
|
||||||
parsed_data = {'type': 'smartContractIncorporation', 'contractType': contracttype[:-1],
|
parsed_data = {'type': 'smartContractIncorporation', 'contractType': contracttype[:-1],
|
||||||
@ -293,3 +297,9 @@ def parse_flodata(string):
|
|||||||
parsed_data = {'type': 'noise'}
|
parsed_data = {'type': 'noise'}
|
||||||
|
|
||||||
return parsed_data
|
return parsed_data
|
||||||
|
|
||||||
|
|
||||||
|
flodata = 'Create Smart Contract with the name elections@ of the type one-time-event* using the asset rmt# at the address FLO Address$ with contractconditions: 1. contractAmount=5rmt 2. userchoices=NAMO=WIN | NAMO=LOSE 3. expirytime= Tue May 21 2019 18:55:00 GMT+0530'
|
||||||
|
|
||||||
|
parsed_flodata = parse_flodata(flodata)
|
||||||
|
print(parsed_flodata)
|
||||||
@ -293,8 +293,8 @@ def startWorking(transaction_data, parsed_data):
|
|||||||
elif parsed_data['type'] == 'smartContractIncorporation':
|
elif parsed_data['type'] == 'smartContractIncorporation':
|
||||||
if not os.path.isfile('./smartContracts/{}.db'.format(parsed_data['contractName'])):
|
if not os.path.isfile('./smartContracts/{}.db'.format(parsed_data['contractName'])):
|
||||||
# todo Rule 49 - If the contract name hasn't been taken before, check if the contract type is an authorized type by the system
|
# todo Rule 49 - If the contract name hasn't been taken before, check if the contract type is an authorized type by the system
|
||||||
if parsed_data['contractType'] == 'betting':
|
if parsed_data['contractType'] == 'one-time-event':
|
||||||
print("Smart contract is of the type betting")
|
print("Smart contract is of the type one-time-event")
|
||||||
# todo Rule 50 - Contract address mentioned in flodata field should be same as the receiver FLO address on the output side
|
# todo Rule 50 - Contract address mentioned in flodata field should be same as the receiver FLO address on the output side
|
||||||
# henceforth we will not consider any flo private key initiated comment as valid from this address
|
# henceforth we will not consider any flo private key initiated comment as valid from this address
|
||||||
# Unlocking can only be done through smart contract system address
|
# Unlocking can only be done through smart contract system address
|
||||||
@ -313,8 +313,11 @@ def startWorking(transaction_data, parsed_data):
|
|||||||
ContractStructure(attribute='flodata', index=0,
|
ContractStructure(attribute='flodata', index=0,
|
||||||
value=parsed_data['flodata']))
|
value=parsed_data['flodata']))
|
||||||
session.add(
|
session.add(
|
||||||
ContractStructure(attribute='userassetcommitment', index=0,
|
ContractStructure(attribute='contractamount', index=0,
|
||||||
value=parsed_data['contractConditions']['userassetcommitment'].split(parsed_data['tokenIdentification'][:-1])[0]))
|
value=parsed_data['contractConditions']['contractamount'].split(parsed_data['tokenIdentification'][:-1])[0]))
|
||||||
|
session.add(
|
||||||
|
ContractStructure(attribute='expirytime', index=0,
|
||||||
|
value=parsed_data['contractConditions']['expirytime']))
|
||||||
for key, value in parsed_data['contractConditions']['smartcontractpays'].items():
|
for key, value in parsed_data['contractConditions']['smartcontractpays'].items():
|
||||||
session.add(ContractStructure(attribute='exitconditions', index=key, value=value))
|
session.add(ContractStructure(attribute='exitconditions', index=key, value=value))
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user