mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-08 16:23:12 +00:00
move common errors to own module. Remove unused ExecutionFailureKind variants
This commit is contained in:
parent
7d85424948
commit
93fd485622
59
common/src/error.rs
Normal file
59
common/src/error.rs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
use crate::rpc_primitives::errors::RpcError;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct SequencerRpcError {
|
||||||
|
pub jsonrpc: String,
|
||||||
|
pub error: RpcError,
|
||||||
|
pub id: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
pub enum SequencerClientError {
|
||||||
|
#[error("HTTP error")]
|
||||||
|
HTTPError(reqwest::Error),
|
||||||
|
#[error("Serde error")]
|
||||||
|
SerdeError(serde_json::Error),
|
||||||
|
#[error("Internal error")]
|
||||||
|
InternalError(SequencerRpcError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<reqwest::Error> for SequencerClientError {
|
||||||
|
fn from(value: reqwest::Error) -> Self {
|
||||||
|
SequencerClientError::HTTPError(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<serde_json::Error> for SequencerClientError {
|
||||||
|
fn from(value: serde_json::Error) -> Self {
|
||||||
|
SequencerClientError::SerdeError(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SequencerRpcError> for SequencerClientError {
|
||||||
|
fn from(value: SequencerRpcError) -> Self {
|
||||||
|
SequencerClientError::InternalError(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum ExecutionFailureKind {
|
||||||
|
#[error("Failed to get account data from sequencer")]
|
||||||
|
SequencerError,
|
||||||
|
#[error("Inputs amounts does not match outputs")]
|
||||||
|
AmountMismatchError,
|
||||||
|
#[error("Accounts key not found")]
|
||||||
|
KeyNotFoundError,
|
||||||
|
#[error("Sequencer client error: {0:?}")]
|
||||||
|
SequencerClientError(#[from] SequencerClientError),
|
||||||
|
#[error("Can not pay for operation")]
|
||||||
|
InsufficientFundsError,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum TransactionSignatureError {
|
||||||
|
#[error("invalid signature for transaction body")]
|
||||||
|
InvalidSignature,
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,98 +1,10 @@
|
|||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
pub mod block;
|
pub mod block;
|
||||||
pub mod rpc_primitives;
|
pub mod rpc_primitives;
|
||||||
pub mod sequencer_client;
|
pub mod sequencer_client;
|
||||||
pub mod transaction;
|
pub mod transaction;
|
||||||
|
pub mod error;
|
||||||
|
|
||||||
//Module for tests utility functions
|
//Module for tests utility functions
|
||||||
pub mod test_utils;
|
pub mod test_utils;
|
||||||
|
|
||||||
use rpc_primitives::errors::RpcError;
|
|
||||||
|
|
||||||
pub type HashType = [u8; 32];
|
pub type HashType = [u8; 32];
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
pub struct SequencerRpcError {
|
|
||||||
pub jsonrpc: String,
|
|
||||||
pub error: RpcError,
|
|
||||||
pub id: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
|
||||||
pub enum SequencerClientError {
|
|
||||||
#[error("HTTP error")]
|
|
||||||
HTTPError(reqwest::Error),
|
|
||||||
#[error("Serde error")]
|
|
||||||
SerdeError(serde_json::Error),
|
|
||||||
#[error("Internal error")]
|
|
||||||
InternalError(SequencerRpcError),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<reqwest::Error> for SequencerClientError {
|
|
||||||
fn from(value: reqwest::Error) -> Self {
|
|
||||||
SequencerClientError::HTTPError(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<serde_json::Error> for SequencerClientError {
|
|
||||||
fn from(value: serde_json::Error) -> Self {
|
|
||||||
SequencerClientError::SerdeError(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<SequencerRpcError> for SequencerClientError {
|
|
||||||
fn from(value: SequencerRpcError) -> Self {
|
|
||||||
SequencerClientError::InternalError(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
|
||||||
pub enum ExecutionFailureKind {
|
|
||||||
#[error("Failed to write into builder err: {0:?}")]
|
|
||||||
WriteError(anyhow::Error),
|
|
||||||
#[error("Failed to interact with a db err: {0:?}")]
|
|
||||||
DBError(anyhow::Error),
|
|
||||||
#[error("Failed to build builder err: {0:?}")]
|
|
||||||
BuilderError(anyhow::Error),
|
|
||||||
#[error("Failed prove execution err: {0:?}")]
|
|
||||||
ProveError(anyhow::Error),
|
|
||||||
#[error("Failed to decode data from VM: {0:?}")]
|
|
||||||
DecodeError(String),
|
|
||||||
#[error("Failed to get account data from sequencer")]
|
|
||||||
SequencerError,
|
|
||||||
#[error("Inputs amounts does not match outputs")]
|
|
||||||
AmountMismatchError,
|
|
||||||
#[error("Accounts key not found")]
|
|
||||||
KeyNotFoundError,
|
|
||||||
#[error("Sequencer client error: {0:?}")]
|
|
||||||
SequencerClientError(#[from] SequencerClientError),
|
|
||||||
#[error("Insufficient gas for operation")]
|
|
||||||
InsufficientGasError,
|
|
||||||
#[error("Can not pay for operation")]
|
|
||||||
InsufficientFundsError,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExecutionFailureKind {
|
|
||||||
pub fn write_error(err: anyhow::Error) -> Self {
|
|
||||||
Self::WriteError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn builder_error(err: anyhow::Error) -> Self {
|
|
||||||
Self::BuilderError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prove_error(err: anyhow::Error) -> Self {
|
|
||||||
Self::ProveError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn db_error(err: anyhow::Error) -> Self {
|
|
||||||
Self::DBError(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
|
||||||
pub enum TransactionSignatureError {
|
|
||||||
#[error("invalid signature for transaction body")]
|
|
||||||
InvalidSignature,
|
|
||||||
}
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ use crate::rpc_primitives::requests::{
|
|||||||
};
|
};
|
||||||
use crate::sequencer_client::json::AccountInitialData;
|
use crate::sequencer_client::json::AccountInitialData;
|
||||||
use crate::transaction::{EncodedTransaction, NSSATransaction};
|
use crate::transaction::{EncodedTransaction, NSSATransaction};
|
||||||
use crate::{SequencerClientError, SequencerRpcError};
|
use crate::error::{SequencerClientError, SequencerRpcError};
|
||||||
|
|
||||||
pub mod json;
|
pub mod json;
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use std::{fs::File, io::Write, path::PathBuf, str::FromStr, sync::Arc};
|
|||||||
|
|
||||||
use base64::{Engine, engine::general_purpose::STANDARD as BASE64};
|
use base64::{Engine, engine::general_purpose::STANDARD as BASE64};
|
||||||
use common::{
|
use common::{
|
||||||
ExecutionFailureKind,
|
error::ExecutionFailureKind,
|
||||||
sequencer_client::{SequencerClient, json::SendTxResponse},
|
sequencer_client::{SequencerClient, json::SendTxResponse},
|
||||||
transaction::{EncodedTransaction, NSSATransaction},
|
transaction::{EncodedTransaction, NSSATransaction},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use common::{ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
||||||
use nssa::{
|
use nssa::{
|
||||||
Address, PrivacyPreservingTransaction,
|
Address, PrivacyPreservingTransaction,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use common::{ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
||||||
use nssa::{
|
use nssa::{
|
||||||
Address, PrivacyPreservingTransaction,
|
Address, PrivacyPreservingTransaction,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use common::{ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use nssa::{
|
use nssa::{
|
||||||
Address, PublicTransaction,
|
Address, PublicTransaction,
|
||||||
program::Program,
|
program::Program,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use common::{ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
||||||
use nssa::{
|
use nssa::{
|
||||||
Account, Address, PrivacyPreservingTransaction,
|
Account, Address, PrivacyPreservingTransaction,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user