use tashi_vertex::{Context, Engine, KeySecret, Message, Options, Peers, Socket, Transaction};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let key: KeySecret = "BASE58_SECRET_KEY".parse()?;
// Configure peers in the network
let mut peers = Peers::new()?;
peers.insert("127.0.0.1:9001", &"BASE58_PEER_PUBLIC_KEY".parse()?, Default::default())?;
peers.insert("127.0.0.1:9000", &key.public(), Default::default())?;
// Initialize the runtime and bind a socket
let context = Context::new()?;
let socket = Socket::bind(&context, "127.0.0.1:9000").await?;
// Start the consensus engine
let options = Options::default();
let engine = Engine::start(&context, socket, options, &key, peers)?;
// Send a transaction
let data = b"hello world";
let mut tx = Transaction::allocate(data.len());
tx.copy_from_slice(data);
engine.send_transaction(tx)?;
// Receive consensus-ordered messages
while let Some(message) = engine.recv_message().await? {
match message {
Message::Event(event) => {
for tx in event.transactions() {
println!("tx: {:?}", tx);
}
}
Message::SyncPoint(_) => { /* session management */ }
}
}
Ok(())
}