Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Asset contracts 2.0 #54

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ repository = "https://github.com/ElementsProject/rust-elements/"
documentation = "https://docs.rs/elements/"

[features]
default = [ "json-contract" ]
default = [ "contracts" ]

json-contract = [ "serde_json" ]
contracts = [ "serde", "serde_cbor", "serde_json" ]
"serde-feature" = [
"bitcoin/use-serde",
"serde"
Expand All @@ -25,13 +25,13 @@ bitcoin = "0.23"
# to avoid requiring two version of bitcoin_hashes.
bitcoin_hashes = "0.7.6"

# Used for ContractHash::from_json_contract.
serde_json = { version = "<=1.0.44", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }

[dependencies.serde]
version = "1.0"
optional = true
# Used for contracts module.
serde_cbor = { version = "0.11.1", optional = true }
serde_json = { version = "<=1.0.44", optional = true }

[dev-dependencies]
rand = "0.6.5"
serde_json = "<=1.0.44"
bitcoin = { version = "0.23", features = ["use-serde"] }
24 changes: 7 additions & 17 deletions src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use bitcoin::util::base58;
use bitcoin::PublicKey;
use bitcoin::hashes::Hash;
use bitcoin::secp256k1;
#[cfg(feature = "serde")]
#[cfg(feature = "serde-feature")]
use serde;

use blech32;
Expand Down Expand Up @@ -75,6 +75,7 @@ impl fmt::Display for AddressError {
}
}

#[allow(deprecated)]
impl error::Error for AddressError {
fn cause(&self) -> Option<&error::Error> {
match *self {
Expand All @@ -87,16 +88,7 @@ impl error::Error for AddressError {
}

fn description(&self) -> &str {
match *self {
AddressError::Base58(ref e) => e.description(),
AddressError::Bech32(ref e) => e.description(),
AddressError::Blech32(ref e) => e.description(),
AddressError::InvalidAddress(..) => "was unable to parse the address",
AddressError::UnsupportedWitnessVersion(..) => "unsupported witness version",
AddressError::InvalidBlindingPubKey(..) => "an invalid blinding pubkey was encountered",
AddressError::InvalidWitnessProgramLength => "program length incompatible with version",
AddressError::InvalidWitnessVersion => "invalid witness script version",
}
"description() is deprecated; use Display"
}
}

Expand Down Expand Up @@ -603,7 +595,7 @@ impl FromStr for Address {
}
}

#[cfg(feature = "serde")]
#[cfg(feature = "serde-feature")]
impl<'de> serde::Deserialize<'de> for Address {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand Down Expand Up @@ -646,7 +638,7 @@ impl<'de> serde::Deserialize<'de> for Address {
}
}

#[cfg(feature = "serde")]
#[cfg(feature = "serde-feature")]
impl serde::Serialize for Address {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -662,8 +654,6 @@ mod test {
use bitcoin::util::key;
use bitcoin::Script;
use bitcoin::secp256k1::{PublicKey, Secp256k1};
#[cfg(feature = "serde")]
use serde_json;

fn roundtrips(addr: &Address) {
assert_eq!(
Expand All @@ -678,9 +668,9 @@ mod test {
"script round-trip failed for {}",
addr,
);
#[cfg(feature = "serde")]
#[cfg(feature = "serde-feature")]
assert_eq!(
serde_json::from_value::<Address>(serde_json::to_value(&addr).unwrap()).ok().as_ref(),
::serde_json::from_value::<Address>(serde_json::to_value(&addr).unwrap()).ok().as_ref(),
Some(addr)
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use bitcoin;
use bitcoin::blockdata::script::Script;
use bitcoin::{BitcoinHash, BlockHash, VarInt};
use bitcoin::hashes::{Hash, sha256};
#[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "serde")] use std::fmt;
#[cfg(feature = "serde-feature")] use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "serde-feature")] use std::fmt;

use dynafed;
use Transaction;
Expand All @@ -49,7 +49,7 @@ pub enum ExtData {
},
}

#[cfg(feature = "serde")]
#[cfg(feature = "serde-feature")]
impl<'de> Deserialize<'de> for ExtData {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
use serde::de;
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<'de> Deserialize<'de> for ExtData {
}
}

#[cfg(feature = "serde")]
#[cfg(feature = "serde-feature")]
impl Serialize for ExtData {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
use serde::ser::SerializeStruct;
Expand Down
6 changes: 3 additions & 3 deletions src/confidential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Structures representing Pedersen commitments of various types
//!

#[cfg(feature = "serde")]
#[cfg(feature = "serde-feature")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use std::{io, fmt};
Expand Down Expand Up @@ -137,7 +137,7 @@ macro_rules! impl_confidential_commitment {
}
}

#[cfg(feature = "serde")]
#[cfg(feature = "serde-feature")]
impl Serialize for $name {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
use serde::ser::SerializeSeq;
Expand All @@ -161,7 +161,7 @@ macro_rules! impl_confidential_commitment {
}
}

#[cfg(feature = "serde")]
#[cfg(feature = "serde-feature")]
impl<'de> Deserialize<'de> for $name {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
use serde::de::{Error, Visitor, SeqAccess};
Expand Down
Loading