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

#448 eth_getBlockByNumber returns latest transaction block #466

Merged
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
3 changes: 3 additions & 0 deletions proxy/indexer/blocks_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def get_block_by_height(self, block_num) -> SolanaBlockDBInfo:
return self._block_from_value(
self._fetchone(self._column_lst, [('height', block_num)], ['finalized desc']))

def get_latest_block_height(self) -> int:
return self._fetchone(['height'], [], ['height desc'])[0]

def set_block(self, block: SolanaBlockDBInfo):
cursor = self._conn.cursor()
cursor.execute(f'''
Expand Down
3 changes: 3 additions & 0 deletions proxy/indexer/indexer_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def get_last_block_slot(self):
def get_last_block_height(self):
return self._constants['last_block_height']

def get_latest_block_height(self):
return self._blocks_db.get_latest_block_height()

def set_last_slot_height(self, slot, height):
self._constants['last_block_slot'] = slot
self._constants['last_block_height'] = height
Expand Down
4 changes: 2 additions & 2 deletions proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __repr__(self):

def process_block_tag(self, tag):
if tag == "latest":
block_number = self.db.get_last_block_height()
block_number = self.db.get_latest_block_height()
elif tag in ('earliest', 'pending'):
raise Exception("Invalid tag {}".format(tag))
elif isinstance(tag, str):
Expand All @@ -134,7 +134,7 @@ def process_block_tag(self, tag):
return block_number

def eth_blockNumber(self):
height = self.db.get_last_block_height()
height = self.db.get_latest_block_height()
logger.debug("eth_blockNumber %s", hex(height))
return hex(height)

Expand Down