Skip to content

Commit

Permalink
fix build after rebase;
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Oct 6, 2021
1 parent acc65e4 commit 7248702
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 29 deletions.
27 changes: 17 additions & 10 deletions bindings/ergo-lib-wasm/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
use std::convert::TryInto;

use derive_more::FromStr;
use ergo_lib::chain::ergo_box::BoxId;
use ergo_lib::chain::ergo_box::BoxValue;
use ergo_lib::chain::ergo_box::ErgoBox;
use ergo_lib::chain::ergo_box::ErgoBoxCandidate;
use ergo_lib::chain::ergo_box::NonMandatoryRegisters;
use ergo_lib::chain::token::Token;
use ergo_lib::chain::token::TokenId;
use ergo_lib::chain::transaction::unsigned::UnsignedTransaction;
use ergo_lib::chain::transaction::DataInput;
use ergo_lib::chain::transaction::Input;
use ergo_lib::chain::transaction::Transaction;
use ergo_lib::chain::transaction::TxId;
use ergo_lib::chain::transaction::UnsignedInput;
use ergo_lib::ergotree_ir::chain::ergo_box::box_value::BoxValue;
use ergo_lib::ergotree_ir::chain::ergo_box::BoxId;
use ergo_lib::ergotree_ir::chain::ergo_box::ErgoBox;
use ergo_lib::ergotree_ir::chain::ergo_box::ErgoBoxCandidate;
use ergo_lib::ergotree_ir::chain::ergo_box::NonMandatoryRegisters;
use ergo_lib::ergotree_ir::chain::token::Token;
use ergo_lib::ergotree_ir::chain::token::TokenId;
use ergo_lib::ergotree_ir::ergo_tree::ErgoTree;
use serde::Serialize;

Expand Down Expand Up @@ -85,7 +85,10 @@ pub(crate) struct ErgoBoxJsonEip12 {
#[serde(rename = "value")]
pub value: BoxValueJsonEip12,
/// guarding script, which should be evaluated to true in order to open this box
#[serde(rename = "ergoTree", with = "ergo_lib::chain::json::ergo_tree")]
#[serde(
rename = "ergoTree",
with = "ergo_lib::ergotree_ir::chain::json::ergo_tree"
)]
pub ergo_tree: ErgoTree,
/// secondary tokens the box contains
#[serde(rename = "assets")]
Expand Down Expand Up @@ -130,7 +133,10 @@ pub(crate) struct ErgoBoxCandidateJsonEip12 {
#[serde(rename = "value")]
pub value: BoxValueJsonEip12,
/// guarding script, which should be evaluated to true in order to open this box
#[serde(rename = "ergoTree", with = "ergo_lib::chain::json::ergo_tree")]
#[serde(
rename = "ergoTree",
with = "ergo_lib::ergotree_ir::chain::json::ergo_tree"
)]
pub ergo_tree: ErgoTree,
#[serde(rename = "assets")]
pub tokens: Vec<TokenJsonEip12>,
Expand Down Expand Up @@ -184,7 +190,7 @@ impl From<Token> for TokenJsonEip12 {
fn from(t: Token) -> Self {
TokenJsonEip12 {
token_id: t.token_id,
amount: TokenAmountJsonEip12(t.amount.as_u64()),
amount: TokenAmountJsonEip12(*t.amount.as_u64()),
}
}
}
Expand All @@ -196,6 +202,7 @@ pub struct TokenAmountJsonEip12(
// Encodes as string always
#[serde_as(as = "serde_with::DisplayFromStr")] u64,
);

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 2 additions & 4 deletions ergo-lib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `Constant::to/from_ergo_box`to Wasm API [#397](https://github.com/ergoplatform/sigma-rust/pull/397);

### Changed(BREAKING!):
- `ErgoTree::to_bytes()` renamed to `ErgoTree::sigma_serialize_bytes()` in Wasm [#387](https://github.com/ergoplatform/sigma-rust/pull/387);
- `ErgoBox` and other types that it uses moved to `ergotree_ir` crate and re-exported in `ergo_lib::ergotree_ir` [#397](https://github.com/ergoplatform/sigma-rust/pull/397);

### Changed(BREAKING)
- **WASM `to_json()` returns string (instead of `JsValue`) to avoid silent accuracy loss on JS object -> text conversion on JS side [#346](https://github.com/ergoplatform/sigma-rust/pull/346);**
- `SigmaSerializable:sigma_serialize_bytes` made failible (returns `Result`) [#328](https://github.com/ergoplatform/sigma-rust/pull/328);
- `ErgoBox::new`, `from_box_candidate` made failible (returns `Result`) [#328](https://github.com/ergoplatform/sigma-rust/pull/328);
- `ErgoTree::new`, `template_bytes`, `to_base16_bytes` made failible (returns `Result`) [#328](https://github.com/ergoplatform/sigma-rust/pull/328);
- `Transaction::new` made failible (returns `Result`) [#328](https://github.com/ergoplatform/sigma-rust/pull/328);
- WASM `ErgoBox::new`, `byte_to_sign` made failible (returns `Result`) [#328](https://github.com/ergoplatform/sigma-rust/pull/328);
- WASM `ErgoTree::to_bytes`, `to_base16_bytes` made failible (returns `Result`) [#328](https://github.com/ergoplatform/sigma-rust/pull/328);
- `ErgoTree::to_bytes()` renamed to `ErgoTree::sigma_serialize_bytes()` in Wasm [#387](https://github.com/ergoplatform/sigma-rust/pull/387);
- `ErgoBox` and other types that it uses moved to `ergotree_ir` crate and re-exported in `ergo_lib::ergotree_ir` [#397](https://github.com/ergoplatform/sigma-rust/pull/397);

### Changed
- Switched to `ThreadRng` CSPRNG for source of randomness in sigma protocol [#315](https://github.com/ergoplatform/sigma-rust/pull/315);
Expand Down
1 change: 1 addition & 0 deletions ergo-lib/src/chain/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub(crate) mod transaction;
use ergotree_interpreter::sigma_protocol::prover::ProofBytes;
use serde::{Deserialize, Serialize};

/// Serde remote type
#[cfg_attr(
feature = "json",
derive(Serialize, Deserialize),
Expand Down
2 changes: 1 addition & 1 deletion ergotree-interpreter/src/eval/coll_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ mod tests {
)
.unwrap()
.into();
assert_eq!(eval_out_wo_ctx::<Vec<i64>>(&expr), vec![]);
assert_eq!(eval_out_wo_ctx::<Vec<i64>>(&expr), Vec::<i64>::new());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion ergotree-interpreter/src/eval/scoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ mod tests {
.unwrap()
.into();
let res = eval_out_wo_ctx::<Vec<i32>>(&expr);
assert_eq!(res, vec![]);
assert_eq!(res, Vec::<i32>::new());
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion ergotree-interpreter/src/sigma_protocol/private_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use ergotree_ir::sigma_protocol::dlog_group;
use ergotree_ir::sigma_protocol::sigma_boolean::ProveDhTuple;
use ergotree_ir::sigma_protocol::sigma_boolean::ProveDlog;

use elliptic_curve::group::ff::PrimeField;
use ergotree_ir::sigma_protocol::sigma_boolean::SigmaBoolean;
use k256::Scalar;

Expand Down
8 changes: 7 additions & 1 deletion ergotree-ir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ default-features = false
features = ["std"]
optional = true

[dependencies.serde_with]
version = "1.9.1"
features = [ "json" ]
optional = true

[features]
default = []
arbitrary = ["proptest", "proptest-derive"]
json = ["serde", "serde_json"]
json = ["serde", "serde_json", "serde_with"]

[dev-dependencies]
sigma-test-util = { version = "0.2.0", path = "../sigma-test-util" }
rand = "0.8.3"
pretty_assertions = "0.7.2"
12 changes: 6 additions & 6 deletions ergotree-ir/src/chain/ergo_box/box_value.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Box value newtype
use crate::chain::token::TokenAmountError;
use derive_more::FromStr;
use ergotree_ir::mir::constant::Constant;
use ergotree_ir::serialization::sigma_byte_writer::SigmaByteWrite;
use ergotree_ir::serialization::SigmaSerializeResult;
use ergotree_ir::serialization::{
use crate::mir::constant::Constant;
use crate::serialization::sigma_byte_writer::SigmaByteWrite;
use crate::serialization::SigmaSerializeResult;
use crate::serialization::{
sigma_byte_reader::SigmaByteRead, SigmaParsingError, SigmaSerializable,
};
use derive_more::FromStr;
use std::convert::TryFrom;
use thiserror::Error;

Expand Down Expand Up @@ -211,7 +211,7 @@ pub fn checked_sum<I: Iterator<Item = BoxValue>>(mut iter: I) -> Result<BoxValue

/// Arbitrary
#[cfg(feature = "arbitrary")]
pub(crate) mod arbitrary {
pub mod arbitrary {
use derive_more::{From, Into};
use proptest::{arbitrary::Arbitrary, prelude::*};
use std::ops::Range;
Expand Down
2 changes: 1 addition & 1 deletion ergotree-ir/src/chain/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use serde::Serializer;

pub(crate) mod ergo_box;
pub(crate) mod ergo_tree;
pub mod ergo_tree;

/// Serialize bytes ([u8]) as base16 encoded string
pub fn serialize_bytes<S, T>(bytes: T, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[allow(clippy::unwrap_used)]
#[cfg(test)]
mod tests {
use crate::chain::ergo_box::BoxValue;
use crate::chain::ergo_box::box_value::BoxValue;
use std::convert::TryInto;

#[test]
Expand Down
2 changes: 2 additions & 0 deletions ergotree-ir/src/chain/json/ergo_tree.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! ErgoTree JSON encoding
use crate::ergo_tree::ErgoTree;
use crate::serialization::SigmaSerializable;
use serde::{Deserialize, Deserializer, Serializer};
Expand Down
8 changes: 5 additions & 3 deletions ergotree-ir/src/chain/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ pub struct TokenAmount(u64);
/// Token amount with bound checks
#[cfg(feature = "json")]
#[serde_with::serde_as]
#[derive(Serialize, Deserialize, PartialEq, Eq, Hash, Debug, Clone, Copy, PartialOrd, Ord)]
#[derive(
serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash, Debug, Clone, Copy, PartialOrd, Ord,
)]
pub struct TokenAmount(
// Tries to decode as u64 first, then fallback to string. Encodes as u64 always
// see details - https://docs.rs/serde_with/1.9.4/serde_with/struct.PickFirst.html
Expand Down Expand Up @@ -157,9 +159,9 @@ impl From<Token> for (Vec<i8>, i64) {
}

/// Token represented with token id paired with it's amount
#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))]
pub struct Token {
/// token id
#[cfg_attr(feature = "json", serde(rename = "tokenId"))]
Expand Down

0 comments on commit 7248702

Please # to comment.