Skip to content

Commit

Permalink
Merge pull request #136 from kinode-dao/develop
Browse files Browse the repository at this point in the history
develop 1.0.1
  • Loading branch information
nick1udwig authored Feb 8, 2025
2 parents 4226321 + 53a2e16 commit cf91c7f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "kinode_process_lib"
authors = ["Sybil Technologies AG"]
version = "1.0.0"
version = "1.0.1"
edition = "2021"
description = "A library for writing Kinode processes in Rust."
homepage = "https://kinode.org"
Expand All @@ -17,6 +17,7 @@ alloy-sol-macro = "0.8.15"
alloy-sol-types = "0.8.15"
alloy = { version = "0.8.1", features = [
"json-rpc",
"rpc-client",
"rpc-types",
] }
anyhow = "1.0"
Expand Down
67 changes: 65 additions & 2 deletions src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub use alloy::rpc::types::{
Block, BlockId, BlockNumberOrTag, FeeHistory, Filter, FilterBlockOption, Log, Transaction,
TransactionReceipt,
};
pub use alloy::transports::Authorization as AlloyAuthorization;
pub use alloy_primitives::{Address, BlockHash, BlockNumber, Bytes, TxHash, U128, U256, U64, U8};
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -220,23 +221,85 @@ pub struct ProviderConfig {
}

#[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
pub enum Authorization {
Basic(String),
Bearer(String),
Raw(String),
}

impl From<Authorization> for AlloyAuthorization {
fn from(auth: Authorization) -> AlloyAuthorization {
match auth {
Authorization::Basic(value) => AlloyAuthorization::Basic(value),
Authorization::Bearer(value) => AlloyAuthorization::Bearer(value),
Authorization::Raw(value) => AlloyAuthorization::Raw(value),
}
}
}

#[derive(Clone, Debug, Serialize, Hash, Eq, PartialEq)]
pub enum NodeOrRpcUrl {
Node {
kns_update: crate::net::KnsUpdate,
use_as_provider: bool, // false for just-routers inside saved config
},
RpcUrl(String),
RpcUrl {
url: String,
auth: Option<Authorization>,
},
}

impl std::cmp::PartialEq<str> for NodeOrRpcUrl {
fn eq(&self, other: &str) -> bool {
match self {
NodeOrRpcUrl::Node { kns_update, .. } => kns_update.name == other,
NodeOrRpcUrl::RpcUrl(url) => url == other,
NodeOrRpcUrl::RpcUrl { url, .. } => url == other,
}
}
}

impl<'de> Deserialize<'de> for NodeOrRpcUrl {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(untagged)]
enum RpcUrlHelper {
String(String),
Struct {
url: String,
auth: Option<Authorization>,
},
}

#[derive(Deserialize)]
enum Helper {
Node {
kns_update: crate::net::KnsUpdate,
use_as_provider: bool,
},
RpcUrl(RpcUrlHelper),
}

let helper = Helper::deserialize(deserializer)?;

Ok(match helper {
Helper::Node {
kns_update,
use_as_provider,
} => NodeOrRpcUrl::Node {
kns_update,
use_as_provider,
},
Helper::RpcUrl(url_helper) => match url_helper {
RpcUrlHelper::String(url) => NodeOrRpcUrl::RpcUrl { url, auth: None },
RpcUrlHelper::Struct { url, auth } => NodeOrRpcUrl::RpcUrl { url, auth },
},
})
}
}

/// An EVM chain provider. Create this object to start making RPC calls.
/// Set the chain_id to determine which chain to call: requests will fail
/// unless the node this process is running on has access to a provider
Expand Down

0 comments on commit cf91c7f

Please sign in to comment.