Add "node" feature.

This commit is contained in:
parazyd
2022-01-13 12:47:25 +01:00
parent fabafa3e5e
commit e441396383
13 changed files with 141 additions and 87 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
*.pyc
*.sage.py
/Cargo.lock
target/*
/zkas/target
/zkas/zkas

View File

@@ -30,14 +30,19 @@ native-tls = {version = "0.2.8", optional = true}
# Encoding
hex = {version = "0.4.3", optional = true}
bs58 = {version = "0.4.0", optional = true}
toml = {version = "0.5.8", optional = true}
bytes = {version = "1.1.0", optional = true}
serde = {version = "1.0.133", features = ["derive"], optional = true}
serde_json = {version = "1.0.74", optional = true}
bincode = {version = "1.3.3", optional = true}
# Utilities
clap = {version = "3.0.7", features = ["derive"], optional = true}
dirs = {version = "4.0.0", optional = true}
url = {version = "2.2.2", optional = true}
lazy_static = {version = "1.4.0", optional = true}
subtle = {version = "2.4.1", optional = true}
# Misc
num-bigint = {version = "0.4.3", optional = true}
@@ -47,7 +52,28 @@ termion = {version = "1.5.6", optional = true}
tungstenite = {version = "0.16.0", optional = true}
async-tungstenite = {version = "0.16.1", optional = true}
# Blockchain
# Crypto
blake2b_simd = {version = "1.0.0", optional = true}
pasta_curves = {version = "0.2.1", optional = true}
halo2 = {version = "=0.1.0-beta.1", features = ["dev-graph", "gadget-traces", "sanity-checks"], optional = true}
incrementalmerkletree = {version = "0.2.0", optional = true}
arrayvec = {version = "0.7.2", optional = true}
group = {version = "0.11.0", optional = true}
sha2 = {version = "0.10.1", optional = true}
crypto_api_chachapoly = {version = "0.5.0", optional = true}
# Wallet management
sqlx = {version = "0.5.10", features = ["runtime-async-std-native-tls", "sqlite"], optional = true}
libsqlite3-sys = {version = "0.23.1", features = ["bundled-sqlcipher"], optional = true }
# Node networking
zeromq = {version = "0.3.3", default-features = false, features = ["async-std-runtime", "all-transport"], optional = true }
# Node utilities
signal-hook = {version = "0.3.13", optional = true}
signal-hook-async-std = {version = "0.2.2", optional = true}
[dependencies.rocksdb]
# TODO: Revert to upstream after bd966750ec861d687913d59a9939a1408ac53131 is merged.
git = "https://github.com/parazyd/rust-rocksdb"
@@ -56,34 +82,54 @@ default-features = false
features = ["zstd"]
optional = true
[dependencies.halo2_gadgets]
git = "https://github.com/parazyd/halo2_gadgets.git"
rev = "b45c527276bb2309f3b256eb5f45ccdcc5bd8c0f"
features = ["dev-graph", "test-dependencies"]
optional = true
[features]
async-runtime = ["async-std", "async-channel", "async-executor", "async-trait", "futures", "smol"]
async-net = ["async-native-tls", "native-tls"]
websockets = ["tungstenite", "async-tungstenite"]
util = ["hex", "serde", "serde_json", "dirs", "num-bigint"]
async-runtime = [
"async-std",
"async-channel",
"async-executor",
"async-trait",
"futures",
"smol",
]
async-net = [
"async-native-tls",
"native-tls",
]
websockets = [
"async-tungstenite",
"tungstenite",
]
util = [
"hex",
"bincode",
"serde",
"serde_json",
"dirs",
"num-bigint"
]
rpc = ["async-runtime", "async-net", "util", "websockets", "url"]
chain = ["async-runtime", "rocksdb", "util"]
tui = ["async-std", "termion"]
system = ["async-runtime"]
cli = ["toml", "serde", "clap", "util"]
net = ["async-runtime", "util", "system"]
# [dependencies.halo2_gadgets]
# git = "https://github.com/parazyd/halo2_gadgets.git"
# rev = "b45c527276bb2309f3b256eb5f45ccdcc5bd8c0f"
# features = ["dev-graph", "test-dependencies"]
crypto = ["pasta_curves", "blake2b_simd", "incrementalmerkletree", "halo2", "halo2_gadgets", "subtle", "lazy_static", "group", "util", "arrayvec", "crypto_api_chachapoly", "sha2", "bs58"]
wallet = ["sqlx", "libsqlite3-sys"]
node = ["url", "async-runtime", "bytes", "crypto", "wallet", "chain", "util", "zeromq", "signal-hook", "signal-hook-async-std"]
# [dependencies]
# # Crypto
# halo2 = {version = "=0.1.0-beta.1", features = ["dev-graph", "gadget-traces", "sanity-checks"]}
# incrementalmerkletree = "0.2.0"
# pasta_curves = "0.2.1"
# rand = "0.8.4"
# num-bigint = {version = "0.4.3", features = ["rand", "serde"]}
# blake2b_simd = "1.0.0"
# group = "0.11.0"
# crypto_api_chachapoly = "0.5.0"
# arrayvec = "0.7.2"
# sha2 = "0.9.8"
@@ -115,7 +161,6 @@ net = ["async-runtime", "util", "system"]
# lazy_static = "1.4.0"
# log = "0.4.14"
# num_cpus = "1.13.0"
# signal-hook = "0.3.10"
# simplelog = "0.11.1"
# subtle = "2.4.1"
# thiserror = "1.0.30"
@@ -131,11 +176,7 @@ net = ["async-runtime", "util", "system"]
# # node dependencies
# ## Used for wallet management.
# sqlx = {version = "0.5.10", features = ["runtime-async-std-native-tls", "sqlite"], optional = true}
# libsqlite3-sys = {version = "0.23.1", features = ["bundled-sqlcipher"], optional = true }
# ## Used for gatewayd network transport.
# zeromq = {version = "0.3.1", default-features = false, features = ["async-std-runtime", "all-transport"], optional = true }
# signal-hook-async-std = {version = "0.2.1", optional = true}
# [workspace]
# members = ["bin/drk", "bin/darkfid", "bin/gateway"]

View File

@@ -32,7 +32,7 @@ pub enum Error {
// ParseFloatError(#[from] std::num::ParseFloatError),
// #[error(transparent)]
// FromHexError(#[from] hex::FromHexError),
#[cfg(feature = "rpc")]
#[cfg(any(feature = "rpc", feature = "node"))]
#[error("Url parse error `{0}`")]
UrlParseError(String),
@@ -52,8 +52,8 @@ pub enum Error {
// #[error("TryInto error")]
// TryIntoError,
// #[error("TryFrom error")]
// TryFromError,
#[error("TryFrom error")]
TryFromError,
// #[error(transparent)]
// TryFromBigIntError(#[from] num_bigint::TryFromBigIntError<num_bigint::BigUint>),
#[cfg(feature = "util")]
@@ -66,8 +66,9 @@ pub enum Error {
// #[error(transparent)]
// TomlSerializeError(#[from] toml::ser::Error),
// #[error("Bincode serialization error: `{0}`")]
// BincodeError(String),
#[cfg(feature = "util")]
#[error("Bincode serialization error: `{0}`")]
BincodeError(String),
// /// Contract
// #[error("Bad variable ref type byte")]
@@ -92,28 +93,29 @@ pub enum Error {
#[error("Unable to decrypt mint note")]
NoteDecryptionFailed,
// #[cfg(feature = "node")]
// #[error(transparent)]
// VerifyFailed(#[from] crate::node::state::VerifyFailed),
#[cfg(feature = "node")]
#[error(transparent)]
VerifyFailed(#[from] crate::node::state::VerifyFailed),
// #[error("MerkleTree is full")]
// TreeFull,
// /// Service
// #[error("Services Error: `{0}`")]
// ServicesError(&'static str),
// #[error("Client failed: `{0}`")]
// ClientFailed(String),
#[error("Services Error: `{0}`")]
ServicesError(&'static str),
#[error("Client failed: `{0}`")]
ClientFailed(String),
// #[error("Cashier failed: `{0}`")]
// CashierError(String),
// #[error("ZmqError: `{0}`")]
// ZmqError(String),
#[error("ZmqError: `{0}`")]
ZmqError(String),
#[cfg(feature = "chain")]
#[error("Rocksdb error: `{0}`")]
RocksdbError(String),
// #[error("sqlx error: `{0}`")]
// SqlxError(String),
// #[error("SlabsStore Error: `{0}`")]
// SlabsStore(String),
#[cfg(feature = "node")]
#[error("sqlx error: `{0}`")]
SqlxError(String),
#[cfg(feature = "node")]
#[error("SlabsStore Error: `{0}`")]
SlabsStore(String),
// /// RPC errors
// #[error("JsonRpc Error: `{0}`")]
@@ -160,10 +162,12 @@ pub enum Error {
KeypairPathNotFound,
// #[error("SetLoggerError")]
// SetLoggerError,
// #[error("Async_channel sender error")]
// AsyncChannelSenderError,
// #[error(transparent)]
// AsyncChannelReceiverError(#[from] async_channel::RecvError),
#[cfg(feature = "async-runtime")]
#[error("Async_channel sender error")]
AsyncChannelSenderError,
#[cfg(feature = "async-runtime")]
#[error(transparent)]
AsyncChannelReceiverError(#[from] async_channel::RecvError),
// #[error("Error converting Address to PublicKey")]
// AddressToPublicKeyError,
@@ -178,12 +182,12 @@ pub enum Error {
InvalidAddress,
}
// #[cfg(feature = "node")]
// impl From<zeromq::ZmqError> for Error {
// fn from(err: zeromq::ZmqError) -> Error {
// Error::ZmqError(err.to_string())
// }
// }
#[cfg(feature = "node")]
impl From<zeromq::ZmqError> for Error {
fn from(err: zeromq::ZmqError) -> Error {
Error::ZmqError(err.to_string())
}
}
#[cfg(feature = "chain")]
impl From<rocksdb::Error> for Error {
@@ -192,12 +196,12 @@ impl From<rocksdb::Error> for Error {
}
}
// #[cfg(feature = "node")]
// impl From<sqlx::error::Error> for Error {
// fn from(err: sqlx::error::Error) -> Error {
// Error::SqlxError(err.to_string())
// }
// }
#[cfg(feature = "node")]
impl From<sqlx::error::Error> for Error {
fn from(err: sqlx::error::Error) -> Error {
Error::SqlxError(err.to_string())
}
}
#[cfg(feature = "util")]
impl From<serde_json::Error> for Error {
@@ -212,11 +216,12 @@ impl From<std::io::Error> for Error {
}
}
// impl<T> From<async_channel::SendError<T>> for Error {
// fn from(_err: async_channel::SendError<T>) -> Error {
// Error::AsyncChannelSenderError
// }
// }
#[cfg(feature = "async-runtime")]
impl<T> From<async_channel::SendError<T>> for Error {
fn from(_err: async_channel::SendError<T>) -> Error {
Error::AsyncChannelSenderError
}
}
#[cfg(feature = "async-net")]
impl From<async_native_tls::Error> for Error {
@@ -232,12 +237,12 @@ impl From<url::ParseError> for Error {
}
}
// #[cfg(feature = "node")]
// impl From<crate::node::client::ClientFailed> for Error {
// fn from(err: crate::node::client::ClientFailed) -> Error {
// Error::ClientFailed(err.to_string())
// }
// }
#[cfg(feature = "node")]
impl From<crate::node::client::ClientFailed> for Error {
fn from(err: crate::node::client::ClientFailed) -> Error {
Error::ClientFailed(err.to_string())
}
}
// impl From<log::SetLoggerError> for Error {
// fn from(_err: log::SetLoggerError) -> Error {
@@ -259,11 +264,12 @@ impl From<halo2::plonk::Error> for Error {
}
}
// impl From<Box<bincode::ErrorKind>> for Error {
// fn from(err: Box<bincode::ErrorKind>) -> Error {
// Error::BincodeError(err.to_string())
// }
// }
#[cfg(feature = "util")]
impl From<Box<bincode::ErrorKind>> for Error {
fn from(err: Box<bincode::ErrorKind>) -> Error {
Error::BincodeError(err.to_string())
}
}
// impl From<std::convert::Infallible> for Error {
// fn from(err: std::convert::Infallible) -> Error {

View File

@@ -8,16 +8,16 @@ use url::Url;
use crate::{
chain::{rocks::columns, Rocks, RocksColumn, Slab},
crypto::{
address::Address,
coin::Coin,
keypair::{Keypair, PublicKey, SecretKey},
merkle_node::MerkleNode,
proof::ProvingKey,
types::DrkTokenId,
OwnCoin,
},
serial::{Decodable, Encodable},
tx,
types::DrkTokenId,
util::Address,
util::serial::{Decodable, Encodable},
zk::circuit::{MintContract, SpendContract},
Result,
};

View File

@@ -1,4 +1,6 @@
pub mod client;
pub mod service;
pub mod state;
#[cfg(feature = "wallet")]
pub mod wallet;

View File

@@ -11,7 +11,7 @@ use url::Url;
use super::reqrep::{PeerId, Publisher, RepProtocol, Reply, ReqProtocol, Request, Subscriber};
use crate::{
chain::{rocks::columns, RocksColumn, Slab, SlabStore},
serial::{deserialize, serialize},
util::serial::{deserialize, serialize},
Error, Result,
};

View File

@@ -11,7 +11,7 @@ use signal_hook_async_std::Signals;
use zeromq::*;
use crate::{
serial::{deserialize, serialize, Decodable, Encodable},
util::serial::{deserialize, serialize, Decodable, Encodable},
Result,
};

View File

@@ -14,9 +14,9 @@ use crate::{
crypto::{
keypair::{Keypair, PublicKey, SecretKey},
merkle_node::MerkleNode,
types::DrkTokenId,
},
node::client::ClientFailed,
types::DrkTokenId,
util::NetworkName,
Error, Result,
};

View File

@@ -1,5 +1,5 @@
use crate::{
serial::{deserialize, serialize, Decodable, Encodable},
util::serial::{deserialize, serialize, Decodable, Encodable},
Result,
};

View File

@@ -16,11 +16,11 @@ use crate::{
merkle_node::MerkleNode,
note::Note,
nullifier::Nullifier,
types::DrkTokenId,
OwnCoin, OwnCoins,
},
node::client::ClientFailed,
serial::serialize,
types::DrkTokenId,
util::serial::serialize,
Error, Result,
};

View File

@@ -14,9 +14,9 @@ use crate::{
proof::ProvingKey,
schnorr::SchnorrSecret,
spend_proof::create_spend_proof,
types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind},
},
serial::Encodable,
types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind},
util::serial::Encodable,
Result,
};

View File

@@ -15,14 +15,14 @@ use crate::{
schnorr,
schnorr::SchnorrPublic,
spend_proof::verify_spend_proof,
types::{DrkTokenId, DrkValueBlind, DrkValueCommit},
util::{mod_r_p, pedersen_commitment_scalar, pedersen_commitment_u64},
MintRevealedValues, SpendRevealedValues,
},
error::Result,
impl_vec,
node::state,
serial::{Decodable, Encodable, VarInt},
types::{DrkTokenId, DrkValueBlind, DrkValueCommit},
util::serial::{Decodable, Encodable, VarInt},
};
pub use self::builder::{

View File

@@ -2,11 +2,15 @@ use std::io;
use super::TransactionOutput;
use crate::{
crypto::{keypair::PublicKey, spend_proof::SpendRevealedValues, Proof},
crypto::{
keypair::PublicKey,
spend_proof::SpendRevealedValues,
types::{DrkTokenId, DrkValueBlind},
Proof,
},
error::Result,
impl_vec,
serial::{Decodable, Encodable, VarInt},
types::{DrkTokenId, DrkValueBlind},
util::serial::{Decodable, Encodable, VarInt},
};
pub struct PartialTransaction {