Compare commits
5 Commits
f41f8b55d2
...
48beb4a2e5
Author | SHA1 | Date | |
---|---|---|---|
48beb4a2e5 | |||
e9667a57be | |||
22d12f31ac | |||
fbe7072995 | |||
15acebbbfa |
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "golgi"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
edition = "2021"
|
||||
authors = ["Max Fowler <max@mfowler.info>", "Andrew Reid <glyph@mycelial.technology>"]
|
||||
readme = "README.md"
|
||||
|
@ -5,7 +5,7 @@ use futures::TryStreamExt;
|
||||
|
||||
use golgi::{
|
||||
api::get_subset::{SubsetQuery, SubsetQueryOptions},
|
||||
messages::{SsbMessageContentType, SsbMessageValue},
|
||||
messages::{SsbMessageContentType, SsbMessageKVT},
|
||||
sbot::Keystore,
|
||||
GolgiError, Sbot,
|
||||
};
|
||||
@ -31,7 +31,7 @@ async fn run() -> Result<(), GolgiError> {
|
||||
/* HISTORY STREAM EXAMPLE */
|
||||
|
||||
// Create an ordered stream of all messages authored by the `author`
|
||||
// identity.
|
||||
// identity. Messages are returned as KVTs (Key Value Timestamp).
|
||||
let history_stream = sbot_client
|
||||
.create_history_stream(author.to_string())
|
||||
.await?;
|
||||
@ -42,12 +42,12 @@ async fn run() -> Result<(), GolgiError> {
|
||||
println!("looping through stream");
|
||||
|
||||
// Iterate through each element in the stream and match on the `Result`.
|
||||
// In this case, each element has type `Result<SsbMessageValue, GolgiError>`.
|
||||
// In this case, each element has type `Result<SsbMessageKVT, GolgiError>`.
|
||||
while let Some(res) = history_stream.next().await {
|
||||
match res {
|
||||
Ok(value) => {
|
||||
// Print the `SsbMessageValue` of this element to `stdout`.
|
||||
println!("value: {:?}", value);
|
||||
Ok(kvt) => {
|
||||
// Print the `SsbMessageKVT` of this element to `stdout`.
|
||||
println!("kvt: {:?}", kvt);
|
||||
}
|
||||
Err(err) => {
|
||||
// Print the `GolgiError` of this element to `stderr`.
|
||||
@ -64,12 +64,12 @@ async fn run() -> Result<(), GolgiError> {
|
||||
.create_history_stream(author.to_string())
|
||||
.await?;
|
||||
|
||||
// Collect the stream elements into a `Vec<SsbMessageValue>` using
|
||||
// Collect the stream elements into a `Vec<SsbMessageKVT>` using
|
||||
// `try_collect`. A `GolgiError` will be returned from the `run`
|
||||
// function if any element contains an error.
|
||||
let results: Vec<SsbMessageValue> = history_stream.try_collect().await?;
|
||||
let results: Vec<SsbMessageKVT> = history_stream.try_collect().await?;
|
||||
|
||||
// Loop through the `SsbMessageValue` elements, printing each one
|
||||
// Loop through the `SsbMessageKVT` elements, printing each one
|
||||
// to `stdout`.
|
||||
for x in results {
|
||||
println!("x: {:?}", x);
|
||||
@ -82,13 +82,14 @@ async fn run() -> Result<(), GolgiError> {
|
||||
.await?;
|
||||
|
||||
// Iterate through the elements in the stream and use `map` to convert
|
||||
// each `SsbMessageValue` element into a tuple of
|
||||
// each `SsbMessageKVT` element into a tuple of
|
||||
// `(String, SsbMessageContentType)`. This is an example of stream
|
||||
// conversion.
|
||||
let type_stream = history_stream.map(|msg| match msg {
|
||||
Ok(val) => {
|
||||
let message_type = val.get_message_type()?;
|
||||
let tuple: (String, SsbMessageContentType) = (val.signature, message_type);
|
||||
Ok(kvt) => {
|
||||
let message_type = kvt.value.get_message_type()?;
|
||||
// Return the message key and type.
|
||||
let tuple: (String, SsbMessageContentType) = (kvt.key, message_type);
|
||||
Ok(tuple)
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
|
@ -34,6 +34,8 @@ pub enum GolgiError {
|
||||
Rpc(RpcError),
|
||||
/// Go-sbot error.
|
||||
Sbot(String),
|
||||
/// Error initializing Go-sbot.
|
||||
SbotInit(String),
|
||||
/// SSB sigil-link error.
|
||||
SigilLink(String),
|
||||
/// JSON serialization or deserialization error.
|
||||
@ -57,6 +59,7 @@ impl std::error::Error for GolgiError {
|
||||
GolgiError::Feed(ref err) => Some(err),
|
||||
GolgiError::Rpc(ref err) => Some(err),
|
||||
GolgiError::Sbot(_) => None,
|
||||
GolgiError::SbotInit(_) => None,
|
||||
GolgiError::SigilLink(_) => None,
|
||||
GolgiError::SerdeJson(ref err) => Some(err),
|
||||
GolgiError::ContentType(_) => None,
|
||||
@ -78,6 +81,9 @@ impl std::fmt::Display for GolgiError {
|
||||
// then have the core display msg be: "SSB RPC error: {}", context
|
||||
GolgiError::Rpc(ref err) => write!(f, "SSB RPC failure: {}", err),
|
||||
GolgiError::Sbot(ref err) => write!(f, "Sbot returned an error response: {}", err),
|
||||
GolgiError::SbotInit(ref err) => {
|
||||
write!(f, "Sbot encountered an initialization error: {}", err)
|
||||
}
|
||||
GolgiError::SigilLink(ref context) => write!(f, "SSB blob ID error: {}", context),
|
||||
GolgiError::SerdeJson(_) => write!(f, "Failed to serialize JSON slice"),
|
||||
//GolgiError::WhoAmI(ref err) => write!(f, "{}", err),
|
||||
|
34
src/sbot.rs
34
src/sbot.rs
@ -75,25 +75,35 @@ impl Sbot {
|
||||
};
|
||||
|
||||
let OwnedIdentity { pk, sk, id } = match keystore {
|
||||
Keystore::Patchwork => keystore::from_patchwork_local()
|
||||
.await
|
||||
.expect("couldn't read local patchwork secret from default location"),
|
||||
Keystore::GoSbot => keystore::from_gosbot_local()
|
||||
.await
|
||||
.expect("couldn't read local go-sbot secret from default location"),
|
||||
Keystore::Patchwork => keystore::from_patchwork_local().await.map_err(|_err| {
|
||||
GolgiError::SbotInit(
|
||||
"couldn't read local patchwork secret from default location".to_string(),
|
||||
)
|
||||
})?,
|
||||
Keystore::GoSbot => keystore::from_gosbot_local().await.map_err(|_err| {
|
||||
GolgiError::SbotInit(
|
||||
"couldn't read local go-sbot secret from default location".to_string(),
|
||||
)
|
||||
})?,
|
||||
Keystore::CustomGoSbot(key_path) => {
|
||||
keystore::from_custom_gosbot_keypath(key_path.to_string())
|
||||
.await
|
||||
.unwrap_or_else(|_| {
|
||||
panic!("couldn't read local go-sbot secret from: {}", key_path)
|
||||
})
|
||||
.map_err(|_err| {
|
||||
GolgiError::SbotInit(format!(
|
||||
"couldn't read local go-sbot secret from: {}",
|
||||
key_path
|
||||
))
|
||||
})?
|
||||
}
|
||||
Keystore::CustomPatchwork(key_path) => {
|
||||
keystore::from_custom_patchwork_keypath(key_path.to_string())
|
||||
.await
|
||||
.unwrap_or_else(|_| {
|
||||
panic!("couldn't read local patchwork secret from: {}", key_path)
|
||||
})
|
||||
.map_err(|_err| {
|
||||
GolgiError::SbotInit(format!(
|
||||
"couldn't read local patchwork secret from: {}",
|
||||
key_path
|
||||
))
|
||||
})?
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user