Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 43 additions & 35 deletions proxy/indexer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,50 +45,58 @@ def check_error(trx):


def get_trx_results(trx):
# init variables for instruction owner checks
accounts = trx["transaction"]["message"]["accountKeys"]
evm_loader_instructions = []
for idx, instruction in enumerate(trx["transaction"]["message"]["instructions"]):
if accounts[instruction["programIdIndex"]] == evm_loader_id:
evm_loader_instructions.append(idx)

slot = trx['slot']
block_number = hex(slot)
# block_hash = '0x%064x'%slot
got_result = False
logs = []
status = "0x1"
gas_used = 0
return_value = bytes
log_index = 0
for inner in (trx['meta']['innerInstructions']):
for event in inner['instructions']:
log = base58.b58decode(event['data'])
instruction = log[:1]
if (int().from_bytes(instruction, "little") == 7): # OnEvent evmInstruction code
address = log[1:21]
count_topics = int().from_bytes(log[21:29], 'little')
topics = []
pos = 29
for _ in range(count_topics):
topic_bin = log[pos:pos + 32]
topics.append('0x'+topic_bin.hex())
pos += 32
data = log[pos:]
rec = {
'address': '0x'+address.hex(),
'topics': topics,
'data': '0x'+data.hex(),
'transactionLogIndex': hex(0),
'transactionIndex': hex(inner['index']),
'blockNumber': block_number,
# 'transactionHash': trxId, # set when transaction found
'logIndex': hex(log_index),
# 'blockHash': block_hash # set when transaction found
}
logs.append(rec)
log_index +=1
elif int().from_bytes(instruction, "little") == 6: # OnReturn evmInstruction code
got_result = True
if log[1] < 0xd0:
status = "0x1"
else:
status = "0x0"
gas_used = int.from_bytes(log[2:10], 'little')
return_value = log[10:].hex()
if inner["index"] in evm_loader_instructions:
for event in inner['instructions']:
if accounts[event['programIdIndex']] == evm_loader_id:
log = base58.b58decode(event['data'])
instruction = log[:1]
if (int().from_bytes(instruction, "little") == 7): # OnEvent evmInstruction code
address = log[1:21]
count_topics = int().from_bytes(log[21:29], 'little')
topics = []
pos = 29
for _ in range(count_topics):
topic_bin = log[pos:pos + 32]
topics.append('0x'+topic_bin.hex())
pos += 32
data = log[pos:]
rec = {
'address': '0x'+address.hex(),
'topics': topics,
'data': '0x'+data.hex(),
'transactionLogIndex': hex(0),
'transactionIndex': hex(inner['index']),
'blockNumber': block_number,
# 'transactionHash': trxId, # set when transaction found
'logIndex': hex(log_index),
# 'blockHash': block_hash # set when transaction found
}
logs.append(rec)
log_index +=1
elif int().from_bytes(instruction, "little") == 6: # OnReturn evmInstruction code
got_result = True
if log[1] < 0xd0:
status = "0x1"
else:
status = "0x0"
gas_used = int.from_bytes(log[2:10], 'little')
return_value = log[10:].hex()

if got_result:
return (logs, status, gas_used, return_value, slot)
Expand Down
29 changes: 17 additions & 12 deletions proxy/plugin/solana_rest_api_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base58
import base64
import json
import logging
Expand Down Expand Up @@ -451,17 +452,21 @@ def check_if_program_exceeded_instructions(err_result):


def check_if_continue_returned(result):
acc_meta_lst = result["result"]["transaction"]["message"]["accountKeys"]
evm_loader_index = acc_meta_lst.index(evm_loader_id)

innerInstruction = result['result']['meta']['innerInstructions']
innerInstruction = next((i for i in innerInstruction if i["index"] == 0), None)
if (innerInstruction and innerInstruction['instructions']):
instruction = innerInstruction['instructions'][-1]
if (instruction['programIdIndex'] == evm_loader_index):
data = b58decode(instruction['data'])
if (data[0] == 6):
return (True, result['result']['transaction']['signatures'][0])
tx_info = result['result']
accounts = tx_info["transaction"]["message"]["accountKeys"]
evm_loader_instructions = []

for idx, instruction in enumerate(tx_info["transaction"]["message"]["instructions"]):
if accounts[instruction["programIdIndex"]] == evm_loader_id:
evm_loader_instructions.append(idx)

for inner in (tx_info['meta']['innerInstructions']):
if inner["index"] in evm_loader_instructions:
for event in inner['instructions']:
if accounts[event['programIdIndex']] == evm_loader_id:
instruction = base58.b58decode(event['data'])[:1]
if int().from_bytes(instruction, "little") == 6: # OnReturn evmInstruction code
return (True, tx_info['transaction']['signatures'][0])
return (False, ())


Expand Down Expand Up @@ -519,7 +524,7 @@ def call_continue_bucked(signer, client, perm_accs, trx_accs, steps):
else:
raise

logger.debug("Collect bucked results:")
logger.debug("Collect bucked results: {}".format(result_list))
for trx in result_list:
confirm_transaction(client, trx)
result = client.get_confirmed_transaction(trx)
Expand Down