eth & kns: update kns to new process_lib

This commit is contained in:
bitful-pannul 2024-02-05 18:10:21 -03:00
parent 49ec4509b5
commit ae3a480c1f
6 changed files with 393 additions and 801 deletions

59
Cargo.lock generated
View File

@ -92,7 +92,7 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
[[package]] [[package]]
name = "alloy-eips" name = "alloy-eips"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-primitives", "alloy-primitives",
"alloy-rlp", "alloy-rlp",
@ -103,7 +103,7 @@ dependencies = [
[[package]] [[package]]
name = "alloy-json-rpc" name = "alloy-json-rpc"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-primitives", "alloy-primitives",
"serde", "serde",
@ -114,7 +114,7 @@ dependencies = [
[[package]] [[package]]
name = "alloy-network" name = "alloy-network"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-eips", "alloy-eips",
"alloy-json-rpc", "alloy-json-rpc",
@ -148,7 +148,7 @@ dependencies = [
[[package]] [[package]]
name = "alloy-providers" name = "alloy-providers"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-network", "alloy-network",
"alloy-primitives", "alloy-primitives",
@ -167,7 +167,7 @@ dependencies = [
[[package]] [[package]]
name = "alloy-pubsub" name = "alloy-pubsub"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-json-rpc", "alloy-json-rpc",
"alloy-primitives", "alloy-primitives",
@ -206,7 +206,7 @@ dependencies = [
[[package]] [[package]]
name = "alloy-rpc-client" name = "alloy-rpc-client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-json-rpc", "alloy-json-rpc",
"alloy-primitives", "alloy-primitives",
@ -227,7 +227,7 @@ dependencies = [
[[package]] [[package]]
name = "alloy-rpc-trace-types" name = "alloy-rpc-trace-types"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-primitives", "alloy-primitives",
"alloy-rpc-types", "alloy-rpc-types",
@ -238,7 +238,7 @@ dependencies = [
[[package]] [[package]]
name = "alloy-rpc-types" name = "alloy-rpc-types"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-primitives", "alloy-primitives",
"alloy-rlp", "alloy-rlp",
@ -251,7 +251,7 @@ dependencies = [
[[package]] [[package]]
name = "alloy-transport" name = "alloy-transport"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-json-rpc", "alloy-json-rpc",
"base64 0.21.7", "base64 0.21.7",
@ -267,7 +267,7 @@ dependencies = [
[[package]] [[package]]
name = "alloy-transport-http" name = "alloy-transport-http"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-json-rpc", "alloy-json-rpc",
"alloy-transport", "alloy-transport",
@ -280,7 +280,7 @@ dependencies = [
[[package]] [[package]]
name = "alloy-transport-ws" name = "alloy-transport-ws"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/alloy-rs/alloy.git#2d23d57d78844e04c9ea09cf9e5aea2dccc1c639" source = "git+https://github.com/alloy-rs/alloy.git#32618e9243a761858a0843e7e55575e48fdbf500"
dependencies = [ dependencies = [
"alloy-pubsub", "alloy-pubsub",
"alloy-transport", "alloy-transport",
@ -330,9 +330,9 @@ dependencies = [
[[package]] [[package]]
name = "anstyle" name = "anstyle"
version = "1.0.5" version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2faccea4cc4ab4a667ce676a30e8ec13922a692c99bb8f5b11f1502c72e04220" checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
[[package]] [[package]]
name = "anstyle-parse" name = "anstyle-parse"
@ -2103,9 +2103,9 @@ dependencies = [
[[package]] [[package]]
name = "fiat-crypto" name = "fiat-crypto"
version = "0.2.5" version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27573eac26f4dd11e2b1916c3fe1baa56407c83c71a773a8ba17ec0bca03b6b7" checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382"
[[package]] [[package]]
name = "fixed-hash" name = "fixed-hash"
@ -2483,9 +2483,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.3.4" version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3"
[[package]] [[package]]
name = "hex" name = "hex"
@ -2630,9 +2630,9 @@ dependencies = [
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
version = "0.1.59" version = "0.1.60"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
dependencies = [ dependencies = [
"android_system_properties", "android_system_properties",
"core-foundation-sys", "core-foundation-sys",
@ -3264,9 +3264,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
dependencies = [ dependencies = [
"adler", "adler",
] ]
@ -3651,9 +3651,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]] [[package]]
name = "pest" name = "pest"
version = "2.7.6" version = "2.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f200d8d83c44a45b21764d1916299752ca035d15ecd46faca3e9a2a2bf6ad06" checksum = "219c0dcc30b6a27553f9cc242972b67f75b60eb0db71f0b5462f38b058c41546"
dependencies = [ dependencies = [
"memchr", "memchr",
"thiserror", "thiserror",
@ -5012,13 +5012,12 @@ checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae"
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.9.0" version = "3.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"fastrand", "fastrand",
"redox_syscall",
"rustix", "rustix",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
@ -5056,9 +5055,9 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.32" version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe80ced77cbfb4cb91a94bf72b378b4b6791a0d9b7f09d0be747d1bdff4e68bd" checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749"
dependencies = [ dependencies = [
"deranged", "deranged",
"itoa", "itoa",
@ -6411,9 +6410,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]] [[package]]
name = "winnow" name = "winnow"
version = "0.5.36" version = "0.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "818ce546a11a9986bc24f93d0cdf38a8a1a400f1473ea8c82e59f6e0ffab9249" checksum = "a7cad8365489051ae9f054164e459304af2e7e9bb407c958076c8bf4aef52da5"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]

File diff suppressed because it is too large Load Diff

View File

@ -12,12 +12,12 @@ lto = true
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
alloy-primitives = "0.5.1" alloy-primitives = "0.6.2"
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy.git", rev = "3b1c310" } alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy" }
alloy-sol-types = "0.5.1" alloy-sol-types = "0.6.2"
bincode = "1.3.3" bincode = "1.3.3"
hex = "0.4.3" hex = "0.4.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.5-alpha", features = ["eth"] } kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "032bd43" }
rmp-serde = "1.1.2" rmp-serde = "1.1.2"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"

View File

@ -6,8 +6,9 @@ use alloy_rpc_types::{
use alloy_sol_types::{sol, SolEvent}; use alloy_sol_types::{sol, SolEvent};
use kinode_process_lib::{ use kinode_process_lib::{
await_message, get_typed_state, print_to_terminal, println, set_state, Address, Message, await_message,
Request, Response, eth::{get_block_number, get_logs, EthResponse},
get_typed_state, print_to_terminal, println, set_state, Address, Message, Request, Response,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::string::FromUtf8Error; use std::string::FromUtf8Error;
@ -38,34 +39,10 @@ pub enum EthAction {
}, },
/// Kill a SubscribeLogs subscription of a given ID, to stop getting updates. /// Kill a SubscribeLogs subscription of a given ID, to stop getting updates.
UnsubscribeLogs(u64), UnsubscribeLogs(u64),
/// get_logs Request {
GetLogs { filter: Filter }, method: String,
/// get_block_number params: serde_json::Value,
GetBlockNumber, },
}
//TEMP
/// Potential EthResponse type.
/// Can encapsulate all methods in their own response type,
/// or return generic result which can be parsed later..
#[derive(Debug, Serialize, Deserialize)]
pub enum EthResponse {
// another possible strat, just return RpcResult<T, E, ErrResp>,
// then try deserializing on the process_lib side.
Ok,
//Err(EthError),
Sub(SubscriptionResult),
GetLogs(Vec<Log>),
// GetBlockNumber(u64),
// GetBalance(U256),
// GetGasPrice(U256),
// Call(Vec<u8>), // alloy_primimtives::Bytes deserialization..
// GetTransactionCount(U256),
// GetBlockByNumber(Option<Block>),
// GetBlockByHash(Option<Block>),
// // raw json vs enum type vs into T?
// RawRequest(serde_json::Value),
// SendRawTransaction(Vec<u8>), // alloy_primitives::TxHash deserialization..
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
@ -200,6 +177,24 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
block: 1, block: 1,
}; };
} }
let filter = Filter::new()
.address(contract_address.unwrap().parse::<EthAddress>().unwrap())
.to_block(BlockNumberOrTag::Latest)
.from_block(state.block - 1)
.events(vec![
"NodeRegistered(bytes32,bytes)",
"KeyUpdate(bytes32,bytes32)",
"IpUpdate(bytes32,uint128)",
"WsUpdate(bytes32,uint16)",
"RoutingUpdate(bytes32,bytes32[])",
]);
// if block in state is < current_block, get logs from that part.
if state.block < get_block_number()? {
let logs = get_logs(filter.clone())?;
for log in logs {
handle_log(&our, &mut state, &log)?;
}
}
// shove all state into net::net // shove all state into net::net
Request::new() Request::new()
.target((&our.node, "net", "distro", "sys")) .target((&our.node, "net", "distro", "sys"))
@ -208,26 +203,9 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
))? ))?
.send()?; .send()?;
let filter = Filter::new() let params = Params::Logs(Box::new(filter));
.address(contract_address.unwrap().parse::<EthAddress>().unwrap())
.from_block(0)
.to_block(BlockNumberOrTag::Latest)
.events(vec![
"NodeRegistered(bytes32,bytes)",
"KeyUpdate(bytes32,bytes32)",
"IpUpdate(bytes32,uint128)",
"WsUpdate(bytes32,uint16)",
"RoutingUpdate(bytes32,bytes32[])",
]);
let params = Params::Logs(Box::new(filter.clone()));
let kind = SubscriptionKind::Logs; let kind = SubscriptionKind::Logs;
Request::new()
.target((&our.node, "eth", "distro", "sys"))
.body(serde_json::to_vec(&EthAction::GetLogs { filter })?)
.send()?;
Request::new() Request::new()
.target((&our.node, "eth", "distro", "sys")) .target((&our.node, "eth", "distro", "sys"))
.body(serde_json::to_vec(&EthAction::SubscribeLogs { .body(serde_json::to_vec(&EthAction::SubscribeLogs {
@ -299,12 +277,7 @@ fn handle_eth_message(
}; };
match res { match res {
EthResponse::GetLogs(logs) => { EthResponse::Sub { id, result } => match result {
for log in logs {
handle_log(our, state, &log)?;
}
}
EthResponse::Sub(result) => match result {
SubscriptionResult::Log(log) => { SubscriptionResult::Log(log) => {
handle_log(our, state, &log)?; handle_log(our, state, &log)?;
} }
@ -350,7 +323,7 @@ fn handle_eth_message(
fn handle_log(our: &Address, state: &mut State, log: &Log) -> anyhow::Result<()> { fn handle_log(our: &Address, state: &mut State, log: &Log) -> anyhow::Result<()> {
state.block = log.block_number.expect("expect").to::<u64>(); state.block = log.block_number.expect("expect").to::<u64>();
let node_id: alloy_primitives::FixedBytes<32> = log.topics[1]; let node_id = log.topics[1];
let name = match state.names.entry(node_id.to_string()) { let name = match state.names.entry(node_id.to_string()) {
Entry::Occupied(o) => o.into_mut(), Entry::Occupied(o) => o.into_mut(),

View File

@ -1,5 +1,6 @@
use crate::eth::types::*; use crate::eth::types::*;
use crate::types::*; use crate::types::*;
use alloy_providers::provider::TempProvider;
use alloy_pubsub::{PubSubFrontend, RawSubscription}; use alloy_pubsub::{PubSubFrontend, RawSubscription};
use alloy_rpc_client::ClientBuilder; use alloy_rpc_client::ClientBuilder;
use alloy_rpc_types::pubsub::SubscriptionResult; use alloy_rpc_types::pubsub::SubscriptionResult;

View File

@ -1,12 +1,5 @@
use crate::types::ProcessId;
use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxHash, B256, U256};
use alloy_providers::provider::Provider;
use alloy_pubsub::PubSubFrontend;
use alloy_rpc_types::pubsub::{Params, SubscriptionKind, SubscriptionResult}; use alloy_rpc_types::pubsub::{Params, SubscriptionKind, SubscriptionResult};
use alloy_rpc_types::{Block, BlockId, BlockNumberOrTag, CallRequest, Filter, Log};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tokio::task::JoinHandle;
/// The Request type that can be made to eth:distro:sys. Currently primitive, this /// The Request type that can be made to eth:distro:sys. Currently primitive, this
/// enum will expand to support more actions in the future. /// enum will expand to support more actions in the future.
@ -62,7 +55,9 @@ pub fn to_static_str(method: &str) -> Option<&'static str> {
"eth_getBalance" => Some("eth_getBalance"), "eth_getBalance" => Some("eth_getBalance"),
"eth_sendRawTransaction" => Some("eth_sendRawTransaction"), "eth_sendRawTransaction" => Some("eth_sendRawTransaction"),
"eth_call" => Some("eth_call"), "eth_call" => Some("eth_call"),
"eth_chainId" => Some("eth_chainId"),
"eth_getTransactionReceipt" => Some("eth_getTransactionReceipt"), "eth_getTransactionReceipt" => Some("eth_getTransactionReceipt"),
"eth_getTransactionCount" => Some("eth_getTransactionCount"),
"eth_estimateGas" => Some("eth_estimateGas"), "eth_estimateGas" => Some("eth_estimateGas"),
"eth_blockNumber" => Some("eth_blockNumber"), "eth_blockNumber" => Some("eth_blockNumber"),
"eth_getBlockByHash" => Some("eth_getBlockByHash"), "eth_getBlockByHash" => Some("eth_getBlockByHash"),