From 1dc61dcefcca99dbf924ebef0b7a7d6eae042432 Mon Sep 17 00:00:00 2001 From: Matthew Howard Date: Wed, 31 Jul 2024 13:25:22 +0100 Subject: [PATCH] add api info for pybindings --- wheel/generate_type_stubs.py | 13 ++++++++++++ wheel/python/chia_rs/chia_rs.pyi | 13 ++++++++++++ wheel/src/api.rs | 35 +++++++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/wheel/generate_type_stubs.py b/wheel/generate_type_stubs.py index 008b8ecdb..c8c9a952f 100644 --- a/wheel/generate_type_stubs.py +++ b/wheel/generate_type_stubs.py @@ -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 = ... diff --git a/wheel/python/chia_rs/chia_rs.pyi b/wheel/python/chia_rs/chia_rs.pyi index 3a543d342..686c99d43 100644 --- a/wheel/python/chia_rs/chia_rs.pyi +++ b/wheel/python/chia_rs/chia_rs.pyi @@ -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 = ... diff --git a/wheel/src/api.rs b/wheel/src/api.rs index 43c7e88d3..fc6441de2 100644 --- a/wheel/src/api.rs +++ b/wheel/src/api.rs @@ -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, @@ -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; @@ -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 { + let osbc = get_conditions_from_spendbundle(spend_bundle, max_cost, height, constants).map_err( + |e| { + let error_code: u32 = e.1.into(); + PyErr::new::(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 { + 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 @@ -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)?;