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!({
|
||||
path: "target/wit",
|
||||
world: "process-v0",
|
||||
});
|
||||
|
||||
call_init!(init);
|
||||
fn init(_our: Address) {
|
||||
let Ok(args) = await_next_message_body() else {
|
||||
println!("failed to get args");
|
||||
return;
|
||||
};
|
||||
|
||||
// incoming args bytes are a string we parse to u64, if none provided, default to 1
|
||||
let chain_id = std::str::from_utf8(&args)
|
||||
script!(init);
|
||||
fn init(_our: Address, args: String) -> String {
|
||||
// call get_block with the chain id provided in the args
|
||||
let chain_id = args
|
||||
.split_whitespace()
|
||||
.next()
|
||||
.unwrap_or("1")
|
||||
.parse::<u64>()
|
||||
.unwrap_or(1);
|
||||
@ -22,11 +19,7 @@ fn init(_our: Address) {
|
||||
let provider = eth::Provider::new(chain_id, 5);
|
||||
|
||||
match provider.get_block_number() {
|
||||
Ok(block_number) => {
|
||||
println!("latest block number: {block_number}");
|
||||
}
|
||||
Err(e) => {
|
||||
println!("failed to get block number: {e:?}");
|
||||
}
|
||||
Ok(block_number) => format!("latest block number: {block_number}"),
|
||||
Err(e) => format!("failed to get block number: {e:?}"),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user