1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// cargo run -- modules/hello <did>: runs hello's count entry (after `atlibs add bobvmbuilder.bsky.social/hello`).
use std::sync::Arc;
use atlibs_host::host::{Fetch, HostCall};
use atlibs_host::run::{Ctx, Module, Options, run_module};
use atlibs_host::wasm::{Bound, Wasm};
use serde_json::{Value, json};
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), String> {
atlibs_host::tls();
let mut args = std::env::args().skip(1);
let (path, did) = (args.next().ok_or("a module: modules/hello")?, args.next().ok_or("a DID")?);
let read = |ext: &str| std::fs::read(format!("{path}.{ext}")).map_err(|e| format!("{path}.{ext}: {e}"));
let spec: Value = serde_json::from_slice(&read("json")?).map_err(|e| e.to_string())?;
let module = Module::from_manifest(read("wasm")?, &spec)?;
let ctx = Ctx { runner: Arc::new(Bound { wasm: Wasm::new(5000), bytes: module.bytes.clone(), sha256: None }), ledger: None, now: None };
// signed out: public reads only (a Session here acts as an account)
let fetch: Arc<dyn Fetch> = Arc::new(reqwest::Client::new());
let call = Arc::new(HostCall { fetch, session: None, attest: None });
let input = json!({ "did": did, "collection": "com.fedfork.exec.wasm.module" });
let ran = run_module(&ctx, &module, "count", input.as_object().unwrap(), call, Options::default()).await;
println!("{}", ran["result"]);
Ok(())
}