Skip to content

Commit

Permalink
Updated LazyNode::to_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiaMineJP committed Apr 10, 2024
1 parent d7ce52f commit 43c6db0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ mod test;
pub use de::node_from_bytes;
pub use de_br::{node_from_bytes_backrefs, node_from_bytes_backrefs_record};
pub use de_tree::{parse_triples, ParsedTriple};
pub use ser::node_to_bytes;
pub use ser_br::node_to_bytes_backrefs;
pub use ser::{node_to_bytes, node_to_bytes_limit};
pub use ser_br::{node_to_bytes_backrefs, node_to_bytes_backrefs_limit};
pub use tools::{
serialized_length_from_bytes, serialized_length_from_bytes_trusted, tree_hash_from_stream,
};
17 changes: 8 additions & 9 deletions wasm/src/lazy_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use js_sys::Array;
use std::rc::Rc;
use wasm_bindgen::prelude::*;

use crate::flags::ALLOW_BACKREFS;
use clvmr::allocator::{Allocator, NodePtr, SExp};
use clvmr::serde::{node_to_bytes, node_to_bytes_backrefs};
use clvmr::serde::{node_to_bytes_limit, node_to_bytes_backrefs_limit};

#[wasm_bindgen]
#[derive(Clone)]
Expand Down Expand Up @@ -39,13 +38,13 @@ impl LazyNode {
}

#[wasm_bindgen]
pub fn to_bytes(&self, flag: u32) -> Option<Vec<u8>> {
let serializer = if (flag & ALLOW_BACKREFS) != 0 {
node_to_bytes_backrefs
} else {
node_to_bytes
};
serializer(&self.allocator, self.node).ok()
pub fn to_bytes_with_backref(&self, limit: usize) -> Result<Vec<u8>, String> {
node_to_bytes_backrefs_limit(&self.allocator, self.node, limit).map_err(|e| e.to_string())
}

#[wasm_bindgen]
pub fn to_bytes(&self, limit: usize) -> Result<Vec<u8>, String> {
node_to_bytes_limit(&self.allocator, self.node, limit).map_err(|e| e.to_string())
}
}

Expand Down

0 comments on commit 43c6db0

Please sign in to comment.