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

Add Copy, Default, and size constant to ClassgroupElement #480

Merged
merged 1 commit into from
Apr 22, 2024
Merged
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
17 changes: 9 additions & 8 deletions crates/chia-protocol/src/classgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ use chia_streamable_macro::streamable;
use pyo3::prelude::*;

#[streamable]
#[derive(Copy)]
pub struct ClassgroupElement {
data: Bytes100,
}

impl ClassgroupElement {
pub fn get_default_element() -> ClassgroupElement {
impl Default for ClassgroupElement {
fn default() -> Self {
let mut data = [0_u8; 100];
data[0] = 0x08;
ClassgroupElement { data: data.into() }
Self { data: data.into() }
}
}

pub fn get_size() -> i32 {
100
}
impl ClassgroupElement {
pub const SIZE: usize = 100;
}

#[cfg(feature = "py-bindings")]
Expand All @@ -41,12 +42,12 @@ impl ClassgroupElement {
#[staticmethod]
#[pyo3(name = "get_default_element")]
pub fn py_get_default_element() -> ClassgroupElement {
Self::get_default_element()
Self::default()
}

#[staticmethod]
#[pyo3(name = "get_size")]
pub fn py_get_size() -> i32 {
Self::get_size()
Self::SIZE as i32
}
}
Loading