Skip to content

Commit

Permalink
refactor: minor changes and reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
edytapawlak committed Mar 25, 2024
1 parent 425bb92 commit 5cbc80c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
16 changes: 13 additions & 3 deletions components/witness/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ use keri_core::{
prelude::{HashFunctionCode, SerializationFormats},
simple_controller::{PossibleResponse, SimpleController},
SignedQueryError,
}, database::{escrow::EscrowDb, SledEventDatabase}, error::Error, event::sections::{
},
database::{escrow::EscrowDb, SledEventDatabase},
error::Error,
event::sections::{
seal::{EventSeal, Seal},
threshold::SignatureThreshold,
}, event_message::signed_event_message::{Message, Notice, Op, SignedEventMessage}, keys::PublicKey, mailbox::{exchange::ForwardTopic, MailboxResponse}, prefix::{BasicPrefix, IdentifierPrefix, SelfSigningPrefix}, processor::{
},
event_message::signed_event_message::{Message, Notice, Op, SignedEventMessage},
keys::PublicKey,
mailbox::{exchange::ForwardTopic, MailboxResponse},
prefix::{BasicPrefix, IdentifierPrefix, SelfSigningPrefix},
processor::{
basic_processor::BasicProcessor, escrow::EscrowConfig, event_storage::EventStorage,
Processor,
}, query::query_event::LogsQueryArgs, signer::{CryptoBox, Signer}
},
query::query_event::LogsQueryArgs,
signer::{CryptoBox, Signer},
};
use tempfile::Builder;
use url::Url;
Expand Down
4 changes: 2 additions & 2 deletions keriox_core/src/actor/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ pub enum ActorError {

#[error("Signing error: {0}")]
SigningError(#[from] KeysError),

#[error("Error: {0}")]
GeneralError(String)
GeneralError(String),
}

#[cfg(feature = "oobi")]
Expand Down
9 changes: 6 additions & 3 deletions keriox_core/src/actor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,19 @@ pub fn process_query(qr: &QueryRoute, storage: &EventStorage) -> Result<ReplyTyp
QueryRoute::Mbx { args, .. } => {
let mail = storage.get_mailbox_messages(args)?;
Ok(ReplyType::Mbx(mail))
},
QueryRoute::Logs { reply_route: _, args } => {
}
QueryRoute::Logs {
reply_route: _,
args,
} => {
let sn_kel = storage
.get_kel_messages_with_receipts(&args.i, args.s)?
.ok_or_else(|| QueryError::UnknownId { id: args.i.clone() })?
.into_iter()
.map(Message::Notice)
.collect();
Ok(ReplyType::Kel(sn_kel))
},
}
}
}

Expand Down
26 changes: 15 additions & 11 deletions keriox_core/src/processor/event_storage.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use std::sync::Arc;

use super::compute_state;
use crate::event_message::signed_event_message::SignedEventMessage;
#[cfg(feature = "query")]
use crate::query::{
key_state_notice::KeyStateNotice, mailbox::QueryArgsMbx, reply_event::SignedReply,
};
use crate::{
actor::prelude::Message,
database::{timestamped::{Timestamped, TimestampedSignedEventMessage}, SledEventDatabase},
database::{
timestamped::{Timestamped, TimestampedSignedEventMessage},
SledEventDatabase,
},
error::Error,
event::{
event_data::EventData,
Expand All @@ -20,7 +24,6 @@ use crate::{
#[cfg(feature = "query")]
use said::version::format::SerializationFormats;
use said::SelfAddressingIdentifier;
use crate::event_message::signed_event_message::SignedEventMessage;

#[cfg(feature = "mailbox")]
use crate::mailbox::MailboxResponse;
Expand Down Expand Up @@ -75,23 +78,24 @@ impl EventStorage {
pub fn get_kel_messages_with_receipts(
&self,
id: &IdentifierPrefix,
sn: Option<u64>
sn: Option<u64>,
) -> Result<Option<Vec<Notice>>, Error> {
let events = self.db.get_kel_finalized_events(id);
Ok(match (events, sn) {
(None, _) => None,
Ok(match (events, sn) {
(None, _) => None,
(Some(events), None) => self.collect_with_receipts(events),
(Some(events), Some(sn)) => {
let evs = events
.filter(|ev| ev.signed_event_message.event_message.data.get_sn() <= sn );
let evs =
events.filter(|ev| ev.signed_event_message.event_message.data.get_sn() <= sn);
self.collect_with_receipts(evs)
}
})

}

fn collect_with_receipts<'a, I>(&self, events: I ) -> Option<Vec<Notice>>
where I: IntoIterator<Item = Timestamped<SignedEventMessage>> {
fn collect_with_receipts<'a, I>(&self, events: I) -> Option<Vec<Notice>>
where
I: IntoIterator<Item = Timestamped<SignedEventMessage>>,
{
let evs = events
.into_iter()
.flat_map(|event: Timestamped<SignedEventMessage>| {
Expand All @@ -112,7 +116,7 @@ impl EventStorage {
None => vec![Notice::Event(event.into())],
}
});
Some(evs.collect())
Some(evs.collect())
}

pub fn get_event_at_sn(
Expand Down
1 change: 0 additions & 1 deletion keriox_core/src/query/query_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ fn test_query_deserialize() {
let input_query = r#"{"v":"KERI10JSON000105_","t":"qry","d":"EHtaQHsKzezkQUEYjMjEv6nIf4AhhR9Zy6AvcfyGCXkI","dt":"2021-01-01T00:00:00.000000+00:00","r":"logs","rr":"","q":{"s":0,"i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","src":"BGKVzj4ve0VSd8z_AmvhLg4lqcC_9WYX90k03q-R_Ydo"}}"#;
let qr: QueryEvent = serde_json::from_str(input_query).unwrap();
assert!(matches!(qr.data.data, QueryRoute::Logs { .. },));

}

#[test]
Expand Down
10 changes: 1 addition & 9 deletions keriox_tests/tests/indirect_mode_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,6 @@ async fn indirect_mode_signing() -> Result<(), ControllerError> {
.await;
}

// Now get expected KEL
let kel = verifying_identifier
.source
.storage
.get_kel(&signing_identifier.id)
.unwrap();
println!("{:?}", String::from_utf8(kel.unwrap()).unwrap());

// Verify signed message.
assert!(verifying_controller
.verify(first_message, &first_signature)
Expand All @@ -264,7 +256,7 @@ async fn indirect_mode_signing() -> Result<(), ControllerError> {

// Rotation needs two witness receipts to be accepted
let rotation_event = signing_identifier
.rotate(vec![pk], vec![npk], 1, vec![], vec![], 1)
.rotate(vec![pk], vec![npk], 1, vec![], vec![], 2)
.await?;

let signature = SelfSigningPrefix::Ed25519Sha512(key_manager.sign(rotation_event.as_bytes())?);
Expand Down

0 comments on commit 5cbc80c

Please sign in to comment.