contacts: add get_names script

This commit is contained in:
hosted-fornet 2024-10-21 17:07:51 -07:00
parent 189f0378bb
commit d4aac4e83b
5 changed files with 118 additions and 1 deletions

View File

@ -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"

View File

@ -2,6 +2,7 @@
resolver = "2"
members = [
"contacts",
"get_names",
]
[profile.release]

View File

@ -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"

View File

@ -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:?}");
}

View File

@ -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
}
}