Added check to stop users from making contracts on an address which has/had tokens before

This commit is contained in:
Vivek Teega 2023-05-01 17:10:09 +00:00
parent 355364badb
commit dce543284c

View File

@ -1217,11 +1217,6 @@ def processTransaction(transaction_data, parsed_data, blockinfo):
# Check if the swap amount is available in the deposits of the selling token # Check if the swap amount is available in the deposits of the selling token
# if yes do the transfers, otherwise reject the transaction # if yes do the transfers, otherwise reject the transaction
# #
'''active_contract_deposits = contract_session.query(ContractDeposits).filter(ContractDeposits.status=='active').all()
SELECT * FROM contractdeposits WHERE id IN ( SELECT MAX(id) FROM contractdeposits GROUP BY transactionHash) AND status = 'active' AND status != 'deposit-return';'''
'''SELECT MAX(id) FROM contractdeposits GROUP BY transactionHash'''
subquery = contract_session.query(func.max(ContractDeposits.id)).group_by(ContractDeposits.transactionHash) subquery = contract_session.query(func.max(ContractDeposits.id)).group_by(ContractDeposits.transactionHash)
active_contract_deposits = contract_session.query(ContractDeposits).filter(ContractDeposits.id.in_(subquery)).filter(ContractDeposits.status != 'deposit-return').filter(ContractDeposits.status != 'consumed').filter(ContractDeposits.status == 'active').all() active_contract_deposits = contract_session.query(ContractDeposits).filter(ContractDeposits.id.in_(subquery)).filter(ContractDeposits.status != 'deposit-return').filter(ContractDeposits.status != 'consumed').filter(ContractDeposits.status == 'active').all()
@ -1233,15 +1228,6 @@ def processTransaction(transaction_data, parsed_data, blockinfo):
else: else:
available_deposit_sum = float(available_deposit_sum[0][0]) available_deposit_sum = float(available_deposit_sum[0][0])
'''consumed_deposit_ids = contract_session.query(ConsumedInfo.id_deposittable).all()
available_deposit_sum = 0
for entry in active_contract_deposits:
if entry.id in [consumed_deposit_ids] or arrow.get(entry.unix_expiryTime)<arrow.get(blockinfo['time']):
index = active_contract_deposits.index(entry)
del available_deposits[index]
else:
available_deposit_sum = available_deposit_sum + entry.depositBalance'''
if available_deposit_sum >= swapAmount: if available_deposit_sum >= swapAmount:
# accepting token transfer from participant to smart contract address # accepting token transfer from participant to smart contract address
returnval = transferToken(parsed_data['tokenIdentification'], parsed_data['tokenAmount'], inputlist[0], outputlist[0], transaction_data=transaction_data, parsed_data=parsed_data, isInfiniteToken=None, blockinfo=blockinfo) returnval = transferToken(parsed_data['tokenIdentification'], parsed_data['tokenAmount'], inputlist[0], outputlist[0], transaction_data=transaction_data, parsed_data=parsed_data, isInfiniteToken=None, blockinfo=blockinfo)
@ -1475,6 +1461,10 @@ def processTransaction(transaction_data, parsed_data, blockinfo):
# if it has been taken then reject the incorporation. # if it has been taken then reject the incorporation.
elif parsed_data['type'] == 'smartContractIncorporation': elif parsed_data['type'] == 'smartContractIncorporation':
if not check_database_existence('smart_contract', {'contract_name':f"{parsed_data['contractName']}", 'contract_address':f"{parsed_data['contractAddress']}"}): if not check_database_existence('smart_contract', {'contract_name':f"{parsed_data['contractName']}", 'contract_address':f"{parsed_data['contractAddress']}"}):
# Cannot incorporate on an address with any previous token transaction
systemdb_session = create_database_session_orm('system_dbs', {'db_name':'system'}, SystemBase)
tokenAddressMapping_of_contractAddress = systemdb_session.query(TokenAddressMapping).filter(TokenAddressMapping.tokenAddress == parsed_data['contractAddress']).all()
if len(tokenAddressMapping_of_contractAddress) == 0:
# 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'] == 'one-time-event': if parsed_data['contractType'] == 'one-time-event':
logger.info("Smart contract is of the type one-time-event") logger.info("Smart contract is of the type one-time-event")
@ -1712,6 +1702,13 @@ def processTransaction(transaction_data, parsed_data, blockinfo):
delete_contract_database({'contract_name': parsed_data['contractName'], 'contract_address': parsed_data['contractAddress']}) delete_contract_database({'contract_name': parsed_data['contractName'], 'contract_address': parsed_data['contractAddress']})
return 0 return 0
else:
rejectComment = f"Smart contract creation transaction {transaction_data['txid']} rejected as token transactions already exist on the address {parsed_data['contractAddress']}"
logger.info(rejectComment)
rejected_contract_transaction_history(transaction_data, parsed_data, 'incorporation', inputadd, inputadd, outputlist[0], rejectComment)
delete_contract_database({'contract_name': parsed_data['contractName'], 'contract_address': parsed_data['contractAddress']})
return 0
else: else:
rejectComment = f"Transaction {transaction_data['txid']} rejected as a Smart Contract with the name {parsed_data['contractName']} at address {parsed_data['contractAddress']} already exists" rejectComment = f"Transaction {transaction_data['txid']} rejected as a Smart Contract with the name {parsed_data['contractName']} at address {parsed_data['contractAddress']} already exists"
logger.info(rejectComment) logger.info(rejectComment)
@ -1953,11 +1950,6 @@ def processTransaction(transaction_data, parsed_data, blockinfo):
# Push the deposit transaction into deposit database contract database # Push the deposit transaction into deposit database contract database
session = create_database_session_orm('smart_contract', {'contract_name': f"{parsed_data['contractName']}", 'contract_address': f"{outputlist[0]}"}, ContractBase) session = create_database_session_orm('smart_contract', {'contract_name': f"{parsed_data['contractName']}", 'contract_address': f"{outputlist[0]}"}, ContractBase)
blockchainReference = neturl + 'tx/' + transaction_data['txid'] blockchainReference = neturl + 'tx/' + transaction_data['txid']
'''old_depositBalance = session.query(ContractDeposits.depositBalance).order_by(ContractDeposits.id.desc()).first()
if old_depositBalance is None:
old_depositBalance = 0
else:
old_depositBalance = old_depositBalance[0]'''
session.add(ContractDeposits(depositorAddress = inputadd, depositAmount = parsed_data['depositAmount'], depositBalance = parsed_data['depositAmount'], expiryTime = parsed_data['depositConditions']['expiryTime'], unix_expiryTime = convert_datetime_to_arrowobject(parsed_data['depositConditions']['expiryTime']).timestamp(), status = 'active', transactionHash = transaction_data['txid'], blockNumber = transaction_data['blockheight'], blockHash = transaction_data['blockhash'])) session.add(ContractDeposits(depositorAddress = inputadd, depositAmount = parsed_data['depositAmount'], depositBalance = parsed_data['depositAmount'], expiryTime = parsed_data['depositConditions']['expiryTime'], unix_expiryTime = convert_datetime_to_arrowobject(parsed_data['depositConditions']['expiryTime']).timestamp(), status = 'active', transactionHash = transaction_data['txid'], blockNumber = transaction_data['blockheight'], blockHash = transaction_data['blockhash']))
session.add(ContractTransactionHistory(transactionType = 'smartContractDeposit', session.add(ContractTransactionHistory(transactionType = 'smartContractDeposit',
transactionSubType = None, transactionSubType = None,