diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index 54a19ecf4..ba0b1fb45 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -34,7 +34,7 @@ import os from ..indexer.utils import get_trx_results, LogDB from ..indexer.sql_dict import SQLDict -from proxy.environment import evm_loader_id, solana_cli, solana_url +from proxy.environment import evm_loader_id, solana_cli, solana_url, neon_cli logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) @@ -195,6 +195,21 @@ def getBlockBySlot(self, slot, full): } return ret + def eth_getStorageAt(self, account, position, block_identifier): + '''Retrieves storage data by given position + Currently supports only 'latest' block + ''' + if block_identifier != "latest": + logger.debug(f"Block type '{block_identifier}' is not supported yet") + raise RuntimeError(f"Not supported block identifier: {block_identifier}") + + try: + value = neon_cli().call('get-storage-at', account, position) + return value + except Exception as err: + logger.debug(f"Neon-cli failed to execute: {err}") + return '0x00' + def eth_getBlockByHash(self, trx_hash, full): """Returns information about a block by hash. trx_hash - Hash of a block. diff --git a/proxy/test_eth_sendRawTransaction.py b/proxy/test_eth_sendRawTransaction.py index 35ac90651..12e3f4633 100644 --- a/proxy/test_eth_sendRawTransaction.py +++ b/proxy/test_eth_sendRawTransaction.py @@ -428,6 +428,38 @@ def test_07_execute_long_transaction(self): print('times_to_calculate:', times_to_calculate) print('time_duration:', time_duration) + def test_get_storage_at(self): + print("\nhttps://github.com/neonlabsorg/proxy-model.py/issues/289") + right_nonce = proxy.eth.get_transaction_count(proxy.eth.default_account) + value_to_store = 452356 + trx_store = self.storage_contract.functions.store(value_to_store).buildTransaction({'nonce': right_nonce}) + print('trx_store:', trx_store) + trx_store_signed = proxy.eth.account.sign_transaction(trx_store, eth_account.key) + print('trx_store_signed:', trx_store_signed) + trx_store_hash = proxy.eth.send_raw_transaction(trx_store_signed.rawTransaction) + print('trx_store_hash:', trx_store_hash.hex()) + trx_store_receipt = proxy.eth.wait_for_transaction_receipt(trx_store_hash) + print('trx_store_receipt:', trx_store_receipt) + + number_pos = 0 + value_received = proxy.eth.get_storage_at(self.storage_contract.address, number_pos, "latest") + print('eth_getStorageAt existing address and index => ', value_received.hex()) + self.assertEqual(int.from_bytes(value_received, byteorder='big'), value_to_store) + + non_existing_pos = 12 + value_received = proxy.eth.get_storage_at(self.storage_contract.address, non_existing_pos, "latest") + print('eth_getStorageAt existing address and non-existing index => ', value_received.hex()) + self.assertEqual(int.from_bytes(value_received, byteorder='big'), 0) + + non_exising_address = b'\xe1\xda\xb7\xa6\x17\x6f\x87\x68\xF5\x3a\x42\x5f\x29\x61\x73\x60\x5e\xd5\x08\x32' + value_received = proxy.eth.get_storage_at(non_exising_address, non_existing_pos, "latest") + print('eth_getStorageAt non-existing address => ', value_received.hex()) + self.assertEqual(int.from_bytes(value_received, byteorder='big'), 0) + + not_a_contract_address = proxy.eth.default_account + value_received = proxy.eth.get_storage_at(not_a_contract_address, 0, "latest") + print('eth_getStorageAt not_a_contract_address address => ', value_received.hex()) + self.assertEqual(int.from_bytes(value_received, byteorder='big'), 0) if __name__ == '__main__': unittest.main()