Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiaMineJP committed Apr 3, 2024
1 parent b84b537 commit 8be82d5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
16 changes: 6 additions & 10 deletions wasm/src/lazy_node.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::rc::Rc;
use clvmr::allocator::{Allocator, NodePtr, SExp};
use std::rc::Rc;

use clvmr::serde::{node_to_bytes, node_to_bytes_backrefs};
use clvmr::ALLOW_BACKREFS;
use js_sys::Array;
use wasm_bindgen::prelude::*;
use clvmr::ALLOW_BACKREFS;
use clvmr::serde::{node_to_bytes, node_to_bytes_backrefs};

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

#[wasm_bindgen]
pub fn to_bytes(&self, flag: u32) -> Option<Vec<u8>>{
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
};
match serializer(&self.allocator, self.node) {
Ok(b) => {
Some(b)
},
Err(_) => {
None
}
Ok(b) => Some(b),
Err(_) => None,
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions wasm/src/run_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use wasm_bindgen::prelude::*;

use crate::lazy_node::LazyNode;
use clvmr::allocator::Allocator;
use clvmr::ALLOW_BACKREFS;
use clvmr::chia_dialect::ChiaDialect;
use clvmr::chia_dialect::NO_UNKNOWN_OPS as _no_unknown_ops;
use clvmr::cost::Cost;
use clvmr::run_program::run_program;
use clvmr::serde::{node_from_bytes, node_from_bytes_backrefs, node_to_bytes};
use clvmr::ALLOW_BACKREFS;

// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
Expand Down Expand Up @@ -47,13 +47,7 @@ pub fn run_clvm(program: &[u8], args: &[u8], flag: u32) -> Vec<u8> {
let args = deserializer(&mut allocator, args).unwrap();
let dialect = ChiaDialect::new(flag);

let r = run_program(
&mut allocator,
&dialect,
program,
args,
max_cost,
);
let r = run_program(&mut allocator, &dialect, program, args, max_cost);
match r {
Ok(reduction) => node_to_bytes(&allocator, reduction.1).unwrap(),
Err(_eval_err) => format!("{:?}", _eval_err).into(),
Expand Down
12 changes: 5 additions & 7 deletions wasm/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::lazy_node::LazyNode;
use clvmr::serde::{node_from_bytes, node_from_bytes_backrefs, serialized_length_from_bytes};
use clvmr::{Allocator, ALLOW_BACKREFS};
use std::rc::Rc;
use wasm_bindgen::prelude::wasm_bindgen;
use clvmr::{Allocator, ALLOW_BACKREFS};
use clvmr::serde::{node_from_bytes, node_from_bytes_backrefs, serialized_length_from_bytes};
use crate::lazy_node::LazyNode;

#[wasm_bindgen]
pub fn serialized_length(program: &[u8]) -> Result<u64, String> {
Expand All @@ -21,9 +21,7 @@ pub fn sexp_from_bytes(b: &[u8], flag: u32) -> Result<LazyNode, String> {
node_from_bytes
};
match deserializer(&mut allocator, b) {
Ok(node) => {
Ok(LazyNode::new(Rc::new(allocator), node))
},
Err(err) => Err(err.to_string())
Ok(node) => Ok(LazyNode::new(Rc::new(allocator), node)),
Err(err) => Err(err.to_string()),
}
}

0 comments on commit 8be82d5

Please sign in to comment.