From ee5f94ad3337d69e565f021c214cb764a164f7ca Mon Sep 17 00:00:00 2001 From: parazyd Date: Thu, 13 Jan 2022 15:14:33 +0100 Subject: [PATCH] bin/darkfid: Finalize features refactor. --- bin/darkfid/.gitignore | 4 +-- bin/darkfid/Cargo.toml | 64 +++++++++++++++++++++++++--------------- bin/darkfid/Makefile | 37 +++++++++++++++++++++++ bin/darkfid/src/main.rs | 21 +++++++------ src/crypto/mod.rs | 1 + src/crypto/token_list.rs | 4 +-- src/error.rs | 36 ++++++++++++---------- 7 files changed, 112 insertions(+), 55 deletions(-) create mode 100644 bin/darkfid/Makefile diff --git a/bin/darkfid/.gitignore b/bin/darkfid/.gitignore index 47eeb99a3..eb5a316cb 100644 --- a/bin/darkfid/.gitignore +++ b/bin/darkfid/.gitignore @@ -1,3 +1 @@ - -/target -Cargo.lock +target diff --git a/bin/darkfid/Cargo.toml b/bin/darkfid/Cargo.toml index 9bef0534f..88e541b55 100644 --- a/bin/darkfid/Cargo.toml +++ b/bin/darkfid/Cargo.toml @@ -1,36 +1,52 @@ [package] name = "darkfid" -version = "0.1.0" +version = "0.2.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies.darkfi] +path = "../../" +features = ["node", "rpc", "cli"] [dependencies] -darkfi = {path= "../../", features= ["node", "chain"] } +# Async +smol = "1.2.5" +async-std = "1.10.0" +async-trait = "0.1.52" +async-channel = "1.6.1" +async-executor = "1.4.1" +easy-parallel = "3.2.0" + +# Misc +clap = {version = "3.0.7", features = ["derive"]} +url = "2.2.2" +log = "0.4.14" +num_cpus = "1.13.1" +simplelog = "0.11.2" # Encoding and parsing -serde_json = "1.0.72" -serde = {version = "1.0.130", features = ["derive"]} -url = "2.2.2" +serde_json = "1.0.74" +num-bigint = {version = "0.4.3", features = ["serde"]} +# serde = {version = "1.0.130", features = ["derive"]} +# url = "2.2.2" -# Async -async-std = "1.10.0" -async-trait = "0.1.51" -async-channel = "1.6.1" -easy-parallel = "3.1.0" -async-executor = "1.4.1" -futures = "0.3.17" -smol = "1.2.5" +# # Async +# async-std = "1.10.0" +# async-trait = "0.1.51" +# async-channel = "1.6.1" +# easy-parallel = "3.1.0" +# async-executor = "1.4.1" +# futures = "0.3.17" +# smol = "1.2.5" -# Utilities -clap = { version = "3.0.0", features = ["derive"] } -log = "0.4.14" -simplelog = "0.11.1" -thiserror = "1.0.30" -rand = "0.8.4" -num_cpus = "1.13.0" -lazy_static = "1.4.0" -anyhow = "1.0.49" -num-bigint = {version = "0.4.3", features = ["rand", "serde"]} +# # Utilities +# clap = { version = "3.0.0", features = ["derive"] } +# log = "0.4.14" +# simplelog = "0.11.1" +# thiserror = "1.0.30" +# rand = "0.8.4" +# num_cpus = "1.13.0" +# lazy_static = "1.4.0" +# anyhow = "1.0.49" +# num-bigint = {version = "0.4.3", features = ["rand", "serde"]} diff --git a/bin/darkfid/Makefile b/bin/darkfid/Makefile new file mode 100644 index 000000000..2e0521ed0 --- /dev/null +++ b/bin/darkfid/Makefile @@ -0,0 +1,37 @@ +.POSIX: + +# Cargo binary +CARGO = cargo + +# Binary to be built +BIN = darkfid + +# Dependencies which should force the binaries to be rebuilt +BINDEPS = \ + Cargo.toml \ + $(shell find src -type f) \ + $(shell find ../../sql -type f) \ + $(shell find ../../contrib/token -type f) + +all: $(BIN) + +$(BIN): $(BINDEPS) + $(CARGO) build --release --all-features + cp -f target/release/$@ $@ + +check: $(BINDEPS) + $(CARGO) hack check --release --feature-powerset --no-dev-deps + +fix: + $(CARGO) clippy --release --all-features --fix --allow-dirty + +clippy: + $(CARGO) clippy --release --all-features + +test: + $(CARGO) test --release --all-features + +clean: + rm -f $(BIN) + +.PHONY: all check fix clippy test clean diff --git a/bin/darkfid/src/main.rs b/bin/darkfid/src/main.rs index d959c044d..88fe5fa0d 100644 --- a/bin/darkfid/src/main.rs +++ b/bin/darkfid/src/main.rs @@ -12,29 +12,28 @@ use simplelog::{ColorChoice, LevelFilter, TermLogger, TerminalMode}; use url::Url; use darkfi::{ - chain::{rocks::columns, Rocks, RocksColumn}, + blockchain::{rocks::columns, Rocks, RocksColumn}, cli::{CliDarkfid, Config, DarkfidConfig}, crypto::{ + address::Address, keypair::{Keypair, PublicKey, SecretKey}, proof::VerifyingKey, + token_list::{assign_id, DrkTokenList, TokenList}, + types::DrkTokenId, }, node::{ client::Client, state::{ProgramState, State}, wallet::walletdb::WalletDb, }, - types::DrkTokenId, - util::{ - assign_id, decode_base10, encode_base10, expand_path, join_config_path, - rpc::{ - jsonrpc::{ - error as jsonerr, request as jsonreq, response as jsonresp, send_raw_request, - ErrorCode::*, JsonRequest, JsonResult, - }, - rpcserver::{listen_and_serve, RequestHandler, RpcServerConfig}, + rpc::{ + jsonrpc::{ + error as jsonerr, request as jsonreq, response as jsonresp, send_raw_request, + ErrorCode::*, JsonRequest, JsonResult, }, - Address, DrkTokenList, NetworkName, TokenList, + rpcserver::{listen_and_serve, RequestHandler, RpcServerConfig}, }, + util::{decode_base10, encode_base10, expand_path, join_config_path, NetworkName}, zk::circuit::{MintContract, SpendContract}, Error, Result, }; diff --git a/src/crypto/mod.rs b/src/crypto/mod.rs index acb412356..d52ed62d1 100644 --- a/src/crypto/mod.rs +++ b/src/crypto/mod.rs @@ -12,6 +12,7 @@ pub mod proof; pub mod schnorr; pub mod spend_proof; pub mod token_id; +pub mod token_list; pub mod types; pub mod util; diff --git a/src/crypto/token_list.rs b/src/crypto/token_list.rs index 0f8023656..7cd0c4f0f 100644 --- a/src/crypto/token_list.rs +++ b/src/crypto/token_list.rs @@ -3,8 +3,8 @@ use std::collections::HashMap; use serde_json::Value; use crate::{ - types::DrkTokenId, - util::{generate_id2, NetworkName}, + crypto::{token_id::generate_id2, types::DrkTokenId}, + util::NetworkName, Error, Result, }; diff --git a/src/error.rs b/src/error.rs index 75c8ee0bd..741781a98 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,10 +18,10 @@ pub enum Error { #[cfg(feature = "util")] #[error("parse failed: `{0}`")] ParseFailed(&'static str), - // #[error("decode failed: `{0}`")] - // DecodeError(&'static str), - // #[error("encode failed: `{0}`")] - // EncodeError(&'static str), + #[error("decode failed: `{0}`")] + DecodeError(&'static str), + #[error("encode failed: `{0}`")] + EncodeError(&'static str), #[error(transparent)] ParseIntError(#[from] std::num::ParseIntError), @@ -56,8 +56,11 @@ pub enum Error { // TryIntoError, #[error("TryFrom error")] TryFromError, - // #[error(transparent)] - // TryFromBigIntError(#[from] num_bigint::TryFromBigIntError), + + #[cfg(feature = "util")] + #[error(transparent)] + TryFromBigIntError(#[from] num_bigint::TryFromBigIntError), + #[cfg(feature = "util")] #[error("Json serialization error: `{0}`")] SerdeJsonError(String), @@ -104,8 +107,8 @@ pub enum Error { ServicesError(&'static str), #[error("Client failed: `{0}`")] ClientFailed(String), - // #[error("Cashier failed: `{0}`")] - // CashierError(String), + #[error("Cashier failed: `{0}`")] + CashierError(String), #[error("ZmqError: `{0}`")] ZmqError(String), #[cfg(feature = "blockchain")] @@ -162,8 +165,11 @@ pub enum Error { #[cfg(feature = "util")] #[error("No keypair file detected.")] KeypairPathNotFound, - // #[error("SetLoggerError")] - // SetLoggerError, + #[error("No cashier public keys detected.")] + CashierKeysNotFound, + + #[error("SetLoggerError")] + SetLoggerError, #[cfg(feature = "async-runtime")] #[error("Async_channel sender error")] AsyncChannelSenderError, @@ -246,11 +252,11 @@ impl From for Error { } } -// impl From for Error { -// fn from(_err: log::SetLoggerError) -> Error { -// Error::SetLoggerError -// } -// } +impl From for Error { + fn from(_err: log::SetLoggerError) -> Error { + Error::SetLoggerError + } +} #[cfg(feature = "websockets")] impl From for Error {