Skip to content

Commit

Permalink
feat(blueprint-sdk): sdk error (#602)
Browse files Browse the repository at this point in the history
* feat(blueprint-sdk): sdk error

* feat(blueprint-sdk): easy alloy error conversion

* fix(blueprint-sdk): export error

* feat(blueprint-sdk): sdk error

* feat(blueprint-sdk): easy alloy error conversion

* fix(blueprint-sdk): general error variant

* chore(clippy): fmt

* fix(blueprint-sdk): redundant mod
  • Loading branch information
Tjemmmic authored Jan 24, 2025
1 parent 713667f commit 928299e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion crates/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ gadget-stores = { workspace = true, optional = true }
tangle-subxt = { workspace = true, optional = true }

# EigenLayer and EVM
alloy = { workspace = true, optional = true }
alloy = { workspace = true, optional = true, features = ["full"] }
alloy-json-abi = { workspace = true, optional = true, features = ["serde_json"] }
eigensdk = { workspace = true, optional = true, features = ["full"] }

# Error Handling
thiserror = { workspace = true }

# Serialization
serde = { workspace = true, features = ["derive"] }

Expand Down Expand Up @@ -89,6 +92,7 @@ tangle = [
"gadget-macros?/tangle",
"gadget-testing-utils?/tangle",
"gadget-utils/tangle",
"gadget-event-listeners/tangle"
]

evm = [
Expand All @@ -97,6 +101,7 @@ evm = [
"alloy",
"alloy-json-abi",
"gadget-macros?/evm",
"gadget-event-listeners/evm"
]

eigenlayer = [
Expand All @@ -107,6 +112,7 @@ eigenlayer = [
"alloy",
"alloy-json-abi",
"eigensdk",
"gadget-event-listeners/evm"
]

testing = [
Expand Down
75 changes: 75 additions & 0 deletions crates/sdk/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use super::{config, keystore};

#[cfg(any(feature = "evm", feature = "eigenlayer", feature = "tangle"))]
use super::event_listeners;

#[derive(thiserror::Error, Debug)]
pub enum Error {
// General Errors
#[error("Config error: {0}")]
Config(#[from] config::Error),
#[error("Keystore error: {0}")]
Keystore(#[from] keystore::Error),
#[error("Other Error: {0}")]
Other(String),

// Specific to Tangle
#[cfg(feature = "tangle")]
#[error("Event listener error: {0}")]
TangleEvent(
#[from]
event_listeners::core::Error<event_listeners::tangle::error::TangleEventListenerError>,
),
#[cfg(feature = "tangle")]
#[error("Tangle Subxt error: {0}")]
TangleSubxt(#[from] tangle_subxt::subxt::Error),

// EVM and EigenLayer
#[cfg(any(feature = "evm", feature = "eigenlayer"))]
#[error("Event listener error: {0}")]
EvmEvent(#[from] event_listeners::core::Error<event_listeners::evm::error::Error>),
#[cfg(any(feature = "evm", feature = "eigenlayer"))]
#[error("EVM error: {0}")]
Alloy(#[from] AlloyError),
#[cfg(feature = "eigenlayer")]
#[error("Eigenlayer error: {0}")]
Eigenlayer(#[from] eigensdk::types::avs::SignatureVerificationError),

// Specific to Networking
#[cfg(feature = "networking")]
#[error("Networking error: {0}")]
Networking(#[from] gadget_networking::Error),
}

#[cfg(any(feature = "evm", feature = "eigenlayer"))]
#[derive(thiserror::Error, Debug)]
pub enum AlloyError {
#[error("Alloy signer error: {0}")]
Signer(#[from] alloy::signers::Error),
#[error("Alloy contract error: {0}")]
Contract(#[from] alloy::contract::Error),
#[error("Alloy transaction error: {0}")]
Conversion(#[from] alloy::rpc::types::transaction::ConversionError),
#[error("Alloy local signer error: {0}")]
LocalSigner(#[from] alloy::signers::local::LocalSignerError),
}

#[cfg(any(feature = "evm", feature = "eigenlayer"))]
macro_rules! implement_from_alloy_error {
($($path:ident)::+, $variant:ident) => {
impl From<alloy::$($path)::+> for Error {
fn from(value: alloy::$($path)::+) -> Self {
Error::Alloy(AlloyError::$variant(value))
}
}
};
}

#[cfg(any(feature = "evm", feature = "eigenlayer"))]
implement_from_alloy_error!(signers::Error, Signer);
#[cfg(any(feature = "evm", feature = "eigenlayer"))]
implement_from_alloy_error!(contract::Error, Contract);
#[cfg(any(feature = "evm", feature = "eigenlayer"))]
implement_from_alloy_error!(rpc::types::transaction::ConversionError, Conversion);
#[cfg(any(feature = "evm", feature = "eigenlayer"))]
implement_from_alloy_error!(signers::local::LocalSignerError, LocalSigner);
4 changes: 4 additions & 0 deletions crates/sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,9 @@ pub use gadget_std as std;
pub use serde;
pub use tokio;

/// Error
pub mod error;
pub use error::Error;

#[cfg(feature = "local-store")]
pub use gadget_stores as stores;

0 comments on commit 928299e

Please sign in to comment.