Skip to content

Commit

Permalink
remove BoxValue::new in favor of try_from;
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Jun 24, 2020
1 parent 3b4c0af commit 7c09fc3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
3 changes: 2 additions & 1 deletion bindings/ergo-wallet-wasm/src/lib.rs
Expand Up @@ -15,6 +15,7 @@ use sigma_tree::chain;
mod utils;

use chain::BoxValue;
use std::convert::TryFrom;
use wasm_bindgen::prelude::*;

/**
Expand Down Expand Up @@ -155,7 +156,7 @@ impl ErgoBoxCandidate {
// value is u32, because u64 makes in BigInt in JS
let ergo_tree = contract.0.get_ergo_tree();
let b = chain::ErgoBoxCandidate::new(
BoxValue::new(value as u64).expect("value out of bounds"),
BoxValue::try_from(value as u64).expect("value out of bounds"),
ergo_tree,
creation_height,
);
Expand Down
10 changes: 1 addition & 9 deletions sigma-tree/src/chain/ergo_box.rs
Expand Up @@ -156,22 +156,14 @@ impl BoxValue {
/// Minimal value
pub const MIN: BoxValue = BoxValue(BoxValue::MIN_RAW);

/// Create new value (with bounds check)
pub fn new(v: u64) -> Option<BoxValue> {
if BoxValue::within_bounds(v) {
Some(BoxValue(v))
} else {
None
}
}

/// Check if a value is in bounds
pub fn within_bounds(v: u64) -> bool {
v >= BoxValue::MIN_RAW && v <= BoxValue::MAX_RAW
}
}

/// BoxValue errors
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum BoxValueError {
/// Value is out of bounds
OutOfBounds,
Expand Down

0 comments on commit 7c09fc3

Please sign in to comment.