Onionr/src/blockdb/getblocks.py

34 lines
974 B
Python
Raw Normal View History

2022-07-31 05:32:43 +00:00
from typing import Generator
import db
from onionrblocks import Block
from .dbpath import block_db_path
2022-09-02 02:31:49 +00:00
2022-07-31 05:32:43 +00:00
def get_blocks_by_type(block_type: str) -> "Generator[Block]":
2022-09-02 02:31:49 +00:00
try:
block_type = block_type.decode('utf-8')
except AttributeError:
pass
2022-07-31 05:32:43 +00:00
block_db = db.get_db_obj(block_db_path, 'u')
for block_hash in db.list_keys(block_db_path):
block = Block(block_hash, block_db[block_hash], auto_verify=False)
if block.type == block_type:
yield block
def get_blocks_after_timestamp(
timestamp: int, block_type: str = '') -> "Generator[Block]":
block_db = db.get_db_obj(block_db_path, 'u')
for block_hash in db.list_keys(block_db_path):
block = Block(block_hash, block_db[block_hash], auto_verify=False)
if block.timestamp > timestamp:
if block_type:
if block_type == block.type:
yield block
else:
2022-09-02 02:31:49 +00:00
yield block