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

make datalayer a submodule for the namespacing benefits #847

Merged
merged 4 commits into from
Jan 9, 2025
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
2 changes: 1 addition & 1 deletion tests/test_datalayer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from chia_rs import LeafNode, MerkleBlob
from chia_rs.datalayer import LeafNode, MerkleBlob
from chia_rs.sized_bytes import bytes32
from chia_rs.sized_ints import int64, uint8

Expand Down
55 changes: 0 additions & 55 deletions wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,61 +396,6 @@ def derive_child_sk_unhardened(sk: PrivateKey, index: int) -> PrivateKey: ...
def derive_child_pk_unhardened(pk: G1Element, index: int) -> G1Element: ...


@final
class InternalNode:
@property
def parent(self) -> Optional[uint32]: ...
@property
def hash(self) -> bytes: ...

@property
def left(self) -> uint32: ...
@property
def right(self) -> uint32: ...


@final
class LeafNode:
@property
def parent(self) -> Optional[uint32]: ...
@property
def hash(self) -> bytes: ...

@property
def key(self) -> int64: ...
@property
def value(self) -> int64: ...


@final
class MerkleBlob:
@property
def blob(self) -> bytearray: ...
@property
def free_indexes(self) -> set[uint32]: ...
@property
def key_to_index(self) -> Mapping[int64, uint32]: ...
@property
def check_integrity_on_drop(self) -> bool: ...

def __init__(
self,
blob: bytes,
) -> None: ...

def insert(self, key: int64, value: int64, hash: bytes32, reference_kid: Optional[int64] = None, side: Optional[uint8] = None) -> None: ...
def delete(self, key: int64) -> None: ...
def get_raw_node(self, index: uint32) -> Union[InternalNode, LeafNode]: ...
def calculate_lazy_hashes(self) -> None: ...
def get_lineage_with_indexes(self, index: uint32) -> list[tuple[uint32, Union[InternalNode, LeafNode]]]:...
def get_nodes_with_indexes(self) -> list[tuple[uint32, Union[InternalNode, LeafNode]]]: ...
def empty(self) -> bool: ...
def get_root_hash(self) -> bytes32: ...
def batch_insert(self, keys_values: list[tuple[int64, int64]], hashes: list[bytes32]): ...
def get_hash_at_index(self, index: uint32): ...

def __len__(self) -> int: ...

@final
class MerkleSet:
def get_root(self) -> bytes32: ...
Expand Down
55 changes: 0 additions & 55 deletions wheel/python/chia_rs/chia_rs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -125,61 +125,6 @@ class AugSchemeMPL:
def derive_child_pk_unhardened(pk: G1Element, index: int) -> G1Element: ...


@final
class InternalNode:
@property
def parent(self) -> Optional[uint32]: ...
@property
def hash(self) -> bytes: ...

@property
def left(self) -> uint32: ...
@property
def right(self) -> uint32: ...


@final
class LeafNode:
@property
def parent(self) -> Optional[uint32]: ...
@property
def hash(self) -> bytes: ...

@property
def key(self) -> int64: ...
@property
def value(self) -> int64: ...


@final
class MerkleBlob:
@property
def blob(self) -> bytearray: ...
@property
def free_indexes(self) -> set[uint32]: ...
@property
def key_to_index(self) -> Mapping[int64, uint32]: ...
@property
def check_integrity_on_drop(self) -> bool: ...

def __init__(
self,
blob: bytes,
) -> None: ...

def insert(self, key: int64, value: int64, hash: bytes32, reference_kid: Optional[int64] = None, side: Optional[uint8] = None) -> None: ...
def delete(self, key: int64) -> None: ...
def get_raw_node(self, index: uint32) -> Union[InternalNode, LeafNode]: ...
def calculate_lazy_hashes(self) -> None: ...
def get_lineage_with_indexes(self, index: uint32) -> list[tuple[uint32, Union[InternalNode, LeafNode]]]:...
def get_nodes_with_indexes(self) -> list[tuple[uint32, Union[InternalNode, LeafNode]]]: ...
def empty(self) -> bool: ...
def get_root_hash(self) -> bytes32: ...
def batch_insert(self, keys_values: list[tuple[int64, int64]], hashes: list[bytes32]): ...
def get_hash_at_index(self, index: uint32): ...

def __len__(self) -> int: ...

@final
class MerkleSet:
def get_root(self) -> bytes32: ...
Expand Down
63 changes: 63 additions & 0 deletions wheel/python/chia_rs/datalayer.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from typing import Mapping, Optional, Sequence, Union, Any, ClassVar, final
from .sized_bytes import bytes32, bytes100
from .sized_ints import uint8, uint16, uint32, uint64, uint128, int8, int16, int32, int64
from typing_extensions import Self
from chia.types.blockchain_format.program import Program as ChiaProgram

@final
class InternalNode:
@property
def parent(self) -> Optional[uint32]: ...
@property
def hash(self) -> bytes: ...

@property
def left(self) -> uint32: ...
@property
def right(self) -> uint32: ...


@final
class LeafNode:
@property
def parent(self) -> Optional[uint32]: ...
@property
def hash(self) -> bytes: ...

@property
def key(self) -> int64: ...
@property
def value(self) -> int64: ...


@final
class MerkleBlob:
@property
def blob(self) -> bytearray: ...
@property
def free_indexes(self) -> set[uint32]: ...
@property
def key_to_index(self) -> Mapping[int64, uint32]: ...
@property
def check_integrity_on_drop(self) -> bool: ...

def __init__(
self,
blob: bytes,
) -> None: ...

def insert(self, key: int64, value: int64, hash: bytes32, reference_kid: Optional[int64] = None, side: Optional[uint8] = None) -> None: ...
def delete(self, key: int64) -> None: ...
def get_raw_node(self, index: uint32) -> Union[InternalNode, LeafNode]: ...
def calculate_lazy_hashes(self) -> None: ...
def get_lineage_with_indexes(self, index: uint32) -> list[tuple[uint32, Union[InternalNode, LeafNode]]]:...
def get_nodes_with_indexes(self) -> list[tuple[uint32, Union[InternalNode, LeafNode]]]: ...
def empty(self) -> bool: ...
def get_root_hash(self) -> bytes32: ...
def batch_insert(self, keys_values: list[tuple[int64, int64]], hashes: list[bytes32]): ...
def get_hash_at_index(self, index: uint32): ...

def __len__(self) -> int: ...

# TODO: i would rather not specify this at all
__all__: Sequence[str] = ["InternalNode", "LeafNode", "MerkleBlob"]
26 changes: 20 additions & 6 deletions wheel/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ pub fn py_get_flags_for_height_and_constants(height: u32, constants: &ConsensusC
}

#[pymodule]
pub fn chia_rs(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
pub fn chia_rs(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
// generator functions
m.add_function(wrap_pyfunction!(run_block_generator, m)?)?;
m.add_function(wrap_pyfunction!(run_block_generator2, m)?)?;
Expand All @@ -475,11 +475,6 @@ pub fn chia_rs(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
// constants
m.add_class::<ConsensusConstants>()?;

// datalayer
m.add_class::<MerkleBlob>()?;
m.add_class::<InternalNode>()?;
m.add_class::<LeafNode>()?;

// merkle tree
m.add_class::<MerkleSet>()?;
m.add_function(wrap_pyfunction!(confirm_included_already_hashed, m)?)?;
Expand Down Expand Up @@ -647,5 +642,24 @@ pub fn chia_rs(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<AugSchemeMPL>()?;
m.add_class::<BlsCache>()?;

add_datalayer_submodule(py, m)?;

Ok(())
}

pub fn add_datalayer_submodule(py: Python<'_>, parent: &Bound<'_, PyModule>) -> PyResult<()> {
let datalayer = PyModule::new(py, "datalayer")?;
parent.add_submodule(&datalayer)?;

datalayer.add_class::<MerkleBlob>()?;
datalayer.add_class::<InternalNode>()?;
datalayer.add_class::<LeafNode>()?;

// https://github.com/PyO3/pyo3/issues/1517#issuecomment-808664021
// https://github.com/PyO3/pyo3/issues/759
py.import("sys")?
.getattr("modules")?
.set_item("chia_rs.datalayer", datalayer)?;

Ok(())
}
Loading