Procházet zdrojové kódy

fixed merge errors

lunar-mining před 4 roky
rodič
revize
d45ec5da5d

+ 38 - 13
src/client.rs

@@ -27,31 +27,19 @@ use crate::{
 };
 };
 */
 */
 
 
-#[derive(Debug, Clone, thiserror::Error)]
+#[derive(Debug, Clone)]
 pub enum ClientFailed {
 pub enum ClientFailed {
-    #[error("here is no enough value {0}")]
     NotEnoughValue(u64),
     NotEnoughValue(u64),
-    #[error("Invalid Address  {0}")]
     InvalidAddress(String),
     InvalidAddress(String),
-    #[error("Invalid Amount {0}")]
     InvalidAmount(u64),
     InvalidAmount(u64),
-    #[error("Unable to get deposit address")]
     UnableToGetDepositAddress,
     UnableToGetDepositAddress,
-    #[error("Unable to get withdraw address")]
     UnableToGetWithdrawAddress,
     UnableToGetWithdrawAddress,
-    #[error("Does not have cashier public key")]
     DoesNotHaveCashierPublicKey,
     DoesNotHaveCashierPublicKey,
-    #[error("Does not have keypair")]
     DoesNotHaveKeypair,
     DoesNotHaveKeypair,
-    #[error("Password is empty. Cannot create database")]
     EmptyPassword,
     EmptyPassword,
-    #[error("Wallet already initalized")]
     WalletInitialized,
     WalletInitialized,
-    #[error("Keypair already exists")]
     KeyExists,
     KeyExists,
-    #[error("{0}")]
     ClientError(String),
     ClientError(String),
-    #[error("Verify error: {0}")]
     VerifyError(String),
     VerifyError(String),
 }
 }
 
 
@@ -549,6 +537,43 @@ impl State {
 }
 }
 */
 */
 
 
+impl std::error::Error for ClientFailed {}
+
+impl std::fmt::Display for ClientFailed {
+    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+        match self {
+            ClientFailed::NotEnoughValue(i) => {
+                write!(f, "There is no enough value {}", i)
+            }
+            ClientFailed::InvalidAddress(i) => {
+                write!(f, "Invalid Address {}", i)
+            }
+            ClientFailed::InvalidAmount(i) => {
+                write!(f, "Invalid Amount {}", i)
+            }
+            ClientFailed::UnableToGetDepositAddress => f.write_str("Unable to get deposit address"),
+            ClientFailed::UnableToGetWithdrawAddress => {
+                f.write_str("Unable to get withdraw address")
+            }
+            ClientFailed::DoesNotHaveCashierPublicKey => {
+                f.write_str("Does not have cashier public key")
+            }
+            ClientFailed::DoesNotHaveKeypair => f.write_str("Does not have keypair"),
+            ClientFailed::EmptyPassword => f.write_str("Password is empty. Cannot create database"),
+            ClientFailed::WalletInitialized => f.write_str("Wallet already initalized"),
+            ClientFailed::KeyExists => f.write_str("Keypair already exists"),
+
+            ClientFailed::ClientError(i) => {
+                write!(f, "{}", i)
+            }
+
+            ClientFailed::VerifyError(i) => {
+                write!(f, "Verify error: {}", i)
+            }
+        }
+    }
+}
+
 impl From<super::error::Error> for ClientFailed {
 impl From<super::error::Error> for ClientFailed {
     fn from(err: super::error::Error) -> ClientFailed {
     fn from(err: super::error::Error) -> ClientFailed {
         ClientFailed::ClientError(err.to_string())
         ClientFailed::ClientError(err.to_string())

+ 0 - 6
src/crypto/mod.rs

@@ -1,9 +1,3 @@
-Warning: can't set `wrap_comments = true`, unstable features are only available in nightly channel.
-Warning: can't set `comment_width = 100`, unstable features are only available in nightly channel.
-Warning: can't set `imports_granularity = Crate`, unstable features are only available in nightly channel.
-Warning: can't set `binop_separator = Back`, unstable features are only available in nightly channel.
-Warning: can't set `trailing_semicolon = false`, unstable features are only available in nightly channel.
-Warning: can't set `trailing_comma = Vertical`, unstable features are only available in nightly channel.
 pub mod arith_chip;
 pub mod arith_chip;
 pub mod coin;
 pub mod coin;
 pub mod constants;
 pub mod constants;

+ 0 - 6
src/crypto/nullifier.rs

@@ -1,9 +1,3 @@
-Warning: can't set `wrap_comments = true`, unstable features are only available in nightly channel.
-Warning: can't set `comment_width = 100`, unstable features are only available in nightly channel.
-Warning: can't set `imports_granularity = Crate`, unstable features are only available in nightly channel.
-Warning: can't set `binop_separator = Back`, unstable features are only available in nightly channel.
-Warning: can't set `trailing_semicolon = false`, unstable features are only available in nightly channel.
-Warning: can't set `trailing_comma = Vertical`, unstable features are only available in nightly channel.
 use std::io;
 use std::io;
 
 
 use pasta_curves::{arithmetic::FieldExt, pallas};
 use pasta_curves::{arithmetic::FieldExt, pallas};

+ 3 - 6
src/rpc/jsonrpc.rs

@@ -154,11 +154,8 @@ pub async fn send_raw_request(url: &str, data: Value) -> Result<JsonResult, Erro
     match parsed_url.scheme() {
     match parsed_url.scheme() {
         "tcp" => use_tls = false,
         "tcp" => use_tls = false,
         "tls" => use_tls = true,
         "tls" => use_tls = true,
-        scheme => {
-            return Err(Error::UrlParseError(format!(
-                "Invalid scheme `{}` found in `{}`",
-                scheme, parsed_url
-            )))
+        _ => {
+            return Err(Error::UrlParseError)
         }
         }
     }
     }
 
 
@@ -171,7 +168,7 @@ pub async fn send_raw_request(url: &str, data: Value) -> Result<JsonResult, Erro
         smol::unblock(move || (host.as_str(), port).to_socket_addrs())
         smol::unblock(move || (host.as_str(), port).to_socket_addrs())
             .await?
             .await?
             .next()
             .next()
-            .ok_or(Error::NoUrlFound)?
+            .ok_or(Error::UrlParseError)?
     };
     };
 
 
     let mut buf = [0; 2048];
     let mut buf = [0; 2048];

+ 4 - 7
src/rpc/websockets.rs

@@ -65,18 +65,18 @@ pub async fn connect(addr: &str, tls: TlsConnector) -> DrkResult<(WsStream, Resp
     let url = Url::parse(addr)?;
     let url = Url::parse(addr)?;
     let host = url
     let host = url
         .host_str()
         .host_str()
-        .ok_or(Error::UrlParseError(format!("Missing Host in {}", url)))?
+        .ok_or(Error::UrlParseError)?
         .to_string();
         .to_string();
     let port = url
     let port = url
         .port_or_known_default()
         .port_or_known_default()
-        .ok_or_else(|| Error::UrlParseError(format!("Missing port in {}", url)))?;
+        .ok_or_else(|| Error::UrlParseError)?;
 
 
     let socket_addr = {
     let socket_addr = {
         let host = host.clone();
         let host = host.clone();
         smol::unblock(move || (host.as_str(), port).to_socket_addrs())
         smol::unblock(move || (host.as_str(), port).to_socket_addrs())
             .await?
             .await?
             .next()
             .next()
-            .ok_or(Error::NoUrlFound)?
+            .ok_or(Error::UrlParseError)?
     };
     };
 
 
     match url.scheme() {
     match url.scheme() {
@@ -91,9 +91,6 @@ pub async fn connect(addr: &str, tls: TlsConnector) -> DrkResult<(WsStream, Resp
             let (stream, resp) = async_tungstenite::client_async(addr, stream).await?;
             let (stream, resp) = async_tungstenite::client_async(addr, stream).await?;
             Ok((WsStream::Tls(stream), resp))
             Ok((WsStream::Tls(stream), resp))
         }
         }
-        scheme => Err(Error::UrlParseError(format!(
-            "Invalid url scheme `{}`, in `{}`",
-            scheme, url
-        ))),
+        scheme => Err(Error::UrlParseError),
     }
     }
 }
 }

+ 29 - 8
src/service/btc.rs

@@ -841,24 +841,45 @@ impl Decodable for Keypair {
     }
     }
 }
 }
 
 
-#[derive(Debug, Clone, thiserror::Error)]
+#[derive(Debug, Clone)]
 pub enum BtcFailed {
 pub enum BtcFailed {
-    #[error("There is no enough value {0}")]
     NotEnoughValue(u64),
     NotEnoughValue(u64),
-    #[error("could not parse BTC address: {0}")]
     BadBtcAddress(String),
     BadBtcAddress(String),
-    #[error("Unable to create Electrum Client: {0}")]
     ElectrumError(String),
     ElectrumError(String),
-    #[error("BtcFailed: {0}")]
     BtcError(String),
     BtcError(String),
-    #[error("Decode and decode keys error: {0}")]
     DecodeAndEncodeError(String),
     DecodeAndEncodeError(String),
-    #[error("Keypair error from Secp256k1:  {0}")]
     KeypairError(String),
     KeypairError(String),
-    #[error("Received Notification Error: {0}")]
     Notification(String),
     Notification(String),
 }
 }
 
 
+impl std::error::Error for BtcFailed {}
+
+impl std::fmt::Display for BtcFailed {
+    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+        match self {
+            BtcFailed::NotEnoughValue(i) => {
+                write!(f, "There is no enough value {}", i)
+            }
+            BtcFailed::BadBtcAddress(ref err) => {
+                write!(f, "Unable to create Electrum Client: {}", err)
+            }
+            BtcFailed::ElectrumError(ref err) => write!(f, "could not parse BTC address: {}", err),
+            BtcFailed::DecodeAndEncodeError(ref err) => {
+                write!(f, "Decode and decode keys error: {}", err)
+            }
+            BtcFailed::KeypairError(ref err) => {
+                write!(f, "Keypair error from Secp256k1: {}", err)
+            }
+            BtcFailed::Notification(i) => {
+                write!(f, "Received Notification Error: {}", i)
+            }
+            BtcFailed::BtcError(i) => {
+                write!(f, "BtcFailed: {}", i)
+            }
+        }
+    }
+}
+
 impl From<crate::error::Error> for BtcFailed {
 impl From<crate::error::Error> for BtcFailed {
     fn from(err: crate::error::Error) -> BtcFailed {
     fn from(err: crate::error::Error) -> BtcFailed {
         BtcFailed::BtcError(err.to_string())
         BtcFailed::BtcError(err.to_string())

+ 1 - 3
src/service/eth.rs

@@ -201,7 +201,6 @@ impl EthClient {
             notify_channel,
             notify_channel,
         })
         })
         }
         }
-    }
 
 
     async fn send_eth_to_main_wallet(&self, acc: &str, amount: BigUint) -> Result<()> {
     async fn send_eth_to_main_wallet(&self, acc: &str, amount: BigUint) -> Result<()> {
         debug!(target: "ETH BRIDGE", "Send eth to main wallet");
         debug!(target: "ETH BRIDGE", "Send eth to main wallet");
@@ -287,8 +286,7 @@ impl EthClient {
             .await?;
             .await?;
 
 
         debug!(target: "ETH BRIDGE", "Received {} eth", received_balance_ui );
         debug!(target: "ETH BRIDGE", "Received {} eth", received_balance_ui );
-        }
-
+        
         Ok(())
         Ok(())
     }
     }
 
 

+ 2 - 2
src/service/gateway.rs

@@ -185,7 +185,7 @@ impl GatewayClient {
         let addr_sock = (addr.host().unwrap().to_string(), addr.port().unwrap())
         let addr_sock = (addr.host().unwrap().to_string(), addr.port().unwrap())
             .to_socket_addrs()?
             .to_socket_addrs()?
             .next()
             .next()
-            .ok_or(Error::NoUrlFound)?;
+            .ok_or(Error::UrlParseError)?;
         let protocol = ReqProtocol::new(addr_sock, String::from("GATEWAY CLIENT"));
         let protocol = ReqProtocol::new(addr_sock, String::from("GATEWAY CLIENT"));
 
 
         let slabstore = SlabStore::new(rocks)?;
         let slabstore = SlabStore::new(rocks)?;
@@ -198,7 +198,7 @@ impl GatewayClient {
         )
         )
             .to_socket_addrs()?
             .to_socket_addrs()?
             .next()
             .next()
-            .ok_or(Error::NoUrlFound)?;
+            .ok_or(Error::UrlParseError)?;
 
 
         Ok(GatewayClient {
         Ok(GatewayClient {
             protocol,
             protocol,

+ 87 - 23
src/service/sol.rs

@@ -178,7 +178,7 @@ impl SolClient {
             let message = read
             let message = read
                 .next()
                 .next()
                 .await
                 .await
-                .ok_or_else(|| Error::TungsteniteError("No more messages".to_string()))?;
+                .ok_or_else(|| Error::TungsteniteError)?;
             let message = message?;
             let message = message?;
 
 
             if let Message::Pong(_) = message.clone() {
             if let Message::Pong(_) = message.clone() {
@@ -613,36 +613,100 @@ impl Decodable for Pubkey {
     }
     }
 }
 }
 
 
-#[derive(Debug, thiserror::Error)]
+#[derive(Debug)]
 pub enum SolFailed {
 pub enum SolFailed {
-    #[error("There is no enough value `{0}`")]
     NotEnoughValue(u64),
     NotEnoughValue(u64),
-    #[error("Main Account Has no enough value")]
     MainAccountNotEnoughValue,
     MainAccountNotEnoughValue,
-    #[error("Bad Sol Address: `{0}`")]
     BadSolAddress(String),
     BadSolAddress(String),
-    #[error("Decode and decode keys error: `{0}`")]
     DecodeAndEncodeError(String),
     DecodeAndEncodeError(String),
-    #[error(transparent)]
-    WebSocketError(#[from] tungstenite::Error),
-    #[error("RpcError: `{0}`")]
+    WebSocketError(String),
     RpcError(String),
     RpcError(String),
-    #[error(transparent)]
-    SolClientError(#[from] solana_client::client_error::ClientError),
-    #[error("Received Notification Error: `{0}`")]
+    SolClientError(String),
     Notification(String),
     Notification(String),
-    #[error(transparent)]
-    ProgramError(#[from] solana_sdk::program_error::ProgramError),
-    #[error("Given mint is not valid: `{0}`")]
+    ProgramError(String),
     MintIsNotValid(String),
     MintIsNotValid(String),
-    #[error(transparent)]
-    JsonError(#[from] serde_json::Error),
-    #[error(transparent)]
-    ParseError(#[from] solana_sdk::pubkey::ParsePubkeyError),
-    #[error("Signature Error: `{0}`")]
-    Signature(String),
-    #[error(transparent)]
-    Darkfi(#[from] crate::error::Error),
+    JsonError(String),
+    ParseError(String),
+}
+
+impl std::error::Error for SolFailed {}
+
+impl std::fmt::Display for SolFailed {
+    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+        match self {
+            SolFailed::NotEnoughValue(i) => {
+                write!(f, "There is no enough value {}", i)
+            }
+            SolFailed::MainAccountNotEnoughValue => {
+                write!(f, "Main Account Has no enough value")
+            }
+            SolFailed::BadSolAddress(ref err) => {
+                write!(f, "Bad Sol Address: {}", err)
+            }
+            SolFailed::DecodeAndEncodeError(ref err) => {
+                write!(f, "Decode and decode keys error: {}", err)
+            }
+            SolFailed::WebSocketError(i) => {
+                write!(f, "WebSocket Error: {}", i)
+            }
+            SolFailed::RpcError(i) => {
+                write!(f, "Rpc Error: {}", i)
+            }
+            SolFailed::ParseError(i) => {
+                write!(f, "Parse Error: {}", i)
+            }
+            SolFailed::SolClientError(i) => {
+                write!(f, "Solana Client Error: {}", i)
+            }
+            SolFailed::Notification(i) => {
+                write!(f, "Received Notification Error: {}", i)
+            }
+            SolFailed::ProgramError(i) => {
+                write!(f, "ProgramError Error: {}", i)
+            }
+            SolFailed::MintIsNotValid(i) => {
+                write!(f, "Given mint is not valid: {}", i)
+            }
+            SolFailed::JsonError(i) => {
+                write!(f, "JsonError: {}", i)
+            }
+        }
+    }
+}
+
+impl From<solana_sdk::pubkey::ParsePubkeyError> for SolFailed {
+    fn from(err: solana_sdk::pubkey::ParsePubkeyError) -> SolFailed {
+        SolFailed::ParseError(err.to_string())
+    }
+}
+
+impl From<tungstenite::Error> for SolFailed {
+    fn from(err: tungstenite::Error) -> SolFailed {
+        SolFailed::WebSocketError(err.to_string())
+    }
+}
+
+impl From<solana_client::client_error::ClientError> for SolFailed {
+    fn from(err: solana_client::client_error::ClientError) -> SolFailed {
+        SolFailed::SolClientError(err.to_string())
+    }
+}
+
+impl From<solana_sdk::program_error::ProgramError> for SolFailed {
+    fn from(err: solana_sdk::program_error::ProgramError) -> SolFailed {
+        SolFailed::ProgramError(err.to_string())
+    }
+}
+
+impl From<crate::error::Error> for SolFailed {
+    fn from(err: crate::error::Error) -> SolFailed {
+        SolFailed::SolClientError(err.to_string())
+    }
+}
+impl From<serde_json::Error> for SolFailed {
+    fn from(err: serde_json::Error) -> SolFailed {
+        SolFailed::JsonError(err.to_string())
+    }
 }
 }
 
 
 pub type SolResult<T> = std::result::Result<T, SolFailed>;
 pub type SolResult<T> = std::result::Result<T, SolFailed>;

+ 1 - 10
src/state.rs

@@ -28,25 +28,16 @@ pub struct StateUpdate {
 
 
 pub type VerifyResult<T> = std::result::Result<T, VerifyFailed>;
 pub type VerifyResult<T> = std::result::Result<T, VerifyFailed>;
 
 
-#[derive(Debug, Clone, thiserror::Error)]
+#[derive(Debug, Clone)]
 pub enum VerifyFailed {
 pub enum VerifyFailed {
-    #[error("Invalid cashier public key for clear input {0}")]
     InvalidCashierKey(usize),
     InvalidCashierKey(usize),
-    #[error("Invalid merkle root for input {0}")]
     InvalidMerkle(usize),
     InvalidMerkle(usize),
-    #[error("Duplicate nullifier for input {0}")]
     DuplicateNullifier(usize),
     DuplicateNullifier(usize),
-    #[error("Spend proof for input {0}")]
     SpendProof(usize),
     SpendProof(usize),
-    #[error("Mint proof for input {0}")]
     MintProof(usize),
     MintProof(usize),
-    #[error("Invalid signature for clear input {0}")]
     ClearInputSignature(usize),
     ClearInputSignature(usize),
-    #[error("Invalid signature for input {0}")]
     InputSignature(usize),
     InputSignature(usize),
-    #[error("Money in does not match money out (value commits)")]
     MissingFunds,
     MissingFunds,
-    #[error("Assets don't match some inputs or outputs (token commits)")]
     AssetMismatch,
     AssetMismatch,
 }
 }
 
 

+ 1 - 1
src/util/token_list.rs

@@ -67,7 +67,7 @@ impl DrkTokenList {
 
 
         let mut tokens: HashMap<String, DrkTokenId> = sol_symbols
         let mut tokens: HashMap<String, DrkTokenId> = sol_symbols
             .iter()
             .iter()
-            .filter_map(|symbol| Self::generate_hash_pair(sol_list, symbol).ok())
+            .filter_map(|symbol| Self::generate_hash_pair(&sol_list, symbol).ok())
         .collect();
         .collect();
 
 
          tokens.insert(
          tokens.insert(