diff --git a/kinode/packages/contacts/Cargo.lock b/kinode/packages/contacts/Cargo.lock index 9df40bfb..accb072b 100644 --- a/kinode/packages/contacts/Cargo.lock +++ b/kinode/packages/contacts/Cargo.lock @@ -780,7 +780,7 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" name = "contacts" version = "0.1.0" dependencies = [ - "kinode_process_lib", + "kinode_process_lib 0.9.4", "serde", "serde_json", "wit-bindgen", @@ -1161,6 +1161,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "get-names" +version = "0.1.0" +dependencies = [ + "anyhow", + "kinode_process_lib 0.9.3", + "process_macros", + "serde", + "serde_json", + "wit-bindgen", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -1460,6 +1472,29 @@ dependencies = [ "sha3-asm", ] +[[package]] +name = "kinode_process_lib" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7722aef4bff0625445fafda89a02f82ce0e16c7def6024e1317ae55a632ad331" +dependencies = [ + "alloy", + "alloy-primitives", + "alloy-sol-macro", + "alloy-sol-types", + "anyhow", + "bincode", + "http", + "mime_guess", + "rand", + "rmp-serde", + "serde", + "serde_json", + "thiserror", + "url", + "wit-bindgen", +] + [[package]] name = "kinode_process_lib" version = "0.9.4" @@ -1887,6 +1922,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "process_macros" +version = "0.1.0" +source = "git+https://github.com/kinode-dao/process_macros?rev=626e501#626e501d351e3365480ec6f770d474ed4ae339bf" +dependencies = [ + "quote", + "syn 2.0.79", +] + [[package]] name = "proptest" version = "1.5.0" diff --git a/kinode/packages/contacts/Cargo.toml b/kinode/packages/contacts/Cargo.toml index 43e1d296..e69e3bbb 100644 --- a/kinode/packages/contacts/Cargo.toml +++ b/kinode/packages/contacts/Cargo.toml @@ -2,6 +2,7 @@ resolver = "2" members = [ "contacts", + "get_names", ] [profile.release] diff --git a/kinode/packages/contacts/get_names/Cargo.toml b/kinode/packages/contacts/get_names/Cargo.toml new file mode 100644 index 00000000..da056b75 --- /dev/null +++ b/kinode/packages/contacts/get_names/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "get-names" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +anyhow = "1.0" +kinode_process_lib = "0.9.2" +process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +wit-bindgen = "0.24.0" + +[lib] +crate-type = ["cdylib"] + +[package.metadata.component] +package = "kinode:process" diff --git a/kinode/packages/contacts/get_names/src/lib.rs b/kinode/packages/contacts/get_names/src/lib.rs new file mode 100644 index 00000000..f5ca50a7 --- /dev/null +++ b/kinode/packages/contacts/get_names/src/lib.rs @@ -0,0 +1,35 @@ +use crate::kinode::process::contacts::{Capabilities as ContactsCapability, Request as ContactsRequest, Response as ContactsResponse}; +use kinode_process_lib::{call_init, println, Address, Capability, Request}; + +wit_bindgen::generate!({ + path: "target/wit", + world: "contacts-sys-v0", + generate_unused_types: true, + additional_derives: [serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto], +}); + +call_init!(init); +fn init(our: Address) { + let contacts_process = Address::from((our.node(), ("contacts", "contacts", "sys"))); + + let read_names_cap = Capability::new( + &contacts_process, + serde_json::to_string(&ContactsCapability::ReadNameOnly).unwrap() + ); + + let Ok(Ok(response)) = Request::to(&contacts_process) + .body(ContactsRequest::GetNames) + .capabilities(vec![read_names_cap]) + .send_and_await_response(5) else + { + println!("did not receive expected Response from contacts:contacts:sys"); + return; + }; + + let Ok(ContactsResponse::GetNames(names)) = response.body().try_into() else { + println!("did not receive GetNames resposne from contacts:contacts:sys"); + return; + }; + + println!("{names:?}"); +} diff --git a/kinode/packages/contacts/pkg/scripts.json b/kinode/packages/contacts/pkg/scripts.json new file mode 100644 index 00000000..80b2db1d --- /dev/null +++ b/kinode/packages/contacts/pkg/scripts.json @@ -0,0 +1,18 @@ +{ + "get_names.wasm": { + "root": false, + "public": false, + "request_networking": false, + "request_capabilities": [ + "contacts:contacts:sys", + { + "process": "contacts:contacts:sys", + "params": "ReadNameOnly" + } + ], + "grant_capabilities": [ + "contacts:contacts:sys" + ], + "wit_version": 0 + } +}