Keeping a map of address's first associtiation with a token
This commit is contained in:
parent
d3e2357a08
commit
3ba6b95b72
@ -103,4 +103,12 @@ class ContractParticipantMapping(SystemBase):
|
|||||||
tokenAmount = Column('tokenAmount', Float)
|
tokenAmount = Column('tokenAmount', Float)
|
||||||
transactionHash = Column('transactionHash', String)
|
transactionHash = Column('transactionHash', String)
|
||||||
|
|
||||||
|
class TokenAddressMapping(SystemBase):
|
||||||
|
__tablename__ = "tokenAddressMapping"
|
||||||
|
|
||||||
|
id = Column('id', Integer, primary_key=True)
|
||||||
|
tokenAddress = Column('tokenAddress', String)
|
||||||
|
token = Column('token', String)
|
||||||
|
transactionHash = Column('transactionHash', String)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,9 @@ import pybtc
|
|||||||
|
|
||||||
|
|
||||||
def pushData_SSEapi(message):
|
def pushData_SSEapi(message):
|
||||||
url = 'https://ranchimallflo.duckdns.org/'
|
|
||||||
signature = pybtc.sign_message(message, privKey)
|
signature = pybtc.sign_message(message, privKey)
|
||||||
headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'Signature': signature}
|
headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'Signature': signature}
|
||||||
r = requests.post(url, json={'message': '{}'.format(message)}, headers=headers)
|
r = requests.post(sseAPI_url, json={'message': '{}'.format(message)}, headers=headers)
|
||||||
|
|
||||||
|
|
||||||
def transferToken(tokenIdentification, tokenAmount, inputAddress, outputAddress):
|
def transferToken(tokenIdentification, tokenAmount, inputAddress, outputAddress):
|
||||||
@ -401,11 +400,12 @@ def startWorking(transaction_data, parsed_data, blockinfo):
|
|||||||
connection = engine.connect()
|
connection = engine.connect()
|
||||||
|
|
||||||
blockno_txhash = connection.execute('select blockNumber, transactionHash from transactionHistory').fetchall()
|
blockno_txhash = connection.execute('select blockNumber, transactionHash from transactionHistory').fetchall()
|
||||||
|
connection.close()
|
||||||
blockno_txhash_T = list(zip(*blockno_txhash))
|
blockno_txhash_T = list(zip(*blockno_txhash))
|
||||||
|
|
||||||
if transaction_data['txid'] in list(blockno_txhash_T[1]):
|
if transaction_data['txid'] in list(blockno_txhash_T[1]):
|
||||||
print('Transaction {} already exists in the token db. This is unusual, please check your code'.format(transaction_data['txid']))
|
print('Transaction {} already exists in the token db. This is unusual, please check your code'.format(transaction_data['txid']))
|
||||||
pushData_SSEapi('Error | Transaction {} already exists in the token db. This is unusual, please check your code'.format(transaction_data['txid'])
|
pushData_SSEapi('Error | Transaction {} already exists in the token db. This is unusual, please check your code'.format(transaction_data['txid']))
|
||||||
return
|
return
|
||||||
|
|
||||||
returnval = transferToken(parsed_data['tokenIdentification'], parsed_data['tokenAmount'], inputlist[0], outputlist[0])
|
returnval = transferToken(parsed_data['tokenIdentification'], parsed_data['tokenAmount'], inputlist[0], outputlist[0])
|
||||||
@ -414,6 +414,17 @@ def startWorking(transaction_data, parsed_data, blockinfo):
|
|||||||
pushData_SSEapi('Error | Something went wrong while doing the internal db transactions for {}'.format(transaction_data['txid']))
|
pushData_SSEapi('Error | Something went wrong while doing the internal db transactions for {}'.format(transaction_data['txid']))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# If this is the first interaction of the outputlist's address with the given token name, add it to token mapping
|
||||||
|
engine = create_engine('sqlite:///system.db'.format(parsed_data['tokenIdentification']), echo=True)
|
||||||
|
connection = engine.connect()
|
||||||
|
firstInteractionCheck = connection.execute('select * from tokenAddressMapping where tokenAddress="{}" and token="{}"'.format(outputlist[0], parsed_data['tokenIdentification'])).fetchall()
|
||||||
|
|
||||||
|
if len(firstInteractionCheck) == 0:
|
||||||
|
connection.execute('INSERT INTO tokenAddressMapping [(tokenAddress, token, transactionHash)] VALUES ({}, {}, {});'.format(outputlist[0], parsed_data['tokenIdentification']))
|
||||||
|
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
# Pass information to SSE channel
|
# Pass information to SSE channel
|
||||||
url = 'https://ranchimallflo.duckdns.org/'
|
url = 'https://ranchimallflo.duckdns.org/'
|
||||||
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
|
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
|
||||||
@ -629,6 +640,15 @@ def startWorking(transaction_data, parsed_data, blockinfo):
|
|||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
|
# If this is the first interaction of the outputlist's address with the given token name, add it to token mapping
|
||||||
|
engine = create_engine('sqlite:///system.db'.format(parsed_data['tokenIdentification']), echo=True)
|
||||||
|
connection = engine.connect()
|
||||||
|
connection.execute(
|
||||||
|
'INSERT INTO tokenAddressMapping [(tokenAddress, token, transactionHash)] VALUES ({}, {}, {});'.format(
|
||||||
|
inputadd, parsed_data['tokenIdentification'], transaction_data['txid']))
|
||||||
|
|
||||||
|
connection.close()
|
||||||
|
|
||||||
pushData_SSEapi('Token | Succesfully incorporated token {} at transaction {}'.format(
|
pushData_SSEapi('Token | Succesfully incorporated token {} at transaction {}'.format(
|
||||||
parsed_data['tokenIdentification'], transaction_data['txid']))
|
parsed_data['tokenIdentification'], transaction_data['txid']))
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user