Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement methods needed for replication defined in EntryStore traits #102

Merged
merged 13 commits into from
May 17, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Service error handling, refactor runtime [#92](https://github.com/p2panda/aquadoggo/pull/92)
- Refactor module structure, propagate errors in worker to service manager [#97](https://github.com/p2panda/aquadoggo/pull/97)
- Restructure storage modules and remove JSON RPC [#101](https://github.com/p2panda/aquadoggo/pull/101)
- Implement new methods required for replication defined by `EntryStore` trait [#102](https://github.com/p2panda/aquadoggo/pull/102)

### Changed

Expand Down
109 changes: 107 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion aquadoggo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ jsonrpc-v2 = { version = "0.10.1", features = [
"easy-errors",
"bytes-v05",
], default-features = false }
lipmaa-link = "0.2.2"
log = "0.4.14"
openssl-probe = "0.1.4"
# We can not publish the `aquadoggo` crate yet, since `p2panda-rs` is an
# unpublished dependency.
# @TODO: This points at a WIP branch in p2panda_rs which is used as long as things are slightly unstable
p2panda-rs = { git = "https://github.com/p2panda/p2panda", branch = "main" }
p2panda-rs = { git = "https://github.com/p2panda/p2panda", branch = "aquadoggo-wip" }
rand = "0.8.4"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.67"
Expand Down
38 changes: 0 additions & 38 deletions aquadoggo/src/db/models/entry.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

use p2panda_rs::entry::{decode_entry, Entry, EntrySigned};
use p2panda_rs::operation::OperationEncoded;
use p2panda_rs::storage_provider::errors::ValidationError;
use p2panda_rs::Validate;
use serde::Serialize;
use sqlx::FromRow;

Expand Down Expand Up @@ -35,37 +31,3 @@ pub struct EntryRow {
/// Sequence number of this entry.
pub seq_num: String,
}

impl EntryRow {
pub fn entry_decoded(&self) -> Entry {
// Unwrapping as validation occurs in `EntryWithOperation`.
decode_entry(&self.entry_signed(), self.operation_encoded().as_ref()).unwrap()
}

pub fn entry_signed(&self) -> EntrySigned {
EntrySigned::new(&self.entry_bytes).unwrap()
}

pub fn operation_encoded(&self) -> Option<OperationEncoded> {
Some(OperationEncoded::new(&self.payload_bytes.clone().unwrap()).unwrap())
}
}

impl Validate for EntryRow {
type Error = ValidationError;

fn validate(&self) -> Result<(), Self::Error> {
self.entry_signed().validate()?;
if let Some(operation) = self.operation_encoded() {
operation.validate()?;
}
decode_entry(&self.entry_signed(), self.operation_encoded().as_ref())?;
Ok(())
}
}

impl AsRef<Self> for EntryRow {
fn as_ref(&self) -> &Self {
self
}
}
10 changes: 5 additions & 5 deletions aquadoggo/src/db/provider.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

use async_trait::async_trait;
use sqlx::query_scalar;

use p2panda_rs::document::DocumentId;
use p2panda_rs::hash::Hash;
use p2panda_rs::storage_provider::traits::StorageProvider;
use sqlx::query_scalar;

use crate::db::models::entry::EntryRow;
use crate::db::models::log::LogRow;
use crate::db::stores::entry::StorageEntry;
use crate::db::stores::log::StorageLog;
use crate::db::Pool;
use crate::errors::StorageProviderResult;
use crate::rpc::{EntryArgsRequest, EntryArgsResponse, PublishEntryRequest, PublishEntryResponse};
Expand All @@ -18,7 +18,7 @@ pub struct SqlStorage {

/// A `StorageProvider` implementation based on `sqlx` that supports SQLite and PostgreSQL databases.
#[async_trait]
impl StorageProvider<EntryRow, LogRow> for SqlStorage {
impl StorageProvider<StorageEntry, StorageLog> for SqlStorage {
type EntryArgsResponse = EntryArgsResponse;
type EntryArgsRequest = EntryArgsRequest;
type PublishEntryResponse = PublishEntryResponse;
Expand Down
Loading