diff --git a/Cargo.lock b/Cargo.lock index a04d3d57a..b4c210b65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3074,6 +3074,7 @@ dependencies = [ "aes-gcm", "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "alloy-contract", + "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "alloy-network", "alloy-primitives 0.6.4", "alloy-providers", @@ -3291,6 +3292,7 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" name = "lib" version = "0.8.0" dependencies = [ + "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "anyhow", "kit", diff --git a/kinode/Cargo.toml b/kinode/Cargo.toml index 929f6d429..85592d1cd 100644 --- a/kinode/Cargo.toml +++ b/kinode/Cargo.toml @@ -30,6 +30,7 @@ alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" } alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" } alloy-pubsub = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" } alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" } +alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" } alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4", features = ["ws"]} alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" } alloy-providers = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" } diff --git a/kinode/src/eth/mod.rs b/kinode/src/eth/mod.rs index bee8c092a..b2a22ad3c 100644 --- a/kinode/src/eth/mod.rs +++ b/kinode/src/eth/mod.rs @@ -1,3 +1,4 @@ +use alloy_json_rpc::RpcError; use alloy_providers::provider::Provider; use alloy_pubsub::PubSubFrontend; use alloy_rpc_client::ClientBuilder; @@ -618,6 +619,10 @@ async fn fulfill_request( return EthResponse::Response { value }; } Err(rpc_error) => { + // if rpc_error is of type ErrResponse, return to user! + if let RpcError::ErrorResp(err) = rpc_error { + return EthResponse::Err(EthError::RpcError(err)); + } verbose_print( print_tx, &format!( @@ -651,7 +656,7 @@ async fn fulfill_request( ) .await; if let EthResponse::Err(e) = response { - if e == EthError::RpcMalformedResponse { + if let EthError::RpcMalformedResponse = e { node_provider.usable = false; } } else { diff --git a/kinode/src/eth/subscription.rs b/kinode/src/eth/subscription.rs index 92b1d2e13..c00718574 100644 --- a/kinode/src/eth/subscription.rs +++ b/kinode/src/eth/subscription.rs @@ -287,7 +287,7 @@ async fn build_subscription( node_provider.usable = false; } EthResponse::Err(e) => { - if e == EthError::RpcMalformedResponse { + if let EthError::RpcMalformedResponse = e { node_provider.usable = false; } } diff --git a/lib/Cargo.toml b/lib/Cargo.toml index ab1c80164..2c9ebccf4 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -18,6 +18,7 @@ tokio = "1.28" [dependencies] alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" } +alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" } lazy_static = "1.4.0" rand = "0.8.4" ring = "0.17.8" diff --git a/lib/src/eth.rs b/lib/src/eth.rs index 6d449be53..16ec46601 100644 --- a/lib/src/eth.rs +++ b/lib/src/eth.rs @@ -1,3 +1,4 @@ +use alloy_json_rpc::ErrorPayload; use alloy_rpc_types::pubsub::{Params, SubscriptionKind, SubscriptionResult}; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; @@ -59,8 +60,10 @@ pub enum EthResponse { Err(EthError), } -#[derive(Debug, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Serialize, Deserialize)] pub enum EthError { + /// RPC provider returned an error + RpcError(ErrorPayload), /// provider module cannot parse message MalformedRequest, /// No RPC provider for the chain