atmst.blockstore package
Submodules
atmst.blockstore.car_file module
- atmst.blockstore.car_file.decode_varint(stream: BinaryIO)
- atmst.blockstore.car_file.encode_varint(n: int) bytes
- class atmst.blockstore.car_file.ReadOnlyCARBlockStore(file: BinaryIO, validate_hashes: bool = True)
Bases:
BlockStore
This is a sliiiightly unclean abstraction because BlockStores are indexed by bytes rather than CID, but same idea. This is convenient for verifying proofs provided in CAR format, and for testing.
- car_roots: List[CID]
- block_offsets: Dict[bytes, Tuple[int, int]]
- put_block(key: bytes, value: bytes) None
- get_block(key: bytes) bytes
- del_block(key: bytes) None
Module contents
- class atmst.blockstore.BlockStore
Bases:
ABC
A block store is a k/v store where values are immutable once set. They can be deleted, though. In practice, k==hash(v), but this API doesn’t care about that.
I’m not using the “native” __getitem__, __setitem__, __del__ methods because the semantics of these methods differ subtly.
if you call put() twice with the same args, the second call is a nop. if you call put() twice with the same key but different value, you get a ValueError
get() offers no default return value, you get a KeyError if it doesn’t exist.
if you try to delete a key that doesn’t exist, that’s a nop.
- abstract put_block(key: bytes, value: bytes) None
- abstract get_block(key: bytes) bytes
- abstract del_block(key: bytes) None
- class atmst.blockstore.MemoryBlockStore(state: Dict[bytes, bytes] | None = None)
Bases:
BlockStore
- put_block(key: bytes, value: bytes) None
- get_block(key: bytes) bytes
- del_block(key: bytes) None
- class atmst.blockstore.SqliteBlockStore(con: Connection, table: str = 'mst_blocks')
Bases:
BlockStore
NB: Caller is responsible for calling commit(), etc. TODO: consider allowing a custom table name?
- put_block(key: bytes, value: bytes) None
- get_block(key: bytes) bytes
- del_block(key: bytes) None
- class atmst.blockstore.OverlayBlockStore(upper: BlockStore, lower: BlockStore)
Bases:
BlockStore
reads come from “upper”, then “lower” if they don’t exist in upper. writes/deletes go only to “upper”.
- put_block(key: bytes, value: bytes) None
- get_block(key: bytes) bytes
- del_block(key: bytes) None