@@ -7,6 +7,11 @@ pub use alloy_rpc_types::{
77 TransactionReceipt ,
88} ;
99use serde:: { Deserialize , Serialize } ;
10+ use std:: collections:: HashSet ;
11+
12+ //
13+ // types mirrored from runtime module
14+ //
1015
1116/// The Action and Request type that can be made to eth:distro:sys. Any process with messaging
1217/// capabilities can send this action to the eth provider.
@@ -32,13 +37,13 @@ pub enum EthAction {
3237 } ,
3338}
3439
35- /// Incoming Result type for subscription updates or errors that processes will receive.
40+ /// Incoming `Request` containing subscription updates or errors that processes will receive.
3641/// Can deserialize all incoming requests from eth:distro:sys to this type.
3742///
3843/// Will be serialized and deserialized using `serde_json::to_vec` and `serde_json::from_slice`.
3944pub type EthSubResult = Result < EthSub , EthSubError > ;
4045
41- /// Incoming Request type for successful subscription updates.
46+ /// Incoming type for successful subscription updates.
4247#[ derive( Debug , Serialize , Deserialize ) ]
4348pub struct EthSub {
4449 pub id : u64 ,
@@ -55,6 +60,9 @@ pub struct EthSubError {
5560/// The Response type which a process will get from requesting with an [`EthAction`] will be
5661/// of this type, serialized and deserialized using `serde_json::to_vec`
5762/// and `serde_json::from_slice`.
63+ ///
64+ /// In the case of an [`EthAction::SubscribeLogs`] request, the response will indicate if
65+ /// the subscription was successfully created or not.
5866#[ derive( Debug , Serialize , Deserialize ) ]
5967pub enum EthResponse {
6068 Ok ,
@@ -64,22 +72,16 @@ pub enum EthResponse {
6472
6573#[ derive( Debug , Serialize , Deserialize ) ]
6674pub enum EthError {
75+ /// provider module cannot parse message
76+ MalformedRequest ,
6777 /// No RPC provider for the chain
6878 NoRpcForChain ,
69- /// Underlying transport error
70- TransportError ( String ) ,
7179 /// Subscription closed
7280 SubscriptionClosed ( u64 ) ,
73- /// The subscription ID was not found, so we couldn't unsubscribe.
74- SubscriptionNotFound ,
7581 /// Invalid method
7682 InvalidMethod ( String ) ,
77- /// Invalid params
78- InvalidParams ,
7983 /// Permission denied
8084 PermissionDenied ,
81- /// Internal RPC error
82- RpcError ( String ) ,
8385 /// RPC timed out
8486 RpcTimeout ,
8587}
@@ -111,20 +113,34 @@ pub enum EthConfigAction {
111113 /// Set the list of providers to a new list.
112114 /// Replaces all existing saved provider configs.
113115 SetProviders ( SavedConfigs ) ,
114- /// Get the list of as a [`SavedConfigs`] object.
116+ /// Get the list of current providers as a [`SavedConfigs`] object.
115117 GetProviders ,
118+ /// Get the current access settings.
119+ GetAccessSettings ,
116120}
117121
118122/// Response type from an [`EthConfigAction`] request.
119123#[ derive( Debug , Serialize , Deserialize ) ]
120124pub enum EthConfigResponse {
121125 Ok ,
122126 /// Response from a GetProviders request.
127+ /// Note the [`crate::kernel_types::KnsUpdate`] will only have the correct `name` field.
128+ /// The rest of the Update is not saved in this module.
123129 Providers ( SavedConfigs ) ,
130+ /// Response from a GetAccessSettings request.
131+ AccessSettings ( AccessSettings ) ,
124132 /// Permission denied due to missing capability
125133 PermissionDenied ,
126134}
127135
136+ /// Settings for our ETH provider
137+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
138+ pub struct AccessSettings {
139+ pub public : bool , // whether or not other nodes can access through us
140+ pub allow : HashSet < String > , // whitelist for access (only used if public == false)
141+ pub deny : HashSet < String > , // blacklist for access (always used)
142+ }
143+
128144pub type SavedConfigs = Vec < ProviderConfig > ;
129145
130146/// Provider config. Can currently be a node or a ws provider instance.
@@ -141,6 +157,15 @@ pub enum NodeOrRpcUrl {
141157 RpcUrl ( String ) ,
142158}
143159
160+ impl std:: cmp:: PartialEq < str > for NodeOrRpcUrl {
161+ fn eq ( & self , other : & str ) -> bool {
162+ match self {
163+ NodeOrRpcUrl :: Node ( kns) => kns. name == other,
164+ NodeOrRpcUrl :: RpcUrl ( url) => url == other,
165+ }
166+ }
167+ }
168+
144169/// An EVM chain provider. Create this object to start making RPC calls.
145170/// Set the chain_id to determine which chain to call: requests will fail
146171/// unless the node this process is running on has access to a provider
0 commit comments