Skip to content

Commit

Permalink
add api info for pybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-o-how committed Jul 31, 2024
1 parent 54df4fe commit 1dc61dc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
13 changes: 13 additions & 0 deletions wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,19 @@ def confirm_not_included_already_hashed(
proof: bytes,
) -> bool: ...
def get_name_puzzle_conditions(
spend_bundle: SpendBundle,
max_cost: int,
constants: ConsensusConstants,
height: int,
) -> SpendBundleConditions: ...
def get_flags_for_height_and_constants(
height: int,
constants: ConsensusConstants
) -> int: ...
NO_UNKNOWN_CONDS: int = ...
STRICT_ARGS_COUNT: int = ...
LIMIT_HEAP: int = ...
Expand Down
13 changes: 13 additions & 0 deletions wheel/python/chia_rs/chia_rs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def confirm_not_included_already_hashed(
proof: bytes,
) -> bool: ...

def get_name_puzzle_conditions(
spend_bundle: SpendBundle,
max_cost: int,
constants: ConsensusConstants,
height: int,
) -> SpendBundleConditions: ...

def get_flags_for_height_and_constants(
height: int,
constants: ConsensusConstants
) -> int: ...


NO_UNKNOWN_CONDS: int = ...
STRICT_ARGS_COUNT: int = ...
LIMIT_HEAP: int = ...
Expand Down
35 changes: 34 additions & 1 deletion wheel/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use chia_consensus::gen::solution_generator::solution_generator as native_soluti
use chia_consensus::gen::solution_generator::solution_generator_backrefs as native_solution_generator_backrefs;
use chia_consensus::merkle_set::compute_merkle_set_root as compute_merkle_root_impl;
use chia_consensus::merkle_tree::{validate_merkle_proof, MerkleSet};
use chia_consensus::spendbundle_conditions::get_conditions_from_spendbundle;
use chia_consensus::spendbundle_validation::get_flags_for_height_and_constants;
use chia_protocol::{
BlockRecord, Bytes32, ChallengeBlockInfo, ChallengeChainSubSlot, ClassgroupElement, Coin,
CoinSpend, CoinState, CoinStateFilters, CoinStateUpdate, EndOfSubSlotBundle, Foliage,
Expand Down Expand Up @@ -41,7 +43,7 @@ use chia_protocol::{
use clvm_utils::tree_hash_from_bytes;
use clvmr::{ENABLE_BLS_OPS_OUTSIDE_GUARD, ENABLE_FIXED_DIV, LIMIT_HEAP, NO_UNKNOWN_OPS};
use pyo3::buffer::PyBuffer;
use pyo3::exceptions::{PyRuntimeError, PyValueError};
use pyo3::exceptions::{PyRuntimeError, PyTypeError, PyValueError};
use pyo3::prelude::*;
use pyo3::pybacked::PyBackedBytes;
use pyo3::types::PyBytes;
Expand Down Expand Up @@ -356,6 +358,33 @@ fn fast_forward_singleton<'p>(
))
}

#[pyfunction]
#[pyo3(name = "get_conditions_from_spendbundle")]
pub fn py_get_conditions_from_spendbundle(
spend_bundle: &SpendBundle,
max_cost: u64,
constants: &ConsensusConstants,
height: u32,
) -> PyResult<OwnedSpendBundleConditions> {
let osbc = get_conditions_from_spendbundle(spend_bundle, max_cost, height, constants).map_err(
|e| {
let error_code: u32 = e.1.into();
PyErr::new::<PyTypeError, _>(error_code)
},
)?;
Ok(osbc)
}

#[pyfunction]
#[pyo3(name = "get_flags_for_height_and_constants")]
pub fn py_get_flags_for_height_and_constants(
height: u32,
constants: &ConsensusConstants,
) -> PyResult<u32> {
let flags = get_flags_for_height_and_constants(height, constants);
Ok(flags)
}

#[pymodule]
pub fn chia_rs(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
// generator functions
Expand Down Expand Up @@ -385,6 +414,10 @@ pub fn chia_rs(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(confirm_included_already_hashed, m)?)?;
m.add_function(wrap_pyfunction!(confirm_not_included_already_hashed, m)?)?;

// multithread validattion
m.add_function(wrap_pyfunction!(py_get_conditions_from_spendbundle, m)?)?;
m.add_function(wrap_pyfunction!(py_get_flags_for_height_and_constants, m)?)?;

// clvm functions
m.add("NO_UNKNOWN_CONDS", NO_UNKNOWN_CONDS)?;
m.add("STRICT_ARGS_COUNT", STRICT_ARGS_COUNT)?;
Expand Down

0 comments on commit 1dc61dc

Please sign in to comment.