Skip to content

Commit 96023af

Browse files
committed
sentry - channel - document & clean dummy-deposit route
1 parent 4314a96 commit 96023af

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

README.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Two services are needed to run `Sentry`: `Postgres` and `Redis`.
3030

3131
The easiest way to run these services locally is by using the provided `docker-compose` file:
3232

33-
`docker-compose -f ../docker-compose.harness.yml up -d adex-redis adex-postgres`
33+
`docker-compose -f docker-compose.harness.yml up -d adex-redis adex-postgres`
3434

3535
If you want to run them manually without `docker-compose`:
3636

@@ -81,7 +81,7 @@ POSTGRES_DB="sentry_leader" PORT=8005 KEYSTORE_PWD=ganache0 \
8181
cargo run -p sentry -- \
8282
--adapter ethereum \
8383
--keystoreFile ./adapter/tests/resources/0x80690751969B234697e9059e04ed72195c3507fa_keystore.json \
84-
./docs/config/prod.toml
84+
./docs/config/ganache.toml
8585
```
8686

8787
##### Follower (`0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7`)
@@ -93,11 +93,26 @@ IP_ADDR=127.0.0.1 REDIS_URL="redis://127.0.0.1:6379/2" \
9393
POSTGRES_DB="sentry_follower" PORT=8006 KEYSTORE_PWD=ganache1 cargo run -p sentry -- \
9494
--adapter ethereum \
9595
--keystoreFile ./adapter/test/resources/0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7_keystore.json
96-
./docs/config/prod.toml
96+
./docs/config/ganache.toml
9797
```
9898

9999
#### Using the `Dummy` adapter
100100

101+
Using the dummy adapter you get access to additional route
102+
for adding deposits to the dummy adapter. The authenticated address
103+
is used to set the deposit in the adapter for the given Chain id.
104+
105+
##### `POST /v5/channel/dummy-deposit` (auth required)
106+
107+
Request body (`JSON`):
108+
109+
```json
110+
{
111+
"channel": { "leader": "0x000..", ...},
112+
"deposit": { "total": "10000000" }
113+
}
114+
```
115+
101116
**Dummy** identities:
102117

103118
##### Leader (`0x80690751969B234697e9059e04ed72195c3507fa`)
@@ -107,7 +122,7 @@ IP_ADDR=127.0.0.1 REDIS_URL="redis://127.0.0.1:6379/1" \
107122
POSTGRES_DB="sentry_leader" PORT=8005 cargo run -p sentry -- \
108123
--adapter dummy \
109124
--dummyIdentity 0x80690751969B234697e9059e04ed72195c3507fa \
110-
./docs/config/prod.toml
125+
./docs/config/ganache.toml
111126
```
112127
##### Follower (`0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7`)
113128

@@ -116,12 +131,12 @@ IP_ADDR=127.0.0.1 REDIS_URL="redis://127.0.0.1:6379/2" \
116131
POSTGRES_DB="sentry_follower" PORT=8006 cargo run -p sentry -- \
117132
--adapter dummy \
118133
--dummyIdentity 0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7 \
119-
./docs/config/prod.toml
134+
./docs/config/ganache.toml
120135
```
121136

122137
#### Environment variables
123138

124-
- `ENV` - `production` or `development`; *default*: `development` - passing this env. variable will use the default configuration paths - [`docs/config/dev.toml`](./docs/config/dev.toml) (for `development`) or [`docs/config/prod.toml`](./docs/config/prod.toml) (for `production`). Otherwise you can pass your own configuration file path to the binary (check `cargo run -p sentry --help` for more information). In `development` it will make sure Sentry to seed the database.
139+
- `ENV` - `production` or `development`; *default*: `development` - passing this env. variable will use the default configuration paths - [`docs/config/ganache.toml`](./docs/config/ganache.toml) (for `development`) or [`docs/config/prod.toml`](./docs/config/prod.toml) (for `production`). Otherwise you can pass your own configuration file path to the binary (check `cargo run -p sentry --help` for more information). In `development` it will make sure Sentry to seed the database.
125140
- `PORT` - *default*: `8005` - The local port that Sentry API will be accessible at
126141
- `IP_ADDR` - *default*: `0.0.0.0` - the IP address that the API should be listening to
127142

@@ -154,14 +169,14 @@ cargo run -p validator_worker -- --help
154169
The password for the Keystore file can be set using the environment variable `KEYSTORE_PWD`.
155170

156171
##### Validator Leader (`0x80690751969B234697e9059e04ed72195c3507fa`)
157-
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Leader** on port `8005`:
172+
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Leader** on port `8005`:
158173

159174
```bash
160175
KEYSTORE_PWD=ganache0 cargo run -p validator_worker -- \
161176
--adapter ethereum \
162177
--keystoreFile ./adapter/test/resources/0x80690751969B234697e9059e04ed72195c3507fa_keystore.json \
163178
--sentryUrl http://127.0.0.1:8005 \
164-
./docs/config/prod.toml
179+
./docs/config/ganache.toml
165180
```
166181

167182
##### Validator Follower
@@ -173,7 +188,7 @@ KEYSTORE_PWD=ganache1 cargo run -p validator_worker -- \
173188
--adapter ethereum \
174189
--keystoreFile ./adapter/test/resources/0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7_keystore.json \
175190
--sentryUrl http://127.0.0.1:8006 \
176-
./docs/config/prod.toml
191+
./docs/config/ganache.toml
177192
```
178193

179194
#### Using the `Dummy` adapter
@@ -187,7 +202,7 @@ cargo run -p validator_worker -- \
187202
--adapter dummy \
188203
--dummyIdentity 0x80690751969B234697e9059e04ed72195c3507fa \
189204
--sentryUrl http://127.0.0.1:8005 \
190-
./docs/config/prod.toml
205+
./docs/config/ganache.toml
191206
```
192207

193208
##### Follower: `0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7`
@@ -199,13 +214,12 @@ cargo run -p validator_worker -- \
199214
--adapter dummy \
200215
--dummyIdentity 0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7 \
201216
--sentryUrl http://127.0.0.1:8006 \
202-
./docs/config/prod.toml
217+
./docs/config/ganache.toml
203218
```
204219

205220
#### Environment variables
206221

207-
- `ENV` - `production` or `development` - *default*: `development` - passing this env. variable will use the default configuration paths - [`docs/config/dev.toml`](./docs/config/dev.toml) (for `development`) or [`docs/config/prod.toml`](./docs/config/prod.toml) (for `production`). Otherwise you can pass your own configuration file path to the binary (check `cargo run -p sentry --help` for more information). In `development` it will make sure that Sentry seeds the database.
208-
- `PORT` - The local port that Sentry API will accessible at
222+
- `ENV` - `production` or `development`; *default*: `development` - passing this env. variable will use the default configuration paths - [`docs/config/ganache.toml`](./docs/config/ganache.toml) (for `development`) or [`docs/config/prod.toml`](./docs/config/prod.toml) (for `production`). Otherwise you can pass your own configuration file path to the binary (check `cargo run -p sentry --help` for more information). In `development` it will make sure that Sentry seeds the database.
209223

210224
##### Adapter
211225

sentry/src/routes.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//! - [GET `/v5/channel/:id/last-approved`](#get-v5channelidlast-approved)
1616
//! - [POST `/v5/channel/:id/pay`](#post-v5channelidpay-auth-required) (auth required)
1717
//! - [GET `/v5/channel/:id/get-leaf`](#get-v5channelidget-leaf)
18+
//! - [POST `/v5/channel/dummy-deposit`](#post-v5channeldummy-deposit-auth-required) (auth required) available only with Dummy adapter
1819
//! - [Campaign](#campaign) routes
1920
//! - [GET `/v5/campaign/list`](#get-v5campaignlist)
2021
//! - [POST `/v5/campaign`](#post-v5campaign-auth-required) (auth required)
@@ -164,6 +165,18 @@
164165
//! `/get-leaf?earner=0x....`
165166
//! This module includes all routes for `Sentry` and the documentation of each Request/Response.
166167
//!
168+
//! #### POST `/v5/channel/dummy-deposit` (auth required)
169+
//!
170+
//! Set a deposit for a Channel and depositor (the authenticated address) in the Dummy adapter.
171+
//!
172+
//! **NOTE:** This route is available **only** when using the Dummy adapter.
173+
//!
174+
//! The route is handled by [`channel::channel_dummy_deposit()`].
175+
//!
176+
//! Request body (json): [`ChannelDummyDeposit`](crate::routes::channel::ChannelDummyDeposit)
177+
//!
178+
//! Response: [`SuccessResponse`](primitives::sentry::SuccessResponse)
179+
//!
167180
//! ## Campaign
168181
//!
169182
//! All routes are implemented under the module [campaign].

sentry/src/routes/channel.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ use serde::{Deserialize, Serialize};
3333
use slog::{error, Logger};
3434
use std::{any::Any, collections::HashMap, str::FromStr};
3535

36+
/// Request body for Channel deposit when using the Dummy adapter.
37+
///
38+
/// **NOTE:** available **only** when using the Dummy adapter!
39+
#[derive(Debug, Serialize, Deserialize)]
40+
pub struct ChannelDummyDeposit {
41+
pub channel: Channel,
42+
pub deposit: Deposit<UnifiedNum>,
43+
}
44+
3645
/// GET `/v5/channel/list` request
3746
///
3847
/// Query: [`ChannelListQuery`]
@@ -548,19 +557,13 @@ pub async fn channel_payout<C: Locked + 'static>(
548557

549558
/// POST `/v5/channel/dummy-deposit` request
550559
///
551-
/// Body: [`Deposit<BigNum>`]
560+
/// Request body (json): [`ChannelDummyDeposit`]
552561
///
553562
/// Response: [`SuccessResponse`]
554563
pub async fn channel_dummy_deposit<C: Locked + 'static>(
555564
req: Request<Body>,
556565
app: &Application<C>,
557566
) -> Result<Response<Body>, ResponseError> {
558-
#[derive(Debug, Serialize, Deserialize)]
559-
pub struct ChannelDummyDeposit {
560-
pub channel: Channel,
561-
pub deposit: Deposit<UnifiedNum>,
562-
}
563-
564567
let auth = req
565568
.extensions()
566569
.get::<Auth>()
@@ -583,10 +586,10 @@ pub async fn channel_dummy_deposit<C: Locked + 'static>(
583586
// if this fails, it will cause Bad Request
584587
insert_channel(&app.pool, &channel_chain).await?;
585588

586-
// Convert the UnifiedNum to BigNum with the same precision of UnifiedNum::PRECISION
587-
let deposit = Deposit {
588-
total: request.deposit.total.to_precision(UnifiedNum::PRECISION),
589-
};
589+
// Convert the UnifiedNum to BigNum with the precision of the token
590+
let deposit = request
591+
.deposit
592+
.to_precision(channel_chain.token.precision.into());
590593

591594
let dummy_adapter = <dyn Any + Send + Sync>::downcast_ref::<Adapter<Dummy>>(&app.adapter)
592595
.expect("Only Dummy adapter is allowed here!");

0 commit comments

Comments
 (0)