ergo_lib_c_core/
batchmerkleproof.rs1use crate::{
2 util::{const_ptr_as_ref, mut_ptr_as_mut},
3 Error,
4};
5
6pub struct BatchMerkleProof(pub ergo_lib::ergo_merkle_tree::BatchMerkleProof);
7
8pub type BatchMerkleProofPtr = *mut BatchMerkleProof;
9pub type ConstBatchMerkleProofPtr = *const BatchMerkleProof;
10
11pub unsafe fn batchmerkleproof_valid(
12 proof: ConstBatchMerkleProofPtr,
13 expected_root: &[u8],
14) -> Result<bool, Error> {
15 let proof = const_ptr_as_ref(proof, "proof")?;
16 Ok(proof.0.valid(expected_root))
17}
18
19pub unsafe fn batchmerkleproof_from_json(
20 json: &str,
21 proof_out: *mut BatchMerkleProofPtr,
22) -> Result<(), Error> {
23 let proof_out = mut_ptr_as_mut(proof_out, "proof_out")?;
24 *proof_out = Box::into_raw(Box::new(serde_json::from_str(json).map(BatchMerkleProof)?));
25 Ok(())
26}
27
28pub unsafe fn batchmerkleproof_to_json(proof: ConstBatchMerkleProofPtr) -> Result<String, Error> {
29 let proof = const_ptr_as_ref(proof, "proof")?;
30 serde_json::to_string(&proof.0).map_err(Error::from)
31}