Skip to content

Commit 1013686

Browse files
committed
requested changes
1 parent 1b26f62 commit 1013686

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

sentry/src/routes.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
//! ```
238238
//!
239239
//!
240-
//! #### GET `/v5/channel/:id/get-leaf/spender` and GET `/v5/channel/:id/get-leaf/earner`
240+
//! #### GET `/v5/channel/:id/get-leaf
241241
//!
242242
//! This route gets the latest approved state ([`NewState`]/[`ApproveState`] pair),
243243
//! and finds the given `spender`/`earner` in the balances tree, and produce a merkle proof for it.
@@ -247,11 +247,11 @@
247247
//!
248248
//! Example Spender:
249249
//!
250-
//! `/get-leaf/spender/0x...`
250+
//! `/get-leaf/spender/0xDd589B43793934EF6Ad266067A0d1D4896b0dff0`
251251
//!
252252
//! Example Earner:
253253
//!
254-
//! `/get-leaf/earner/0x....`
254+
//! `/get-leaf/earner/0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9`
255255
//!
256256
//! Response: [`GetLeafResponse`](primitives::sentry::GetLeafResponse)
257257
//!
@@ -263,6 +263,10 @@
263263
#![doc = include_str!("../../primitives/examples/spender_response.rs")]
264264
//! ```
265265
//!
266+
//! #### Subroutes:
267+
//! - GET `/v5/channel/:id/get-leaf/spender`
268+
//! - GET `/v5/channel/:id/get-leaf/earner`
269+
//!
266270
//! This module includes all routes for `Sentry` and the documentation of each Request/Response.
267271
//!
268272
//! #### POST `/v5/channel/dummy-deposit` (auth required)

sentry/src/routes/channel.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,11 @@ pub async fn channel_payout<C: Locked + 'static>(
504504
Ok(Json(SuccessResponse { success: true }))
505505
}
506506

507-
/// GET `/v5/channel/0xXXX.../get-leaf/spender` request and
508-
/// GET `/v5/channel/0xXXX.../get-leaf/earner` request
507+
/// GET `/v5/channel/0xXXX.../get-leaf/` request
508+
///
509+
/// Subroutes:
510+
/// - /v5/channel/0xXXX.../get-leaf/spender
511+
/// - /v5/channel/0xXXX.../get-leaf/earner
509512
///
510513
/// Response: [`GetLeafResponse`]
511514
pub async fn get_leaf<C: Locked + 'static>(
@@ -518,11 +521,7 @@ pub async fn get_leaf<C: Locked + 'static>(
518521

519522
let approve_state = match latest_approve_state(&app.pool, &channel).await? {
520523
Some(approve_state) => approve_state,
521-
None => {
522-
return Err(ResponseError::BadRequest(
523-
"No ApproveState message for spender".to_string(),
524-
))
525-
}
524+
None => return Err(ResponseError::NotFound),
526525
};
527526

528527
let state_root = approve_state.msg.state_root.clone();
@@ -535,9 +534,12 @@ pub async fn get_leaf<C: Locked + 'static>(
535534

536535
let element = match leaf_for {
537536
LeafFor::Spender => {
538-
let amount = new_state.msg.balances.spenders.get(&addr).ok_or_else(|| {
539-
ResponseError::BadRequest("No balance entry for spender!".to_string())
540-
})?;
537+
let amount = new_state
538+
.msg
539+
.balances
540+
.spenders
541+
.get(&addr)
542+
.ok_or(ResponseError::NotFound)?;
541543

542544
get_balance_leaf(
543545
true,
@@ -546,9 +548,12 @@ pub async fn get_leaf<C: Locked + 'static>(
546548
)?
547549
}
548550
LeafFor::Earner => {
549-
let amount = new_state.msg.balances.earners.get(&addr).ok_or_else(|| {
550-
ResponseError::BadRequest("No balance entry for spender!".to_string())
551-
})?;
551+
let amount = new_state
552+
.msg
553+
.balances
554+
.earners
555+
.get(&addr)
556+
.ok_or(ResponseError::NotFound)?;
552557

553558
get_balance_leaf(
554559
false,

0 commit comments

Comments
 (0)