Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 904fea0

Browse files
author
Jan Xie
committed
get blockhashes from hash
1 parent 507099b commit 904fea0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

ethereum/chain.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,21 @@ def get_descendants(self, block, count=1):
417417
block_numbers = list(range(block.number + 1, min(self.head.number + 1,
418418
block.number + count + 1)))
419419
return [self.get(self.index.get_block_by_number(n)) for n in block_numbers]
420+
421+
def get_blockhashes_from_hash(self, hash, max):
422+
try:
423+
header = blocks.get_block_header(self.db, hash)
424+
except KeyError:
425+
return []
426+
427+
hashes = []
428+
for i in xrange(max):
429+
hash = header.prevhash
430+
try:
431+
header = blocks.get_block_header(self.db, hash)
432+
except KeyError:
433+
break
434+
hashes.append(hash)
435+
if header.number == 0:
436+
break
437+
return hashes

0 commit comments

Comments
 (0)