Create new sbot connection for each query

This commit is contained in:
notplants 2022-01-14 12:37:34 -05:00
parent 887d635683
commit 9027ebfe84
2 changed files with 29 additions and 28 deletions

View File

@ -10,19 +10,19 @@ async fn run() -> Result<(), GolgiError> {
let id = sbot_client.whoami().await?;
println!("whoami: {}", id);
let name = SsbMessageContent::About {
about: id.clone(),
name: Some("golgi".to_string()),
title: None,
branch: None,
image: None,
description: None,
location: None,
start_datetime: None,
};
let name_msg_ref = sbot_client.publish(name).await?;
println!("name_msg_ref: {}", name_msg_ref);
// let name = SsbMessageContent::About {
// about: id.clone(),
// name: Some("golgi".to_string()),
// title: None,
// branch: None,
// image: None,
// description: None,
// location: None,
// start_datetime: None,
// };
//
// let name_msg_ref = sbot_client.publish(name).await?;
// println!("name_msg_ref: {}", name_msg_ref);
let post = SsbMessageContent::Post {
text: "golgi go womp womp".to_string(),
@ -42,6 +42,14 @@ async fn run() -> Result<(), GolgiError> {
let description = sbot_client.get_description(&author).await?;
println!("found description: {:?}", description);
let post = SsbMessageContent::Post {
text: "golgi go womp womp2".to_string(),
mentions: None,
};
let post_msg_ref = sbot_client.publish(post).await?;
println!("post_msg_ref2: {}", post_msg_ref);
Ok(())
}

View File

@ -33,17 +33,13 @@ pub struct SbotConnection {
}
/// The Scuttlebutt identity, keys and configuration parameters for connecting to a local sbot
/// instance, as well as handles for calling RPC methods and receiving responses.
pub struct Sbot {
pub id: String,
public_key: ed25519::PublicKey,
private_key: ed25519::SecretKey,
address: String,
// aka caps key (scuttleverse identifier)
network_id: auth::Key,
// the primary connection with sbot which can be re-used for non-stream calls
// note that stream calls will each need their own SbotConnection
sbot_connection: SbotConnection,
network_id: auth::Key
}
impl Sbot {
@ -67,17 +63,12 @@ impl Sbot {
.await
.expect("couldn't read local secret");
let sbot_connection =
Sbot::_get_sbot_connection_helper(address.clone(), network_id.clone(), pk, sk.clone())
.await?;
Ok(Self {
id,
public_key: pk,
private_key: sk,
address,
network_id,
sbot_connection,
network_id
})
}
@ -152,10 +143,11 @@ impl Sbot {
/// Call the `whoami` RPC method and return an `id`.
pub async fn whoami(&mut self) -> Result<String, GolgiError> {
let req_id = self.sbot_connection.client.whoami_req_send().await?;
let mut sbot_connection = self.get_sbot_connection().await?;
let req_id = sbot_connection.client.whoami_req_send().await?;
let result = utils::get_async(
&mut self.sbot_connection.rpc_reader,
&mut sbot_connection.rpc_reader,
req_id,
utils::json_res_parse,
)
@ -177,10 +169,11 @@ impl Sbot {
/// `Channel` and `Vote`. See the `kuska_ssb` documentation for further details such as field
/// names and accepted values for each variant.
pub async fn publish(&mut self, msg: SsbMessageContent) -> Result<String, GolgiError> {
let req_id = self.sbot_connection.client.publish_req_send(msg).await?;
let mut sbot_connection = self.get_sbot_connection().await?;
let req_id = sbot_connection.client.publish_req_send(msg).await?;
utils::get_async(
&mut self.sbot_connection.rpc_reader,
&mut sbot_connection.rpc_reader,
req_id,
utils::string_res_parse,
)