Skip to content

Commit

Permalink
Merge pull request #284 from Chia-Network/member-functions
Browse files Browse the repository at this point in the history
fixup member functions for ClassgroupElement
  • Loading branch information
arvidn committed Oct 19, 2023
2 parents dc79626 + 67af891 commit 3facc85
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
34 changes: 29 additions & 5 deletions chia-protocol/src/classgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,42 @@ use pyo3::prelude::*;

streamable_struct!(ClassgroupElement { data: Bytes100 });

#[cfg(feature = "py-bindings")]
#[cfg_attr(feature = "py-bindings", pymethods)]
impl ClassgroupElement {
#[staticmethod]
pub fn get_default_element() -> ClassgroupElement {
let mut data = [0_u8; 100];
data[0] = 0x08;
ClassgroupElement { data: data.into() }
}

#[staticmethod]
pub fn get_size(_constants: pyo3::PyObject) -> i32 {
pub fn get_size() -> i32 {
100
}
}

#[cfg(feature = "py-bindings")]
#[pymethods]
impl ClassgroupElement {
#[staticmethod]
pub fn create(bytes: &[u8]) -> ClassgroupElement {
if bytes.len() == 100 {
ClassgroupElement { data: bytes.into() }
} else {
assert!(bytes.len() < 100);
let mut data = [0_u8; 100];
data[..bytes.len()].copy_from_slice(bytes);
ClassgroupElement { data: data.into() }
}
}

#[staticmethod]
#[pyo3(name = "get_default_element")]
pub fn py_get_default_element() -> ClassgroupElement {
Self::get_default_element()
}

#[staticmethod]
#[pyo3(name = "get_size")]
pub fn py_get_size() -> i32 {
Self::get_size()
}
}
4 changes: 4 additions & 0 deletions wheel/chia_rs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ class Handshake:

class ClassgroupElement:
data: bytes100
@staticmethod
def get_default_element() -> ClassgroupElement: ...
@staticmethod
def get_size() -> int: ...
def __init__(
self,
data: bytes100
Expand Down
10 changes: 9 additions & 1 deletion wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,15 @@ def parse_rust_source(filename: str) -> List[Tuple[str, List[str]]]:
return ret


extra_members = {"Coin": ["def name(self) -> bytes32: ..."]}
extra_members = {
"Coin": [
"def name(self) -> bytes32: ...",
],
"ClassgroupElement": [
"@staticmethod\n def get_default_element() -> ClassgroupElement: ...",
"@staticmethod\n def get_size() -> int: ...",
],
}

classes = []
for f in sorted(glob(str(input_dir / "*.rs"))):
Expand Down

0 comments on commit 3facc85

Please sign in to comment.