Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ river = { path = "cli", package = "river" }
# Freenet dependencies
freenet-scaffold = "0.2.1"
freenet-scaffold-macro = "0.2.1"
freenet-stdlib = { version = "0.1.30", features = ["contract"] }
freenet-stdlib = { version = "0.1.32", features = ["contract"] }

[workspace.package]
version = "0.1.2"
Expand Down
41 changes: 1 addition & 40 deletions delegates/chat-delegate/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,7 @@
use super::*;

/// Context for the chat delegate, storing pending operations.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub(super) struct ChatDelegateContext {
/// Map of secret IDs to pending operations
pub(super) pending_ops: HashMap<SecretIdKey, PendingOperation>,
}

/// Structure to store the index of keys for an app
/// Structure to store the index of keys for an origin
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub(super) struct KeyIndex {
pub(super) keys: Vec<ChatDelegateKey>,
}

impl TryFrom<DelegateContext> for ChatDelegateContext {
type Error = DelegateError;

fn try_from(value: DelegateContext) -> Result<Self, Self::Error> {
if value == DelegateContext::default() {
return Ok(Self::default());
}
ciborium::from_reader(value.as_ref())
.map_err(|err| DelegateError::Deser(format!("Failed to deserialize context: {err}")))
}
}

impl TryFrom<&ChatDelegateContext> for DelegateContext {
type Error = DelegateError;

fn try_from(value: &ChatDelegateContext) -> Result<Self, Self::Error> {
let mut buffer = Vec::new();
ciborium::ser::into_writer(value, &mut buffer)
.map_err(|err| DelegateError::Deser(format!("Failed to serialize context: {err}")))?;
Ok(DelegateContext::new(buffer))
}
}

impl TryFrom<&mut ChatDelegateContext> for DelegateContext {
type Error = DelegateError;

fn try_from(value: &mut ChatDelegateContext) -> Result<Self, Self::Error> {
// Delegate to the immutable reference implementation
Self::try_from(&*value)
}
}
Loading