Skip to content

Commit

Permalink
Merge pull request #135 from ergoplatform/i120-move-input-datainput-p…
Browse files Browse the repository at this point in the history
…roverresult

API clean up
  • Loading branch information
greenhat committed Nov 9, 2020
2 parents a2f7a97 + 0bc4cc0 commit 18fad86
Show file tree
Hide file tree
Showing 30 changed files with 115 additions and 137 deletions.
4 changes: 2 additions & 2 deletions bindings/ergo-lib-wasm/src/data_input.rs
Expand Up @@ -6,7 +6,7 @@ use wasm_bindgen::prelude::*;
/// Inputs, that are used to enrich script context, but won't be spent by the transaction
#[wasm_bindgen]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct DataInput(chain::data_input::DataInput);
pub struct DataInput(chain::transaction::DataInput);

/// DataInput collection
#[wasm_bindgen]
Expand Down Expand Up @@ -36,7 +36,7 @@ impl DataInputs {
}
}

impl From<&DataInputs> for Vec<chain::data_input::DataInput> {
impl From<&DataInputs> for Vec<chain::transaction::DataInput> {
fn from(v: &DataInputs) -> Self {
v.0.clone().iter().map(|i| i.0.clone()).collect()
}
Expand Down
4 changes: 2 additions & 2 deletions bindings/ergo-lib-wasm/src/ergo_tree.rs
Expand Up @@ -12,15 +12,15 @@ use derive_more::{From, Into};
/// The root of ErgoScript IR. Serialized instances of this class are self sufficient and can be passed around.
#[wasm_bindgen]
#[derive(PartialEq, Eq, Debug, Clone, From, Into)]
pub struct ErgoTree(ergo_lib::ErgoTree);
pub struct ErgoTree(ergo_lib::ergo_tree::ErgoTree);

#[wasm_bindgen]
impl ErgoTree {
/// Decode from base16 encoded serialized ErgoTree
pub fn from_base16_bytes(s: &str) -> Result<ErgoTree, JsValue> {
let bytes = Base16DecodedBytes::try_from(s.to_string())
.map_err(|e| JsValue::from_str(&format!("{}", e)))?;
ergo_lib::ErgoTree::sigma_parse_bytes(bytes.0)
ergo_lib::ergo_tree::ErgoTree::sigma_parse_bytes(bytes.0)
.map(ErgoTree)
.map_err(|e| JsValue::from_str(&format!("{}", e)))
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/ergo-lib-wasm/src/secret_key.rs
@@ -1,7 +1,7 @@
//! Secret key
use std::convert::TryInto;

use ergo_lib::sigma_protocol::DlogProverInput;
use ergo_lib::sigma_protocol::private_input::DlogProverInput;
use ergo_lib::wallet;
use wasm_bindgen::prelude::*;

Expand Down
5 changes: 5 additions & 0 deletions ergo-lib/CHANGELOG.md
Expand Up @@ -8,11 +8,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] - ReleaseDate

### Added

- Support for parsing ErgoBox id also from "id" JSON field name [#134](https://github.com/ergoplatform/sigma-rust/pull/134)
- Address::p2pk_from_ergo_tree to make an Address from ErgoTree with root ProveDlog [#136](https://github.com/ergoplatform/sigma-rust/pull/136)
- Address::p2pk_from_pk_bytes to make an Address from serialized PK [#136](https://github.com/ergoplatform/sigma-rust/pull/136)
- Address::from_str to parse an Address without checking the network prefix [#136](https://github.com/ergoplatform/sigma-rust/pull/136)

### Changed

- moved and change visibility of various modules(input, data_input, prover_result, etc.) [#135](https://github.com/ergoplatform/sigma-rust/pull/135)

## [0.3.0] - 2020-11-04

### Added
Expand Down
4 changes: 0 additions & 4 deletions ergo-lib/src/chain.rs
Expand Up @@ -11,12 +11,8 @@ pub use base16_bytes::Base16EncodedBytes;
pub use digest32::*;

pub mod address;
pub mod context_extension;
pub mod contract;
pub mod data_input;
pub mod ergo_box;
pub mod ergo_state_context;
pub mod input;
pub mod prover_result;
pub mod token;
pub mod transaction;
7 changes: 2 additions & 5 deletions ergo-lib/src/chain/address.rs
@@ -1,17 +1,14 @@
//! Address types

use super::digest32;
use crate::ast::Constant;
use crate::ast::ConstantVal;
use crate::ErgoTreeParsingError;
use crate::{
ast::Expr,
ast::{Constant, ConstantVal, Expr},
ergo_tree::{ErgoTree, ErgoTreeParsingError},
serialization::{SerializationError, SigmaSerializable},
sigma_protocol::{
dlog_group::EcPoint,
sigma_boolean::{ProveDlog, SigmaBoolean, SigmaProofOfKnowledgeTree, SigmaProp},
},
ErgoTree,
};
use std::{
convert::{TryFrom, TryInto},
Expand Down
3 changes: 2 additions & 1 deletion ergo-lib/src/chain/contract.rs
@@ -1,7 +1,8 @@
//! Ergo contract

use super::address::Address;
use crate::{serialization::SerializationError, ErgoTree};
use crate::ergo_tree::ErgoTree;
use crate::serialization::SerializationError;

/// High-level wrapper for ErgoTree
#[derive(PartialEq, Eq, Debug, Clone)]
Expand Down
9 changes: 3 additions & 6 deletions ergo-lib/src/chain/ergo_box/box_builder.rs
@@ -1,18 +1,15 @@
//! ErgoBoxCandidate builder

use std::collections::HashMap;
use std::convert::TryFrom;
use std::convert::TryInto;
use std::convert::{TryFrom, TryInto};

use crate::ast::Constant;
use crate::chain::token::Token;
use crate::ergo_tree::ErgoTree;
use crate::serialization::SigmaSerializable;
use crate::ErgoTree;

use super::box_value::BoxValue;
use super::register::NonMandatoryRegisterId;
use super::register::NonMandatoryRegisters;
use super::register::NonMandatoryRegistersError;
use super::register::{NonMandatoryRegisterId, NonMandatoryRegisters, NonMandatoryRegistersError};
use super::ErgoBoxCandidate;
use thiserror::Error;

Expand Down
20 changes: 11 additions & 9 deletions ergo-lib/src/chain/json.rs
Expand Up @@ -13,7 +13,8 @@ where
pub mod ergo_tree {

use super::*;
use crate::{serialization::SigmaSerializable, ErgoTree};
use crate::ergo_tree::ErgoTree;
use crate::serialization::SigmaSerializable;
use serde::{Deserialize, Deserializer, Serializer};

pub fn serialize<S>(ergo_tree: &ErgoTree, serializer: S) -> Result<S::Ok, S::Error>
Expand All @@ -38,12 +39,13 @@ pub mod ergo_tree {
}

pub mod ergo_box {
use crate::chain::ergo_box::BoxId;
use crate::chain::ergo_box::BoxValue;
use crate::chain::ergo_box::NonMandatoryRegisters;
use crate::{
chain::{token::Token, transaction::TxId},
ErgoTree,
chain::{
ergo_box::{BoxId, BoxValue, NonMandatoryRegisters},
token::Token,
transaction::TxId,
},
ergo_tree::ErgoTree,
};
use serde::Deserialize;

Expand Down Expand Up @@ -78,8 +80,8 @@ pub mod ergo_box {
}

pub mod transaction {
use crate::chain::input::UnsignedInput;
use crate::chain::{data_input::DataInput, ergo_box::ErgoBox, input::Input, transaction::TxId};
use crate::chain::transaction::{DataInput, Input, UnsignedInput};
use crate::chain::{ergo_box::ErgoBox, transaction::TxId};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
Expand Down Expand Up @@ -120,12 +122,12 @@ pub mod transaction {
#[cfg(test)]
mod tests {
use crate::chain::transaction::unsigned::UnsignedTransaction;
use crate::sigma_protocol::prover::ContextExtension;
use std::convert::TryInto;

use super::super::ergo_box::*;
use super::super::transaction::*;
use super::*;
use crate::chain::context_extension::ContextExtension;
use proptest::prelude::*;

proptest! {
Expand Down
7 changes: 5 additions & 2 deletions ergo-lib/src/chain/transaction.rs
@@ -1,15 +1,18 @@
//! Ergo transaction

mod data_input;
mod input;
pub mod unsigned;

pub use data_input::*;
pub use input::*;

#[cfg(feature = "json")]
use super::json;
use super::{
data_input::DataInput,
digest32::{blake2b256_hash, Digest32},
ergo_box::ErgoBox,
ergo_box::ErgoBoxCandidate,
input::Input,
token::TokenId,
};
use crate::serialization::{
Expand Down
Expand Up @@ -2,7 +2,7 @@

use std::io;

use super::ergo_box::BoxId;
use crate::chain::ergo_box::BoxId;
use crate::serialization::{
sigma_byte_reader::SigmaByteRead, sigma_byte_writer::SigmaByteWrite, SerializationError,
SigmaSerializable,
Expand Down
@@ -1,16 +1,14 @@
//! Transaction input
use std::io;

use super::{
context_extension::ContextExtension,
ergo_box::BoxId,
ergo_box::ErgoBoxId,
prover_result::{ProofBytes, ProverResult},
};
use crate::chain::ergo_box::{BoxId, ErgoBoxId};
use crate::serialization::{
sigma_byte_reader::SigmaByteRead, sigma_byte_writer::SigmaByteWrite, SerializationError,
SigmaSerializable,
};
use crate::sigma_protocol::prover::ContextExtension;
use crate::sigma_protocol::prover::ProofBytes;
use crate::sigma_protocol::prover::ProverResult;
#[cfg(feature = "json")]
use serde::{Deserialize, Serialize};

Expand Down
15 changes: 5 additions & 10 deletions ergo-lib/src/chain/transaction/unsigned.rs
@@ -1,24 +1,19 @@
//! Unsigned (without proofs) transaction

use super::input::{Input, UnsignedInput};
#[cfg(feature = "json")]
use super::json;
use super::DataInput;
use super::{
super::{
data_input::DataInput, digest32::blake2b256_hash, ergo_box::ErgoBoxCandidate, input::Input,
},
super::{digest32::blake2b256_hash, ergo_box::ErgoBoxCandidate},
Transaction, TxId,
};
#[cfg(feature = "json")]
use crate::chain::transaction::ErgoBox;
#[cfg(feature = "json")]
use crate::chain::transaction::TransactionFromJsonError;
use crate::{
chain::{
input::UnsignedInput,
prover_result::{ProofBytes, ProverResult},
},
serialization::SigmaSerializable,
};
use crate::serialization::SigmaSerializable;
use crate::sigma_protocol::prover::{ProofBytes, ProverResult};
#[cfg(feature = "json")]
use core::convert::TryFrom;
#[cfg(feature = "json")]
Expand Down
6 changes: 3 additions & 3 deletions ergo-lib/src/lib.rs
Expand Up @@ -14,17 +14,17 @@

mod big_integer;
mod constants;
mod ergo_tree;
pub mod serialization;
mod types;

pub mod ast;
pub mod chain;
pub mod eval;
pub mod serialization;
pub mod sigma_protocol;
pub mod util;
pub mod wallet;
pub use ergo_tree::*;

pub mod ergo_tree;

#[cfg(test)]
pub mod test_util;
2 changes: 1 addition & 1 deletion ergo-lib/src/serialization.rs
Expand Up @@ -10,9 +10,9 @@ mod sigmaboolean;
pub mod constant_store;
pub mod ergo_box;
pub mod op_code;
pub mod serializable;
pub mod sigma_byte_reader;
pub mod sigma_byte_writer;
pub mod types;

mod serializable;
pub use serializable::*;
9 changes: 3 additions & 6 deletions ergo-lib/src/serialization/ergo_box.rs
@@ -1,20 +1,17 @@
//! ErgoBox and ErgoBoxCandidate serialization
use crate::serialization::{
sigma_byte_reader::SigmaByteRead, SerializationError, SigmaSerializable,
};
use crate::{
ast::Constant,
chain::{
ergo_box::{BoxValue, ErgoBoxCandidate, NonMandatoryRegisters},
token::{Token, TokenId},
},
ErgoTree,
ergo_tree::ErgoTree,
serialization::{sigma_byte_reader::SigmaByteRead, SerializationError, SigmaSerializable},
};
use indexmap::IndexSet;

use super::sigma_byte_writer::SigmaByteWrite;
use std::convert::TryFrom;
use std::convert::TryInto;
use std::convert::{TryFrom, TryInto};
use std::io;

/// Box serialization with token ids optionally saved in transaction
Expand Down
21 changes: 10 additions & 11 deletions ergo-lib/src/sigma_protocol.rs
@@ -1,21 +1,18 @@
//! Sigma protocols

mod challenge;
mod private_input;

pub use challenge::*;
pub use private_input::*;

pub mod dlog_group;
pub mod dlog_protocol;
pub mod fiat_shamir;
pub mod private_input;
pub mod prover;
pub mod sig_serializer;
pub mod sigma_boolean;
pub mod unchecked_tree;
pub mod unproven_tree;
pub mod verifier;

mod challenge;
mod dlog_protocol;
mod fiat_shamir;
mod sig_serializer;
mod unchecked_tree;
mod unproven_tree;

use k256::Scalar;

use dlog_protocol::FirstDlogProverMessage;
Expand All @@ -24,6 +21,8 @@ use std::convert::TryInto;
use unchecked_tree::{UncheckedSigmaTree, UncheckedTree};
use unproven_tree::{UnprovenLeaf, UnprovenSchnorr, UnprovenTree};

use self::challenge::Challenge;

/** The message sent by a prover to its associated verifier as part of a sigma protocol interaction. */
pub trait ProverMessage {
/// serialized message
Expand Down
3 changes: 2 additions & 1 deletion ergo-lib/src/sigma_protocol/dlog_group.rs
Expand Up @@ -15,7 +15,6 @@
//!
//! On the other hand, any group element can be mapped to some string.

use super::DlogProverInput;
use crate::serialization::{
sigma_byte_reader::SigmaByteRead, SerializationError, SigmaSerializable,
};
Expand All @@ -28,6 +27,8 @@ use std::{
ops::{Add, Mul, Neg},
};

use super::private_input::DlogProverInput;

/// Elliptic curve point
#[derive(PartialEq, Debug, Clone)]
pub struct EcPoint(ProjectivePoint);
Expand Down
4 changes: 2 additions & 2 deletions ergo-lib/src/sigma_protocol/dlog_protocol.rs
Expand Up @@ -42,7 +42,7 @@ impl From<Scalar> for SecondDlogProverMessage {
/// Interactive prover
pub mod interactive_prover {
use super::{FirstDlogProverMessage, SecondDlogProverMessage};
use crate::sigma_protocol::{dlog_group, Challenge, DlogProverInput, ProveDlog};
use crate::sigma_protocol::{dlog_group, private_input::DlogProverInput, Challenge, ProveDlog};
use dlog_group::EcPoint;
use k256::Scalar;

Expand Down Expand Up @@ -101,7 +101,7 @@ pub mod interactive_prover {
mod tests {
use super::super::*;
use super::*;
use crate::sigma_protocol::DlogProverInput;
use crate::sigma_protocol::private_input::DlogProverInput;
use proptest::prelude::*;

proptest! {
Expand Down

0 comments on commit 18fad86

Please sign in to comment.