Просмотр исходного кода

bin/darkfid: Finalize features refactor.

parazyd 4 лет назад
Родитель
Сommit
ee5f94ad33
7 измененных файлов с 112 добавлено и 55 удалено
  1. 1 3
      bin/darkfid/.gitignore
  2. 40 24
      bin/darkfid/Cargo.toml
  3. 37 0
      bin/darkfid/Makefile
  4. 10 11
      bin/darkfid/src/main.rs
  5. 1 0
      src/crypto/mod.rs
  6. 2 2
      src/crypto/token_list.rs
  7. 21 15
      src/error.rs

+ 1 - 3
bin/darkfid/.gitignore

@@ -1,3 +1 @@
-
-/target
-Cargo.lock
+target

+ 40 - 24
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"] }
-
-# Encoding and parsing
-serde_json = "1.0.72"
-serde = {version = "1.0.130", features = ["derive"]}
-url = "2.2.2"
-
-
 # Async
+smol = "1.2.5"
 async-std = "1.10.0"
-async-trait = "0.1.51"
+async-trait = "0.1.52"
 async-channel = "1.6.1"
-easy-parallel = "3.1.0"
 async-executor = "1.4.1"
-futures = "0.3.17"
-smol = "1.2.5"
-
+easy-parallel = "3.2.0"
 
-# Utilities
-clap = { version = "3.0.0", features = ["derive"] }
+# Misc
+clap = {version = "3.0.7", features = ["derive"]}
+url = "2.2.2"
 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"]}
+num_cpus = "1.13.1"
+simplelog = "0.11.2"
+
+# Encoding and parsing
+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"
+
+
+# # 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"]}

+ 37 - 0
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

+ 10 - 11
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,
 };

+ 1 - 0
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;
 

+ 2 - 2
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,
 };
 

+ 21 - 15
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<num_bigint::BigUint>),
+
+    #[cfg(feature = "util")]
+    #[error(transparent)]
+    TryFromBigIntError(#[from] num_bigint::TryFromBigIntError<num_bigint::BigUint>),
+
     #[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<crate::node::client::ClientFailed> for Error {
     }
 }
 
-// impl From<log::SetLoggerError> for Error {
-// fn from(_err: log::SetLoggerError) -> Error {
-// Error::SetLoggerError
-// }
-// }
+impl From<log::SetLoggerError> for Error {
+    fn from(_err: log::SetLoggerError) -> Error {
+        Error::SetLoggerError
+    }
+}
 
 #[cfg(feature = "websockets")]
 impl From<tungstenite::Error> for Error {