Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Add pending state
  • Loading branch information
afalaleev committed Apr 3, 2022
commit 763b351b45a77c17543bf4a11e987786e49f847d
16 changes: 8 additions & 8 deletions proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def __repr__(self):
return str(self.__dict__)

def _process_block_tag(self, tag) -> SolanaBlockInfo:
if tag == "latest":
if tag in ("latest", "pending"):
block = self._db.get_latest_block()
elif tag in ('earliest', 'pending'):
elif tag in ('earliest'):
raise EthereumError(message=f"invalid tag {tag}")
elif isinstance(tag, str):
try:
Expand Down Expand Up @@ -161,7 +161,7 @@ def eth_getBalance(self, account, tag) -> str:
"""account - address to check for balance.
tag - integer block number, or the string "latest", "earliest" or "pending"
"""
if tag != "latest":
if tag not in ("latest", "pending"):
self.debug(f"Block type '{tag}' is not supported yet")
raise EthereumError(message=f"Not supported block identifier: {tag}")

Expand Down Expand Up @@ -192,7 +192,7 @@ def to_list(items):

if 'fromBlock' in obj and obj['fromBlock'] != '0':
from_block = self._process_block_tag(obj['fromBlock']).slot
if 'toBlock' in obj and obj['toBlock'] != 'latest':
if 'toBlock' in obj and obj['toBlock'] not in ('latest', 'pending'):
to_block = self._process_block_tag(obj['toBlock']).slot
if 'address' in obj:
addresses = to_list(obj['address'])
Expand Down Expand Up @@ -241,7 +241,7 @@ def eth_getStorageAt(self, account, position, block_identifier):
'''Retrieves storage data by given position
Currently supports only 'latest' block
'''
if block_identifier != "latest":
if block_identifier not in ("latest", "pending"):
self.debug(f"Block type '{block_identifier}' is not supported yet")
raise EthereumError(message=f"Not supported block identifier: {block_identifier}")

Expand Down Expand Up @@ -288,7 +288,7 @@ def eth_getBlockByNumber(self, tag, full) -> Optional[dict]:
if block.slot is None:
self.debug(f"Not found block by number {tag}")
return None
ret = self._get_block_by_slot(block, full, tag == 'latest')
ret = self._get_block_by_slot(block, full, tag in ('latest', 'pending'))
return ret

def eth_call(self, obj, tag):
Expand All @@ -303,7 +303,7 @@ def eth_call(self, obj, tag):
data: DATA - (optional) Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI in the Solidity documentation
tag - integer block number, or the string "latest", "earliest" or "pending", see the default block parameter
"""
if tag != "latest":
if tag not in ("latest", "pending"):
self.debug(f"Block type '{tag}' is not supported yet")
raise EthereumError(message=f"Not supported block identifier: {tag}")

Expand All @@ -321,7 +321,7 @@ def eth_call(self, obj, tag):
raise

def eth_getTransactionCount(self, account, tag):
if tag != "latest":
if tag not in ("latest", "pending"):
self.debug(f"Block type '{tag}' is not supported yet")
raise EthereumError(message=f"Not supported block identifier: {tag}")

Expand Down