Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

289 implement eth get storage at #298

Merged
merged 6 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 12 additions & 1 deletion proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -195,6 +195,17 @@ 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":
print(f"Block type '{block_identifier}' is not supported yet")
raise RuntimeError("Not supported block")
value = neon_cli().call('get-ether-storage-at', account, position)
print(f"eth_getStorageAt >> '{value}'")
return value

def eth_getBlockByHash(self, trx_hash, full):
"""Returns information about a block by hash.
trx_hash - Hash of a block.
Expand Down
16 changes: 16 additions & 0 deletions proxy/test_eth_sendRawTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,22 @@ 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)
value_received = proxy.eth.get_storage_at(self.storage_contract.address, 0, "latest")
print('eth_getStorageAt return:', value_received.hex())
self.assertEqual(int.from_bytes(value_received, byteorder='big'), value_to_store)


if __name__ == '__main__':
unittest.main()