Skip to content

Commit

Permalink
move value module to the root;
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Nov 12, 2020
1 parent f86276e commit 3b2f72c
Show file tree
Hide file tree
Showing 24 changed files with 46 additions and 47 deletions.
2 changes: 1 addition & 1 deletion bindings/ergo-lib-wasm/src/ergo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use chain::ergo_box::NonMandatoryRegisters;
use ergo_lib::chain;
use wasm_bindgen::prelude::*;

use crate::ast::Value;
use crate::utils::I64;
use crate::value::Value;
use crate::{contract::Contract, transaction::TxId};

pub mod box_builder;
Expand Down
2 changes: 1 addition & 1 deletion bindings/ergo-lib-wasm/src/ergo_box/box_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
use ergo_lib::chain;
use wasm_bindgen::prelude::*;

use crate::ast::Value;
use crate::contract::Contract;
use crate::token::Token;
use crate::token::TokenAmount;
use crate::token::TokenId;
use crate::value::Value;

use super::BoxValue;
use super::ErgoBoxCandidate;
Expand Down
2 changes: 1 addition & 1 deletion bindings/ergo-lib-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#![allow(clippy::len_without_is_empty)]

pub mod address;
pub mod ast;
pub mod box_coll;
pub mod box_selector;
pub mod contract;
Expand All @@ -28,4 +27,5 @@ pub mod token;
pub mod transaction;
pub mod tx_builder;
pub mod utils;
pub mod value;
pub mod wallet;
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use js_sys::Uint8Array;
use wasm_bindgen::prelude::*;

use crate::utils::I64;
use ergo_lib::TryExtractFrom;
use ergo_lib::value::TryExtractFrom;

/// Ergo constant(evaluated) values
#[wasm_bindgen]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct Value(ergo_lib::Value);
pub struct Value(ergo_lib::value::Value);

#[wasm_bindgen]
impl Value {
Expand All @@ -24,7 +24,7 @@ impl Value {
base16_bytes_str.clone()
))
})?;
ergo_lib::Value::try_from(bytes)
ergo_lib::value::Value::try_from(bytes)
.map_err(|e| JsValue::from_str(&format! {"{:?}", e}))
.map(Value)
}
Expand Down Expand Up @@ -69,13 +69,13 @@ impl Value {
}
}

impl From<ergo_lib::Value> for Value {
fn from(c: ergo_lib::Value) -> Self {
impl From<ergo_lib::value::Value> for Value {
fn from(c: ergo_lib::value::Value) -> Self {
Value(c)
}
}

impl From<Value> for ergo_lib::Value {
impl From<Value> for ergo_lib::value::Value {
fn from(c: Value) -> Self {
c.0
}
Expand Down
3 changes: 1 addition & 2 deletions ergo-lib/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
use crate::eval::cost_accum::CostAccumulator;
use crate::eval::EvalError;
use crate::eval::Evaluable;
use crate::value::Value;
use crate::{serialization::op_code::OpCode, types::*};
use core::fmt;

mod constant_placeholder;
mod ops;
pub(crate) mod value;

pub(crate) use constant_placeholder::*;
pub(crate) use value::*;

#[derive(PartialEq, Eq, Debug, Clone)]
/// newtype for box register id
Expand Down
4 changes: 3 additions & 1 deletion ergo-lib/src/chain/address.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Address types

use super::digest32;
use crate::value::RawValue;
use crate::value::Value;
use crate::{
ast::{Expr, RawValue, Value},
ast::Expr,
ergo_tree::{ErgoTree, ErgoTreeParsingError},
serialization::{SerializationError, SigmaSerializable},
sigma_protocol::{
Expand Down
2 changes: 1 addition & 1 deletion ergo-lib/src/chain/ergo_box/box_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};

use crate::ast::Value;
use crate::value::Value;
use crate::chain::token::Token;
use crate::ergo_tree::ErgoTree;
use crate::serialization::SigmaSerializable;
Expand Down
2 changes: 1 addition & 1 deletion ergo-lib/src/chain/ergo_box/register.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Box registers

use crate::{ast::Value, serialization::SerializationError};
use crate::{value::Value, serialization::SerializationError};
#[cfg(feature = "json")]
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, convert::TryFrom};
Expand Down
8 changes: 3 additions & 5 deletions ergo-lib/src/ergo_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use crate::serialization::{
sigma_byte_writer::{SigmaByteWrite, SigmaByteWriter},
SerializationError, SigmaSerializable,
};
use crate::{
ast::{Expr, Value},
types::SType,
};
use crate::value::Value;
use crate::{ast::Expr, types::SType};
use io::{Cursor, Read};

use crate::serialization::constant_store::ConstantStore;
Expand Down Expand Up @@ -255,7 +253,7 @@ impl SigmaSerializable for ErgoTree {
mod tests {
use super::*;
use crate::serialization::sigma_serialize_roundtrip;
use crate::{ast::RawValue, chain, sigma_protocol::sigma_boolean::SigmaProp, types::SType};
use crate::{chain, sigma_protocol::sigma_boolean::SigmaProp, types::SType, value::RawValue};
use proptest::prelude::*;

impl Arbitrary for ErgoTree {
Expand Down
10 changes: 4 additions & 6 deletions ergo-lib/src/eval.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Interpreter
use crate::{
ast::{Expr, RawValue, Value},
sigma_protocol::sigma_boolean::SigmaBoolean,
types::SType,
};
use crate::value::RawValue;
use crate::value::Value;
use crate::{ast::Expr, sigma_protocol::sigma_boolean::SigmaBoolean, types::SType};

use cost_accum::CostAccumulator;
use thiserror::Error;
Expand Down Expand Up @@ -117,7 +115,7 @@ fn eval(
#[cfg(test)]
mod tests {
use crate::ast::ContextMethods;
use crate::ast::TryExtractFrom;
use crate::value::TryExtractFrom;

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion ergo-lib/src/eval/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ast::Value;
use crate::chain::ergo_state_context::ErgoStateContext;
use crate::value::Value;
use crate::wallet::signing::TransactionContext;

#[derive(PartialEq, Eq, Debug, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions ergo-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
// Clippy exclusions
#![allow(clippy::unit_arg)]

pub(crate) mod ast;
mod ast;
mod big_integer;
mod constants;
mod eval;
mod types;

pub use ast::value::*;

pub mod chain;
pub mod serialization;
pub mod sigma_protocol;
pub mod util;
pub mod value;
pub mod wallet;

pub mod ergo_tree;
Expand Down
2 changes: 1 addition & 1 deletion ergo-lib/src/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Serializers

mod constant;
mod constant_placeholder;
mod data;
mod expr;
mod fold;
mod sigmaboolean;
mod value;

pub(crate) mod constant_store;
pub(crate) mod ergo_box;
Expand Down
2 changes: 1 addition & 1 deletion ergo-lib/src/serialization/constant_placeholder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod tests {
constant_store::ConstantStore, sigma_byte_reader::SigmaByteReader,
sigma_byte_writer::SigmaByteWriter,
},
Value,
value::Value,
};
use io::Cursor;
use proptest::prelude::*;
Expand Down
5 changes: 3 additions & 2 deletions ergo-lib/src/serialization/constant_store.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Constant store for Sigma byte reader

use crate::ast::{ConstantPlaceholder, Value};
use crate::ast::ConstantPlaceholder;
use crate::value::Value;

/// Storage for constants used in ErgoTree constant segregation
pub struct ConstantStore {
Expand Down Expand Up @@ -42,7 +43,7 @@ impl ConstantStore {
#[cfg(test)]
mod tests {
use super::*;
use crate::{ast::RawValue, types::SType};
use crate::{types::SType, value::RawValue};

#[test]
fn test_empty() {
Expand Down
6 changes: 3 additions & 3 deletions ergo-lib/src/serialization/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::serialization::{
};
use crate::util::AsVecU8;
use crate::{
ast::RawValue,
ast::RawValue::*,
ast::{Coll, CollPrim},
value::RawValue,
value::RawValue::*,
value::{Coll, CollPrim},
sigma_protocol,
types::SType,
types::SType::*,
Expand Down
2 changes: 1 addition & 1 deletion ergo-lib/src/serialization/ergo_box.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! ErgoBox and ErgoBoxCandidate serialization
use crate::{
ast::Value,
value::Value,
chain::{
ergo_box::{BoxValue, ErgoBoxCandidate, NonMandatoryRegisters},
token::{Token, TokenId},
Expand Down
2 changes: 1 addition & 1 deletion ergo-lib/src/serialization/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::ast::{CollMethods, ConstantPlaceholder, Expr};
use crate::serialization::{
sigma_byte_reader::SigmaByteRead, SerializationError, SigmaSerializable,
};
use crate::Value;
use crate::value::Value;

use std::io;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use super::{data::DataSerializer, sigma_byte_writer::SigmaByteWrite};
use crate::serialization::{
sigma_byte_reader::SigmaByteRead, SerializationError, SigmaSerializable,
};
use crate::{types::SType, Value};
use crate::types::SType;
use crate::value::Value;

use std::io;

Expand Down
7 changes: 2 additions & 5 deletions ergo-lib/src/sigma_protocol/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,8 @@ impl Prover for TestProver {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
ast::{Expr, RawValue, Value},
sigma_protocol::private_input::DlogProverInput,
types::SType,
};
use crate::value::{RawValue, Value};
use crate::{ast::Expr, sigma_protocol::private_input::DlogProverInput, types::SType};
use std::rc::Rc;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion ergo-lib/src/sigma_protocol/prover/context_extension.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! ContextExtension type
use crate::{
ast::Value,
value::Value,
serialization::{
sigma_byte_reader::SigmaByteRead, sigma_byte_writer::SigmaByteWrite, SerializationError,
SigmaSerializable,
Expand Down
3 changes: 2 additions & 1 deletion ergo-lib/src/sigma_protocol/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ impl Verifier for TestVerifier {}
mod tests {
use super::*;
use crate::{
ast::{Expr, Value},
ast::Expr,
sigma_protocol::{
private_input::{DlogProverInput, PrivateInput},
prover::{Prover, TestProver},
},
types::SType,
value::Value,
};
use proptest::prelude::*;
use std::rc::Rc;
Expand Down
2 changes: 2 additions & 0 deletions ergo-lib/src/ast/value.rs → ergo-lib/src/value.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Value (non-reducable data values)

use crate::chain::{Base16DecodedBytes, Base16EncodedBytes};
use crate::{
chain::ergo_box::ErgoBox,
Expand Down
3 changes: 2 additions & 1 deletion ergo-lib/src/wallet/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ mod tests {
use proptest::collection::vec;
use proptest::prelude::*;

use crate::value::Value;
use crate::{
ast::{Expr, Value},
ast::Expr,
chain::{
ergo_box::{box_builder::ErgoBoxCandidateBuilder, BoxValue, NonMandatoryRegisters},
transaction::{TxId, UnsignedInput},
Expand Down

0 comments on commit 3b2f72c

Please sign in to comment.