10bf70b22b
* Remove check for bandwidth for incoming packets We should only accunt for packets that the client inputs to the mixnet * Introduce BandwidthController for both types of bandwidth creds * Add some non-coconut token bandwidth handling * Use thiserror for gateway-client lib * Add error handling * Unable to build for wasm for now * Fix wasm strange error * Disable non-coconut credentials for wasm client * Check for status and throw the error up * Send encrypted token cred from client * Gateway receive message and signature validation * Put the correct amount of tokens that were burned * [ci skip] Generate TS types * Eth endpoint and secret key as config parameters * Add eth_endpoint config argument for gateway * Update test as well * Separate panicable code from the safe one * Move some bandwidth controller panics up the call stack * Save contract corresponding to the eth endpoint * Fix template * Pass the web3 interface as well * Made event reads possible in gateway * Add checks for event data * Cosmos contract for double spending prevention * Add workflow for the new contract * Add validator rest URL to config * Rename eth_events to erc20_bridge * Pass cosmos mnemonic as well, and put the nymd client in ERC20Bridge * Call cosmos contract for final verification * Ask for config parameters in cli * Fix various stuff * Increase timeout to allow gateway to check the two chains * Put some logs for the new flow * Set consumed bandwidth invariantly of coconut feature * Fix clippy error * Add non-coconut checks * Use 2018 rust instead of 2021 * More verbose nymd error * Explicitly specify TOKENS_TO_BURN constant * Put eth burn function in a constant * Replace to_vec & append with iter & chain * Test for (de)serialization of TokenCredential * Minor rename * Separate credential creation from bandwidth claiming * Switch from panics to errors when claiming coconut bandwidth * Another append changed to chain * Update QA cosmos contract address * Simplify build/test/clippy separation on coconut feature * Fix bad features arg positioning * Use the start_after in cosmos contract query * Set a limit in line with a range on cosmos queries * Added unit tests for new cosmos contract * Fix bandwidth_remaining comparation * Get remaining bandwidth from gateway * Add contract build flag * Add a useful info log * Use a more robust eth depth for release builds * Include recipt logs in error message * Fix clippy for tests * Use Arc instead of clone * Rename as_bytes to to_bytes * Make signature verification in contract more verbose * Missed rename of paging constant * Fix gateway start with coconut enabled * Rename function to claim_token * Simplify nymd client setup * Check with block buffer on gateway as well * Update comment of double spending protection * Correct contract address * Backup the keypairs used for buying tokens, in case of error cases * Don't take any chances with the gateway timeout * [ci skip] Generate TS types * Updated cosmos contract to latest QA address * Add cli options for eth * Update network monitor timeout value as well Co-authored-by: neacsu <neacsu@users.noreply.github.com>
101 lines
2.9 KiB
Rust
101 lines
2.9 KiB
Rust
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use gateway_requests::registration::handshake::error::HandshakeError;
|
|
use std::io;
|
|
use thiserror::Error;
|
|
use tungstenite::Error as WsError;
|
|
#[cfg(target_arch = "wasm32")]
|
|
use wasm_bindgen::JsValue;
|
|
#[cfg(not(feature = "coconut"))]
|
|
use web3::Error as Web3Error;
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum GatewayClientError {
|
|
#[error("Connection to the gateway is not established")]
|
|
ConnectionNotEstablished,
|
|
|
|
#[error("Gateway returned an error response - {0}")]
|
|
GatewayError(String),
|
|
|
|
#[error("There was a network error - {0}")]
|
|
NetworkError(#[from] WsError),
|
|
|
|
// TODO: see if `JsValue` is a reasonable type for this
|
|
#[cfg(target_arch = "wasm32")]
|
|
#[error("There was a network error")]
|
|
NetworkErrorWasm(JsValue),
|
|
|
|
#[cfg(not(feature = "coconut"))]
|
|
#[error("Could not backup keypair - {0}")]
|
|
IOError(#[from] std::io::Error),
|
|
|
|
#[cfg(not(feature = "coconut"))]
|
|
#[error("Could not burn ERC20 token in Ethereum smart contract - {0}")]
|
|
BurnTokenError(#[from] Web3Error),
|
|
|
|
#[cfg(not(feature = "coconut"))]
|
|
#[error("Invalid Ethereum private key")]
|
|
InvalidEthereumPrivateKey,
|
|
|
|
#[error("Invalid URL - {0}")]
|
|
InvalidURL(String),
|
|
|
|
#[error("No shared key was provided or obtained")]
|
|
NoSharedKeyAvailable,
|
|
|
|
#[error("No bandwidth controller provided")]
|
|
NoBandwidthControllerAvailable,
|
|
|
|
#[error("Credential error - {0}")]
|
|
CredentialError(#[from] credentials::error::Error),
|
|
|
|
#[error("Connection was abruptly closed")]
|
|
ConnectionAbruptlyClosed,
|
|
|
|
#[error("Received response was malformed")]
|
|
MalformedResponse,
|
|
|
|
#[error("Credential could not be serialized")]
|
|
SerializeCredential,
|
|
|
|
#[error("Client is not authenticated")]
|
|
NotAuthenticated,
|
|
|
|
#[error("Client does not have enough bandwidth: estimated {0}, remaining: {1}")]
|
|
NotEnoughBandwidth(i64, i64),
|
|
|
|
#[error("Received an unexpected response")]
|
|
UnexpectedResponse,
|
|
|
|
#[error("Connection is in an invalid state - please send a bug report")]
|
|
ConnectionInInvalidState,
|
|
|
|
#[error("Failed to finish registration handshake - {0}")]
|
|
RegistrationFailure(HandshakeError),
|
|
|
|
#[error("Authentication failure")]
|
|
AuthenticationFailure,
|
|
|
|
#[error("Timed out")]
|
|
Timeout,
|
|
}
|
|
|
|
impl GatewayClientError {
|
|
pub fn is_closed_connection(&self) -> bool {
|
|
match self {
|
|
GatewayClientError::NetworkError(ws_err) => match ws_err {
|
|
WsError::AlreadyClosed | WsError::ConnectionClosed => true,
|
|
WsError::Io(io_err) => matches!(
|
|
io_err.kind(),
|
|
io::ErrorKind::ConnectionReset
|
|
| io::ErrorKind::ConnectionAborted
|
|
| io::ErrorKind::BrokenPipe
|
|
),
|
|
_ => false,
|
|
},
|
|
_ => false,
|
|
}
|
|
}
|
|
}
|