mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-23 00:21:38 +03:00
contacts: add get_names script
This commit is contained in:
parent
189f0378bb
commit
d4aac4e83b
46
kinode/packages/contacts/Cargo.lock
generated
46
kinode/packages/contacts/Cargo.lock
generated
@ -780,7 +780,7 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
|
|||||||
name = "contacts"
|
name = "contacts"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"kinode_process_lib",
|
"kinode_process_lib 0.9.4",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"wit-bindgen",
|
"wit-bindgen",
|
||||||
@ -1161,6 +1161,18 @@ dependencies = [
|
|||||||
"zeroize",
|
"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]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
@ -1460,6 +1472,29 @@ dependencies = [
|
|||||||
"sha3-asm",
|
"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]]
|
[[package]]
|
||||||
name = "kinode_process_lib"
|
name = "kinode_process_lib"
|
||||||
version = "0.9.4"
|
version = "0.9.4"
|
||||||
@ -1887,6 +1922,15 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"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]]
|
[[package]]
|
||||||
name = "proptest"
|
name = "proptest"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"contacts",
|
"contacts",
|
||||||
|
"get_names",
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
19
kinode/packages/contacts/get_names/Cargo.toml
Normal file
19
kinode/packages/contacts/get_names/Cargo.toml
Normal 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"
|
35
kinode/packages/contacts/get_names/src/lib.rs
Normal file
35
kinode/packages/contacts/get_names/src/lib.rs
Normal 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:?}");
|
||||||
|
}
|
18
kinode/packages/contacts/pkg/scripts.json
Normal file
18
kinode/packages/contacts/pkg/scripts.json
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user