Skip to content

Commit

Permalink
Merge pull request #466 from neonlabsorg/448_return_block_height_of_l…
Browse files Browse the repository at this point in the history
…atest_block_with_transaction

#448 eth_getBlockByNumber returns latest transaction block
  • Loading branch information
afalaleev authored Jan 20, 2022
2 parents a52737d + 6974603 commit b7961b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
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

0 comments on commit b7961b5

Please sign in to comment.