Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
704 changes: 306 additions & 398 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = "https://github.com/essential-contributions/void-toolkit"

[workspace.dependencies]
alloy = { version = "1.0.30", default-features = false, features = ["sol-types"] }
anyhow = "1.0.100"
axum = "0.8.4"
base64 = "0.22"
futures = "0.3.31"
Expand All @@ -32,6 +33,7 @@ tempfile = "3.23"
tracing = { version = "0.1.41" }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
void-app = { git = "ssh://git@github.com/essential-contributions/void-base.git" }
void-hash = { git = "ssh://git@github.com/essential-contributions/void-base.git" }
void-oracle = { git = "ssh://git@github.com/essential-contributions/void-oracle.git" }
void-oracle-types = { git = "ssh://git@github.com/essential-contributions/void-oracle.git" }
void-types = { git = "ssh://git@github.com/essential-contributions/void-base.git" }
Expand Down
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,25 @@ void-toolkit = { version = "0.1", features = ["run", "oracle", "load-config"] }
### Basic Usage

```rust
use std::convert::Infallible;

use futures::TryStreamExt;
use void_toolkit::{
app::UpdateLatestBlock,
load_config::load_config,
oracle::oracle,
oracle::Db,
oracle::{oracle, Db},
oracle_types::config::Config,
run::run_node,
types::{Block, Lock},
};

// Simple unit type that implements the required trait bound of `run_node` function
pub struct StateUnit;

pub struct State(pub u64);

impl From<&mut State> for StateUnit {
fn from(_: &mut State) -> Self {
StateUnit
impl UpdateLatestBlock for State {
type Error = Infallible;

fn update_latest_block(&mut self, _height: u64, _hash: [u8; 32]) -> Result<(), Self::Error> {
todo!()
}
}

Expand All @@ -113,10 +115,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config: Config = load_config("config.yaml")?;

// Start oracle to watch for cross-chain events
let blocks = oracle(config, Db::memory(), 0);
let blocks = oracle(config, Db::memory(), 0).map_err(|e| anyhow::anyhow!(e));

// Define your app's state and transition logic
let state_transition = |block: &Block, _state: &mut State| {
let state_transition = |block: &Block, _state: &mut State| -> Result<(), Infallible> {
// Process block and update state
for _event in &block.events {
// Handle cross-chain events
Expand All @@ -126,11 +128,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
block.height
);
}
Ok(())
};
let state = Lock::new(State(0));

// Run your VOID node
run_node::<_, Lock<State>, _, StateUnit>(blocks, state, state_transition).await;
run_node(blocks, state, state_transition).await?;

Ok(())
}
Expand Down Expand Up @@ -280,7 +283,7 @@ Use the event decoder to handle events from different chains:

```rust
use alloy::sol;
use futures::StreamExt;
use futures::TryStreamExt;
use void_toolkit::{
load_config::load_config, oracle::oracle, oracle::Db, oracle_decoder::decode_events,
oracle_types::config::Config,
Expand Down Expand Up @@ -308,7 +311,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Process decoded events in your state transition function
blocks
.for_each(|block| async move {
.try_for_each(|block| async move {
println!("Processing block with {} events", block.events.len());

for event in &block.events {
Expand All @@ -329,8 +332,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Unknown event: {} bytes", event.len());
}
}
Ok(())
})
.await;
.await?;

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions crates/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ path = "proof_generation.rs"

[dependencies]
alloy.workspace = true
anyhow.workspace = true
futures.workspace = true
tokio.workspace = true
tracing.workspace = true
Expand Down
25 changes: 14 additions & 11 deletions crates/examples/basic_usage.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use std::convert::Infallible;

use futures::TryStreamExt;
use void_toolkit::{
app::UpdateLatestBlock,
load_config::load_config,
oracle::oracle,
oracle::Db,
oracle::{oracle, Db},
oracle_types::config::Config,
run::run_node,
types::{Block, Lock},
};

// Simple unit type that implements the required trait bound of `run_node` function
pub struct StateUnit;

pub struct State(pub u64);

impl From<&mut State> for StateUnit {
fn from(_: &mut State) -> Self {
StateUnit
impl UpdateLatestBlock for State {
type Error = Infallible;

fn update_latest_block(&mut self, _height: u64, _hash: [u8; 32]) -> Result<(), Self::Error> {
todo!()
}
}

Expand All @@ -24,10 +26,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config: Config = load_config("config.yaml")?;

// Start oracle to watch for cross-chain events
let blocks = oracle(config, Db::memory(), 0);
let blocks = oracle(config, Db::memory(), 0).map_err(|e| anyhow::anyhow!(e));

// Define your app's state and transition logic
let state_transition = |block: &Block, _state: &mut State| {
let state_transition = |block: &Block, _state: &mut State| -> Result<(), Infallible> {
// Process block and update state
for _event in &block.events {
// Handle cross-chain events
Expand All @@ -37,11 +39,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
block.height
);
}
Ok(())
};
let state = Lock::new(State(0));

// Run your VOID node
run_node::<_, Lock<State>, _, StateUnit>(blocks, state, state_transition).await;
run_node(blocks, state, state_transition).await?;

Ok(())
}
7 changes: 4 additions & 3 deletions crates/examples/event_processing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy::sol;
use futures::StreamExt;
use futures::TryStreamExt;
use void_toolkit::{
load_config::load_config, oracle::oracle, oracle::Db, oracle_decoder::decode_events,
oracle_types::config::Config,
Expand Down Expand Up @@ -27,7 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Process decoded events in your state transition function
blocks
.for_each(|block| async move {
.try_for_each(|block| async move {
println!("Processing block with {} events", block.events.len());

for event in &block.events {
Expand All @@ -48,8 +48,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Unknown event: {} bytes", event.len());
}
}
Ok(())
})
.await;
.await?;

Ok(())
}
Loading
Loading