mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-23 08:32:23 +03:00
use script! macro in a terminal script
This commit is contained in:
parent
15557a65c7
commit
bfd0267f66
@ -1,19 +1,16 @@
|
|||||||
use kinode_process_lib::{await_next_message_body, call_init, eth, println, Address};
|
use kinode_process_lib::{eth, script, Address};
|
||||||
|
|
||||||
wit_bindgen::generate!({
|
wit_bindgen::generate!({
|
||||||
path: "target/wit",
|
path: "target/wit",
|
||||||
world: "process-v0",
|
world: "process-v0",
|
||||||
});
|
});
|
||||||
|
|
||||||
call_init!(init);
|
script!(init);
|
||||||
fn init(_our: Address) {
|
fn init(_our: Address, args: String) -> String {
|
||||||
let Ok(args) = await_next_message_body() else {
|
// call get_block with the chain id provided in the args
|
||||||
println!("failed to get args");
|
let chain_id = args
|
||||||
return;
|
.split_whitespace()
|
||||||
};
|
.next()
|
||||||
|
|
||||||
// incoming args bytes are a string we parse to u64, if none provided, default to 1
|
|
||||||
let chain_id = std::str::from_utf8(&args)
|
|
||||||
.unwrap_or("1")
|
.unwrap_or("1")
|
||||||
.parse::<u64>()
|
.parse::<u64>()
|
||||||
.unwrap_or(1);
|
.unwrap_or(1);
|
||||||
@ -22,11 +19,7 @@ fn init(_our: Address) {
|
|||||||
let provider = eth::Provider::new(chain_id, 5);
|
let provider = eth::Provider::new(chain_id, 5);
|
||||||
|
|
||||||
match provider.get_block_number() {
|
match provider.get_block_number() {
|
||||||
Ok(block_number) => {
|
Ok(block_number) => format!("latest block number: {block_number}"),
|
||||||
println!("latest block number: {block_number}");
|
Err(e) => format!("failed to get block number: {e:?}"),
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
println!("failed to get block number: {e:?}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user