Skip to content

Commit cf91c7f

Browse files
authored
Merge pull request #136 from kinode-dao/develop
develop 1.0.1
2 parents 4226321 + 53a2e16 commit cf91c7f

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "kinode_process_lib"
33
authors = ["Sybil Technologies AG"]
4-
version = "1.0.0"
4+
version = "1.0.1"
55
edition = "2021"
66
description = "A library for writing Kinode processes in Rust."
77
homepage = "https://kinode.org"
@@ -17,6 +17,7 @@ alloy-sol-macro = "0.8.15"
1717
alloy-sol-types = "0.8.15"
1818
alloy = { version = "0.8.1", features = [
1919
"json-rpc",
20+
"rpc-client",
2021
"rpc-types",
2122
] }
2223
anyhow = "1.0"

src/eth.rs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use alloy::rpc::types::{
77
Block, BlockId, BlockNumberOrTag, FeeHistory, Filter, FilterBlockOption, Log, Transaction,
88
TransactionReceipt,
99
};
10+
pub use alloy::transports::Authorization as AlloyAuthorization;
1011
pub use alloy_primitives::{Address, BlockHash, BlockNumber, Bytes, TxHash, U128, U256, U64, U8};
1112
use serde::{Deserialize, Serialize};
1213
use std::collections::{HashMap, HashSet};
@@ -220,23 +221,85 @@ pub struct ProviderConfig {
220221
}
221222

222223
#[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
224+
pub enum Authorization {
225+
Basic(String),
226+
Bearer(String),
227+
Raw(String),
228+
}
229+
230+
impl From<Authorization> for AlloyAuthorization {
231+
fn from(auth: Authorization) -> AlloyAuthorization {
232+
match auth {
233+
Authorization::Basic(value) => AlloyAuthorization::Basic(value),
234+
Authorization::Bearer(value) => AlloyAuthorization::Bearer(value),
235+
Authorization::Raw(value) => AlloyAuthorization::Raw(value),
236+
}
237+
}
238+
}
239+
240+
#[derive(Clone, Debug, Serialize, Hash, Eq, PartialEq)]
223241
pub enum NodeOrRpcUrl {
224242
Node {
225243
kns_update: crate::net::KnsUpdate,
226244
use_as_provider: bool, // false for just-routers inside saved config
227245
},
228-
RpcUrl(String),
246+
RpcUrl {
247+
url: String,
248+
auth: Option<Authorization>,
249+
},
229250
}
230251

231252
impl std::cmp::PartialEq<str> for NodeOrRpcUrl {
232253
fn eq(&self, other: &str) -> bool {
233254
match self {
234255
NodeOrRpcUrl::Node { kns_update, .. } => kns_update.name == other,
235-
NodeOrRpcUrl::RpcUrl(url) => url == other,
256+
NodeOrRpcUrl::RpcUrl { url, .. } => url == other,
236257
}
237258
}
238259
}
239260

261+
impl<'de> Deserialize<'de> for NodeOrRpcUrl {
262+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
263+
where
264+
D: serde::Deserializer<'de>,
265+
{
266+
#[derive(Deserialize)]
267+
#[serde(untagged)]
268+
enum RpcUrlHelper {
269+
String(String),
270+
Struct {
271+
url: String,
272+
auth: Option<Authorization>,
273+
},
274+
}
275+
276+
#[derive(Deserialize)]
277+
enum Helper {
278+
Node {
279+
kns_update: crate::net::KnsUpdate,
280+
use_as_provider: bool,
281+
},
282+
RpcUrl(RpcUrlHelper),
283+
}
284+
285+
let helper = Helper::deserialize(deserializer)?;
286+
287+
Ok(match helper {
288+
Helper::Node {
289+
kns_update,
290+
use_as_provider,
291+
} => NodeOrRpcUrl::Node {
292+
kns_update,
293+
use_as_provider,
294+
},
295+
Helper::RpcUrl(url_helper) => match url_helper {
296+
RpcUrlHelper::String(url) => NodeOrRpcUrl::RpcUrl { url, auth: None },
297+
RpcUrlHelper::Struct { url, auth } => NodeOrRpcUrl::RpcUrl { url, auth },
298+
},
299+
})
300+
}
301+
}
302+
240303
/// An EVM chain provider. Create this object to start making RPC calls.
241304
/// Set the chain_id to determine which chain to call: requests will fail
242305
/// unless the node this process is running on has access to a provider

0 commit comments

Comments
 (0)