Skip to content

Commit

Permalink
Multi-crate refactoring completed
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jan 19, 2021
1 parent dd11003 commit ed5d92c
Show file tree
Hide file tree
Showing 30 changed files with 157 additions and 613 deletions.
352 changes: 42 additions & 310 deletions Cargo.lock

Large diffs are not rendered by default.

49 changes: 16 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exclude = [".github", "contrib", "client_side_validation", "strict_encoding"]
[lib]
name = "lnpbp"
path = "src/lib.rs"
crate-type = ["dylib", "rlib", "staticlib"]
crate-type = ["rlib", "staticlib"]

# Dependencies
# ============
Expand All @@ -34,56 +34,39 @@ crate-type = ["dylib", "rlib", "staticlib"]
[dependencies]
# Dependencies on other LNP/BP repositories
# -----------------------------------------
amplify = { version = "2.4", features = ["stringly_conversions"] }
amplify = { version = "3", features = ["stringly_conversions"] }
amplify_derive = "2.4.3"
strict_encoding = { version = "1.0.0-rc.3", path = "./strict_encoding", features = ["miniscript", "derive"] }
client_side_validation = { version = "1.0.0-rc.2", path = "./client_side_validation" }
strict_encoding = { version = "1.0.0-rc.3", features = ["miniscript", "derive"] }
client_side_validation = { version = "1.0.0-rc.1" }
# Dependencies on core rust-bitcoin ecosystem projects
# ----------------------------------------------------
bitcoin = { version = "~0.26.0", features = ["rand"] }
bitcoin_hashes = "~0.9.4" # we need macro from here
# <https://github.com/LNP-BP/LNPBPs/blob/master/lnpbp-0002.md#deterministic-public-key-extraction-from-bitcoin-script>
# We have to fix version of miniscript as required by LNPBP-2 specification
miniscript = { version = "~5.0.0", features = ["compiler"] }
bech32 = "~0.7.2"
# Core rust projects
# ------------------
# This strange naming is a workaround for cargo inability to define required
# features for a dependency. See
# <https://github.com/rust-lang/api-guidelines/issues/180> for the explanation
# and references.
miniscript = { version = "=5.0.0", features = ["compiler"] }
descriptor-wallet = "~0.3.0-rc.1"
# Serialization
# -------------
# This strange naming is a workaround for cargo inability to define required
# features for a dependency. See
# <https://github.com/rust-lang/api-guidelines/issues/180> for the explanation
# and references.
serde_crate = { package = "serde", version = "~1.0.106", features = ["derive"], optional = true }
serde_with = { version = "~1.5.1", features = ["hex"], optional = true }
serde_with_macros = { version = "~1.2.0", optional = true } # Fix for the problem in 1.3.0
# Core rust projects
# ------------------
lazy_static = "~1.4.0"
# Serializtion
# ------------
# Used in RGB data Bech32 encodings
regex = "1"
# Temporary-needed dependencies:
# ------------------------------
# 2. We use these to simplify enum strict encoding, but once the required
# functionality will become part of either amplify_derive or lnpbp_derive
# crates they should be removed
num-traits = "~0.2.11"
num-derive = "~0.3.0"

[dev-dependencies]
serde_json = "~1.0.60"

# Features
# ========
[features]
# Listings
# --------
# By default we use LNP with Tor support and URL support
default = []
all = ["serde", "elgamal"]
serde = ["serde_crate", "serde_with", "serde_with_macros", "amplify/serde",
"bitcoin/use-serde", "bitcoin_hashes/serde", "miniscript/serde"]
# Optional cryptographic functionality
# ------------------------------------
keygen = ["bitcoin/rand"]
"bitcoin/use-serde", "bitcoin_hashes/serde", "miniscript/serde",
"descriptor-wallet/serde"]
elgamal = [] # Provides ElGamal encryption module from this library

[workspace]
Expand Down
82 changes: 0 additions & 82 deletions src/bp/mod.rs

This file was deleted.

20 changes: 6 additions & 14 deletions src/bp/chain.rs → src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use bitcoin::hashes::hex::{self, FromHex, ToHex};
use bitcoin::hashes::{sha256d, Hash};
use bitcoin::BlockHash;

use crate::lightning_encoding;
use crate::strict_encoding::{
self, strict_deserialize, strict_serialize, StrictDecode, StrictEncode,
};
Expand Down Expand Up @@ -191,9 +190,6 @@ hash_newtype!(
impl strict_encoding::Strategy for AssetId {
type Strategy = strict_encoding::strategies::HashFixedBytes;
}
impl lightning_encoding::Strategy for AssetId {
type Strategy = lightning_encoding::strategies::AsBitcoinHash;
}

impl From<BlockHash> for AssetId {
fn from(block_hash: BlockHash) -> Self {
Expand Down Expand Up @@ -389,8 +385,8 @@ lazy_static! {
Debug,
Display,
Hash,
FromPrimitive,
ToPrimitive,
StrictEncode,
StrictDecode,
)]
#[display(Debug)]
#[cfg_attr(
Expand All @@ -406,7 +402,6 @@ pub enum ChainFormat {
/// Confidential transactions format
Elements = 1,
}
impl_enum_strict_encoding!(ChainFormat);

/// Layers on which a given asset can operate
#[derive(
Expand All @@ -419,8 +414,8 @@ impl_enum_strict_encoding!(ChainFormat);
Debug,
Display,
Hash,
FromPrimitive,
ToPrimitive,
StrictEncode,
StrictDecode,
)]
#[display(Debug)]
#[cfg_attr(
Expand All @@ -439,7 +434,6 @@ pub enum AssetLayer {
/// RGB), but also can be used on top of payment/state channels
Layer2and3 = 2,
}
impl_enum_strict_encoding!(AssetLayer);

#[derive(
Clone,
Expand All @@ -451,8 +445,8 @@ impl_enum_strict_encoding!(AssetLayer);
Debug,
Display,
Hash,
FromPrimitive,
ToPrimitive,
StrictEncode,
StrictDecode,
)]
#[cfg_attr(
feature = "serde",
Expand All @@ -472,7 +466,6 @@ pub enum AssetSystem {
/// RGB confidential assets
RgbContract = 2,
}
impl_enum_strict_encoding!(AssetSystem);

/// Parameters for a given asset, which are shared between different types of
/// Layer 1, 2 and 3 assets.
Expand Down Expand Up @@ -565,7 +558,6 @@ impl StrictDecode for AssetParams {
serde(crate = "serde_crate")
)]
#[display(Debug)]
#[lnpbp_crate(crate)]
pub struct ChainParams {
/// Hash of the genesis block, uniquely defining chain
pub genesis_hash: BlockHash,
Expand Down
17 changes: 9 additions & 8 deletions src/bp/dbc/error.rs → src/dbc/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.

use crate::bp;
use wallet::descriptor;

use crate::lnpbp1;

/// Different error types which may happen during deterministic bitcoin
Expand Down Expand Up @@ -40,7 +41,7 @@ pub enum Error {

/// Miniscript was unable to parse provided script data; they are either
/// invalid or miniscript library contains a bug
#[from(crate::bp::scripts::PubkeyParseError)]
#[from(wallet::PubkeyParseError)]
LockscriptParseError,

/// Provided script contains no keys, so commitment or its verification is
Expand All @@ -66,17 +67,17 @@ pub enum Error {
UncompressedKey,
}

impl From<bp::descriptor::Error> for Error {
fn from(err: bp::descriptor::Error) -> Self {
impl From<descriptor::Error> for Error {
fn from(err: descriptor::Error) -> Self {
match err {
bp::descriptor::Error::InvalidKeyData => Error::InvalidKeyData,
bp::descriptor::Error::UnsupportedWitnessVersion => {
descriptor::Error::InvalidKeyData => Error::InvalidKeyData,
descriptor::Error::UnsupportedWitnessVersion => {
Error::UnsupportedWitnessVersion
}
bp::descriptor::Error::PolicyCompilation(err) => {
descriptor::Error::PolicyCompilation(err) => {
Error::PolicyCompilation(err)
}
bp::descriptor::Error::UncompressedKeyInSegWitContext => {
descriptor::Error::UncompressedKeyInSegWitContext => {
Error::UncompressedKey
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bp/dbc/keyset.rs → src/dbc/keyset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use std::collections::BTreeSet;

use bitcoin::hashes::{sha256, Hmac};
use bitcoin::secp256k1;
use client_side_validation::commit_verify::EmbedCommitVerify;
use miniscript::Segwitv0;

use super::{Container, Error, Proof, ScriptEncodeData};
use crate::commit_verify::EmbedCommitVerify;
use crate::lnpbp1;

/// Container for LNPBP-1 commitments. In order to be constructed, commitment
Expand Down
13 changes: 7 additions & 6 deletions src/bp/dbc/lockscript.rs → src/dbc/lockscript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ use std::collections::{BTreeSet, HashSet};
use bitcoin::hashes::{hash160, sha256, Hmac};
use bitcoin::secp256k1;
use bitcoin::PubkeyHash;
use client_side_validation::commit_verify::EmbedCommitVerify;
use miniscript::Segwitv0;
use wallet::LockScript;

use super::{Container, Error, KeysetCommitment, Proof, ScriptEncodeData};
use crate::bp::dbc::KeysetContainer;
use crate::bp::scripts::*;
use crate::commit_verify::EmbedCommitVerify;
use crate::dbc::KeysetContainer;

#[derive(Clone, PartialEq, Eq, Hash, Debug, Display)]
#[display(Debug)]
Expand Down Expand Up @@ -242,14 +242,15 @@ where

#[cfg(test)]
mod test {
use std::str::FromStr;

use bitcoin::hashes::{hash160, sha256, Hash};
use bitcoin::secp256k1;
use miniscript::{Miniscript, Segwitv0};
use std::str::FromStr;
use wallet::SECP256K1;

use super::super::Error;
use super::*;
use crate::SECP256K1;
use crate::dbc::Error;

macro_rules! ms_str {
($($arg:tt)*) => (Miniscript::<bitcoin::PublicKey, Segwitv0>::from_str_insane(&format!($($arg)*)).unwrap())
Expand Down
1 change: 0 additions & 1 deletion src/bp/dbc/mod.rs → src/dbc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.

pub mod digests;
mod error;
pub mod keyset;
pub mod lockscript;
Expand Down
2 changes: 1 addition & 1 deletion src/bp/dbc/pubkey.rs → src/dbc/pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
use bitcoin::hashes::{sha256, Hmac};
use bitcoin::secp256k1;
use client_side_validation::commit_verify::EmbedCommitVerify;

use super::{Container, Error, Proof};
use crate::commit_verify::EmbedCommitVerify;
use crate::lnpbp1;

/// Container for LNPBP-1 commitments. In order to be constructed, commitment
Expand Down
Loading

0 comments on commit ed5d92c

Please sign in to comment.