Skip to content

Commit 32bb3dc

Browse files
authored
Fix some Inconsistencies & add more information (#52)
* Inconsistencies: - sentry - remove `util` module, it's not currently used - domain - README - addd the `repositories` feature - README - update the document to include more information for the repository * domain/sentry - add `deny(rust_2018_idioms)` and fix the errors * fix `clippy` warnings
1 parent 4adb147 commit 32bb3dc

File tree

11 files changed

+48
-68
lines changed

11 files changed

+48
-68
lines changed

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1-
# Adex Validator Stack in Rust [![Build Status](https://travis-ci.com/AdExNetwork/adex-validator-stack-rust.svg?token=TBKq9g6p9sWDrzNyX4kC&branch=master)](https://travis-ci.com/AdExNetwork/adex-validator-stack-rust)
1+
# AdEx Validator Stack in Rust [![Build Status](https://travis-ci.com/AdExNetwork/adex-validator-stack-rust.svg?token=TBKq9g6p9sWDrzNyX4kC&branch=master)](https://travis-ci.com/AdExNetwork/adex-validator-stack-rust)
22

3-
Rust implementation of the Validator Stack
3+
The Rust implementation of the Validator Stack
44

55
Reference implementation of the [AdEx validator stack](https://github.com/adexnetwork/adex-protocol#validator-stack-platform).
66

77
Components:
88

9-
* Sentry - TODO
9+
* Domain crate
10+
* Sentry - check the list of [opened issues](https://github.com/AdExNetwork/adex-validator-stack-rust/issues?q=is:open is:issue project:AdExNetwork/adex-validator-stack-rust/1)
1011
* Validator worker - TODO
1112

13+
## Domain
14+
Contains all the Domain `Aggregates`, `Entities`, `Value Objects`, interfaces (traits) and `Domain Error`.
15+
The interfaces(traits) include The `RepositoryFuture` and the `Aggregates`/`Entities` traits for the repositories.
16+
17+
All the structs have defined (de)serialization. The also have incorporated domain rules, e.g.
18+
`TargetingTag.score` (the `Score` struct) should be with a value between `0` and `100`.
19+
This means that once we have a `Score` object, we are guaranteed to have a valid object everywhere.
20+
21+
The `Repository` traits are meant for retrieving the underlying object types, this includes implementations with
22+
Databases (like `Postgres` for `Sentry`), API calls (for the `Validator` to fetch the objects from `Sentry`),
23+
memory (for testing) and etc.
24+
1225
## Sentry: API
1326

1427
#### Do not require authentication, can be cached:
1528

16-
GET `/channel/list` - get a list of all channels - TODO
29+
The API documentation can be found on the [adex-validator](https://github.com/AdExNetwork/adex-validator/blob/master/docs/api.md).
30+
Currently implemented endpoints:
31+
32+
- POST `/channel` - creates a new channel
33+
- GET `/channel/list` - get a list of all channels
34+
35+
## Validator worker
36+
37+
TODO
1738

1839
## Testing setup
1940

@@ -37,6 +58,9 @@ We've setup `rust-toolchain` but you can manually override it as well with `rust
3758
`DATABASE_URL=postgresql://postgres:docker@localhost:5432/sentry cargo run --bin sentry`
3859

3960
#### Environment variables:
61+
62+
- `DATABASE_URL` - The url of the Postgres database used for production.
63+
4064
**NOTE: For development & testing purposes we use `.env` file to define values for those environment variables.**
4165

4266
- `CHANNEL_LIST_LIMIT` - the limit per page for listing channels from the `/channel/list` request.

domain/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ using Postgres, some sort of Memory implementation and etc.
88

99
### Features:
1010

11+
#### Repositories
12+
13+
If the usage of this crate, requires not only (de)serialization, but also retrieving or storing
14+
the objects in any way (database, API calls, memory and etc.) you would need this feature, as it defines
15+
the Repository traits that should be implemented, as a common interface, for handling such operations.
16+
17+
The trait `RepositoryFuture` with a generic `RepositoryError` is used as the common return type for
18+
repository methods.
19+
1120
#### Fixtures
1221

1322
For testing purposes there are set of fixtures found under the `fixtures` module,

domain/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(rust_2018_idioms)]
12
use std::error;
23
use std::fmt;
34

@@ -40,13 +41,13 @@ pub enum DomainError {
4041
}
4142

4243
impl fmt::Display for DomainError {
43-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4445
write!(f, "Domain error",)
4546
}
4647
}
4748

4849
impl error::Error for DomainError {
49-
fn cause(&self) -> Option<&error::Error> {
50+
fn cause(&self) -> Option<&dyn error::Error> {
5051
None
5152
}
5253
}
@@ -68,5 +69,5 @@ pub mod repository {
6869
User,
6970
}
7071

71-
pub type RepositoryFuture<T> = Pin<Box<Future<Output = Result<T, RepositoryError>> + Send>>;
72+
pub type RepositoryFuture<T> = Pin<Box<dyn Future<Output = Result<T, RepositoryError>> + Send>>;
7273
}

sentry/src/application/resource/channel/channel_create/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct ChannelCreateHandler<'a> {
1010
}
1111

1212
impl<'a> ChannelCreateHandler<'a> {
13-
pub fn new(channel_repository: &'a ChannelRepository) -> Self {
13+
pub fn new(channel_repository: &'a dyn ChannelRepository) -> Self {
1414
Self { channel_repository }
1515
}
1616
}

sentry/src/application/resource/channel/channel_list/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct ChannelListHandler<'a> {
1111
}
1212

1313
impl<'a> ChannelListHandler<'a> {
14-
pub fn new(limit_per_page: u32, channel_repository: &'a ChannelRepository) -> Self {
14+
pub fn new(limit_per_page: u32, channel_repository: &'a dyn ChannelRepository) -> Self {
1515
Self {
1616
limit_per_page,
1717
channel_repository,

sentry/src/infrastructure/persistence/memory.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl error::Error for MemoryPersistenceError {}
1414
impl IOError for MemoryPersistenceError {}
1515

1616
impl fmt::Display for MemoryPersistenceError {
17-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1818
let error_type = match *self {
1919
MemoryPersistenceError::Reading => "reading",
2020
MemoryPersistenceError::Writing => "writing",
@@ -29,13 +29,13 @@ impl fmt::Display for MemoryPersistenceError {
2929
}
3030

3131
impl<T> From<PoisonError<RwLockReadGuard<'_, T>>> for MemoryPersistenceError {
32-
fn from(_: PoisonError<RwLockReadGuard<T>>) -> Self {
32+
fn from(_: PoisonError<RwLockReadGuard<'_, T>>) -> Self {
3333
MemoryPersistenceError::Reading
3434
}
3535
}
3636

3737
impl<T> From<PoisonError<RwLockWriteGuard<'_, T>>> for MemoryPersistenceError {
38-
fn from(_: PoisonError<RwLockWriteGuard<T>>) -> Self {
38+
fn from(_: PoisonError<RwLockWriteGuard<'_, T>>) -> Self {
3939
MemoryPersistenceError::Writing
4040
}
4141
}

sentry/src/infrastructure/persistence/postgres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl error::Error for PostgresPersistenceError {}
1515
impl IOError for PostgresPersistenceError {}
1616

1717
impl fmt::Display for PostgresPersistenceError {
18-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1919
match *self {
2020
PostgresPersistenceError::UserError(ref error) => {
2121
write!(f, "User error occurred: {}", error)

sentry/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(async_await, await_macro)]
2-
2+
#![deny(rust_2018_idioms)]
33
pub mod application;
44
pub mod infrastructure;
5-
pub mod util;

sentry/src/util.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

sentry/src/util/tests.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

sentry/src/util/tests/time.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)