Create new sbot connection for each query
This commit is contained in:
parent
887d635683
commit
9027ebfe84
|
@ -10,19 +10,19 @@ async fn run() -> Result<(), GolgiError> {
|
||||||
let id = sbot_client.whoami().await?;
|
let id = sbot_client.whoami().await?;
|
||||||
println!("whoami: {}", id);
|
println!("whoami: {}", id);
|
||||||
|
|
||||||
let name = SsbMessageContent::About {
|
// let name = SsbMessageContent::About {
|
||||||
about: id.clone(),
|
// about: id.clone(),
|
||||||
name: Some("golgi".to_string()),
|
// name: Some("golgi".to_string()),
|
||||||
title: None,
|
// title: None,
|
||||||
branch: None,
|
// branch: None,
|
||||||
image: None,
|
// image: None,
|
||||||
description: None,
|
// description: None,
|
||||||
location: None,
|
// location: None,
|
||||||
start_datetime: None,
|
// start_datetime: None,
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
let name_msg_ref = sbot_client.publish(name).await?;
|
// let name_msg_ref = sbot_client.publish(name).await?;
|
||||||
println!("name_msg_ref: {}", name_msg_ref);
|
// println!("name_msg_ref: {}", name_msg_ref);
|
||||||
|
|
||||||
let post = SsbMessageContent::Post {
|
let post = SsbMessageContent::Post {
|
||||||
text: "golgi go womp womp".to_string(),
|
text: "golgi go womp womp".to_string(),
|
||||||
|
@ -42,6 +42,14 @@ async fn run() -> Result<(), GolgiError> {
|
||||||
let description = sbot_client.get_description(&author).await?;
|
let description = sbot_client.get_description(&author).await?;
|
||||||
println!("found description: {:?}", description);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
23
src/sbot.rs
23
src/sbot.rs
|
@ -33,17 +33,13 @@ pub struct SbotConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The Scuttlebutt identity, keys and configuration parameters for connecting to a local sbot
|
/// 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 struct Sbot {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
public_key: ed25519::PublicKey,
|
public_key: ed25519::PublicKey,
|
||||||
private_key: ed25519::SecretKey,
|
private_key: ed25519::SecretKey,
|
||||||
address: String,
|
address: String,
|
||||||
// aka caps key (scuttleverse identifier)
|
// aka caps key (scuttleverse identifier)
|
||||||
network_id: auth::Key,
|
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,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sbot {
|
impl Sbot {
|
||||||
|
@ -67,17 +63,12 @@ impl Sbot {
|
||||||
.await
|
.await
|
||||||
.expect("couldn't read local secret");
|
.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 {
|
Ok(Self {
|
||||||
id,
|
id,
|
||||||
public_key: pk,
|
public_key: pk,
|
||||||
private_key: sk,
|
private_key: sk,
|
||||||
address,
|
address,
|
||||||
network_id,
|
network_id
|
||||||
sbot_connection,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,10 +143,11 @@ impl Sbot {
|
||||||
|
|
||||||
/// Call the `whoami` RPC method and return an `id`.
|
/// Call the `whoami` RPC method and return an `id`.
|
||||||
pub async fn whoami(&mut self) -> Result<String, GolgiError> {
|
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(
|
let result = utils::get_async(
|
||||||
&mut self.sbot_connection.rpc_reader,
|
&mut sbot_connection.rpc_reader,
|
||||||
req_id,
|
req_id,
|
||||||
utils::json_res_parse,
|
utils::json_res_parse,
|
||||||
)
|
)
|
||||||
|
@ -177,10 +169,11 @@ impl Sbot {
|
||||||
/// `Channel` and `Vote`. See the `kuska_ssb` documentation for further details such as field
|
/// `Channel` and `Vote`. See the `kuska_ssb` documentation for further details such as field
|
||||||
/// names and accepted values for each variant.
|
/// names and accepted values for each variant.
|
||||||
pub async fn publish(&mut self, msg: SsbMessageContent) -> Result<String, GolgiError> {
|
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(
|
utils::get_async(
|
||||||
&mut self.sbot_connection.rpc_reader,
|
&mut sbot_connection.rpc_reader,
|
||||||
req_id,
|
req_id,
|
||||||
utils::string_res_parse,
|
utils::string_res_parse,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue