basic names rpc support

This commit is contained in:
glyph 2022-06-09 09:15:50 +01:00
parent 0aa616d92b
commit 2e1e9a79f1
4 changed files with 38 additions and 3 deletions

1
Cargo.lock generated
View File

@ -640,7 +640,6 @@ dependencies = [
[[package]]
name = "kuska-ssb"
version = "0.4.0"
source = "git+https://github.com/Kuska-ssb/ssb#fb7062de606e7c9cae8dd4df402a122db46c1b77"
dependencies = [
"async-std",
"async-stream 0.2.1",

View File

@ -19,7 +19,8 @@ futures = "0.3.21"
hex = "0.4.3"
kuska-handshake = { version = "0.2.0", features = ["async_std"] }
kuska-sodiumoxide = "0.2.5-0"
kuska-ssb = { git = "https://github.com/Kuska-ssb/ssb" }
kuska-ssb = { path = "../ssb" }
#kuska-ssb = { git = "https://github.com/Kuska-ssb/ssb" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.10.2"

View File

@ -13,7 +13,17 @@ async fn run() -> Result<(), GolgiError> {
// Attempt to initialise a connection to an sbot instance using the
// secret file at the Patchwork path and the default IP address, port
// and network key (aka. capabilities key).
let mut sbot_client = Sbot::init(Keystore::Patchwork, None, None).await?;
let mut sbot_client =
Sbot::init(Keystore::GoSbot, Some("127.0.0.1:8021".to_string()), None).await?;
// Sbot::init(Keystore::Patchwork, None, None).await?;
//let ssb_id = String::from("@PEqxT8YRvrkf2fyjAgTl8pmdo8aR4KVsKLyh0b5JyOE=.ed25519");
let ssb_id = String::from("@HEqy940T6uB+T+d9Jaa58aNfRzLx9eRWqkZljBmnkmk=.ed25519");
let name = sbot_client.get_name(&ssb_id).await?;
println!("name: {}", name);
/*
// Call the `whoami` RPC method to retrieve the public key for the sbot
// identity. This is our 'local' public key.
@ -114,6 +124,8 @@ async fn run() -> Result<(), GolgiError> {
// Output should be `false`.
println!("isfollowingmref(should be false): {}", mref);
*/
Ok(())
}

View File

@ -13,12 +13,14 @@
use std::collections::HashMap;
use async_std::stream::{Stream, StreamExt};
use serde_json::Value;
use crate::{
api::get_subset::{SubsetQuery, SubsetQueryOptions},
error::GolgiError,
messages::{SsbMessageContentType, SsbMessageValue},
sbot::Sbot,
utils,
};
impl Sbot {
@ -335,6 +337,7 @@ impl Sbot {
Ok(profile_info)
}
/*
/// Get the latest `name` value for a peer.
///
/// # Example
@ -359,6 +362,26 @@ impl Sbot {
pub async fn get_name(&mut self, ssb_id: &str) -> Result<Option<String>, GolgiError> {
self.get_latest_about_message(ssb_id, "name").await
}
*/
//pub async fn get_name(&mut self, ssb_id: &str) -> Result<Value, GolgiError> {
pub async fn get_name(&mut self, ssb_id: &str) -> Result<String, GolgiError> {
let mut sbot_connection = self.get_sbot_connection().await?;
let req_id = sbot_connection
.client
.names_get_signifier_req_send(ssb_id)
//.names_get_image_for_req_send(ssb_id)
//.names_get_req_send()
.await?;
utils::get_async(
&mut sbot_connection.rpc_reader,
req_id,
utils::string_res_parse,
//utils::json_res_parse,
)
.await
}
/// Get the latest `description` value for a peer.
///