Skip to content

Commit 24b42af

Browse files
committed
get-leaf docs improvements
1 parent 1013686 commit 24b42af

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

primitives/src/sentry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ pub struct ValidationErrorResponse {
722722
pub validation: Vec<String>,
723723
}
724724

725-
/// Returns the merkle_proof for the spender/earner
725+
/// Get leaf response with the Merkle proof for the requested spender/earner.
726726
///
727727
/// # Examples
728728
///

sentry/src/routes.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Sentry REST API documentation
22
//!
3+
//! This module includes the documentation for all routes of the `Sentry`
4+
//! REST API and the corresponding requests, responses and parameters.
35
//!
46
//! All routes are listed below. Here is an overview and links to all of them:
57
//! - [Channel](#channel) routes
@@ -236,39 +238,37 @@
236238
#![doc = include_str!("../../primitives/examples/channel_pay_request.rs")]
237239
//! ```
238240
//!
239-
//!
240241
//! #### GET `/v5/channel/:id/get-leaf
241242
//!
242243
//! This route gets the latest approved state ([`NewState`]/[`ApproveState`] pair),
243-
//! and finds the given `spender`/`earner` in the balances tree, and produce a merkle proof for it.
244+
//! finds the given `spender` or `earner` in the balances tree and produces a Merkle proof for it.
244245
//! This is useful for the Platform to verify if a spender leaf really exists.
245246
//!
246247
//! The route is handled by [`channel::get_leaf()`].
247248
//!
248-
//! Example Spender:
249+
//! Response: [`GetLeafResponse`](primitives::sentry::GetLeafResponse)
249250
//!
250-
//! `/get-leaf/spender/0xDd589B43793934EF6Ad266067A0d1D4896b0dff0`
251+
//! ##### Routes:
251252
//!
252-
//! Example Earner:
253+
//! - GET `/v5/channel/:id/get-leaf/spender/:addr`
254+
//! - GET `/v5/channel/:id/get-leaf/earner/:addr`
253255
//!
254-
//! `/get-leaf/earner/0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9`
256+
//! ##### Examples:
255257
//!
256-
//! Response: [`GetLeafResponse`](primitives::sentry::GetLeafResponse)
258+
//! URI for retrieving leaf of a Spender:
257259
//!
258-
//! ##### Examples:
260+
//! `/v5/channel/0xf147fa3f1c5e5e06d359c15aa082442cc3e0380f306306022d1e9047c565a0f9/get-leaf/spender/0xDd589B43793934EF6Ad266067A0d1D4896b0dff0`
261+
//!
262+
//! URI for retrieving leaf of an Earner:
263+
//!
264+
//! `/v5/channel/0xf147fa3f1c5e5e06d359c15aa082442cc3e0380f306306022d1e9047c565a0f9/get-leaf/earner/0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9`
259265
//!
260266
//! Response:
261267
//!
262268
//! ```
263-
#![doc = include_str!("../../primitives/examples/spender_response.rs")]
269+
#![doc = include_str!("../../primitives/examples/get_leaf_response.rs")]
264270
//! ```
265271
//!
266-
//! #### Subroutes:
267-
//! - GET `/v5/channel/:id/get-leaf/spender`
268-
//! - GET `/v5/channel/:id/get-leaf/earner`
269-
//!
270-
//! This module includes all routes for `Sentry` and the documentation of each Request/Response.
271-
//!
272272
//! #### POST `/v5/channel/dummy-deposit` (auth required)
273273
//!
274274
//! Set a deposit for a Channel and depositor (the authenticated address) in the Dummy adapter.

sentry/src/routes/channel.rs

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

507-
/// GET `/v5/channel/0xXXX.../get-leaf/` request
507+
/// GET `/v5/channel/0xXXX.../get-leaf` requests
508508
///
509-
/// Subroutes:
510-
/// - /v5/channel/0xXXX.../get-leaf/spender
511-
/// - /v5/channel/0xXXX.../get-leaf/earner
509+
/// # Routes:
510+
///
511+
/// - GET `/v5/channel/:id/get-leaf/spender/:addr`
512+
/// - GET `/v5/channel/:id/get-leaf/earner/:addr`
512513
///
513514
/// Response: [`GetLeafResponse`]
514515
pub async fn get_leaf<C: Locked + 'static>(
@@ -519,10 +520,9 @@ pub async fn get_leaf<C: Locked + 'static>(
519520
) -> Result<Json<GetLeafResponse>, ResponseError> {
520521
let channel = channel_context.context;
521522

522-
let approve_state = match latest_approve_state(&app.pool, &channel).await? {
523-
Some(approve_state) => approve_state,
524-
None => return Err(ResponseError::NotFound),
525-
};
523+
let approve_state = latest_approve_state(&app.pool, &channel)
524+
.await?
525+
.ok_or(ResponseError::NotFound)?;
526526

527527
let state_root = approve_state.msg.state_root.clone();
528528

@@ -566,9 +566,9 @@ pub async fn get_leaf<C: Locked + 'static>(
566566

567567
let signable_state_root = get_signable_state_root(channel.id().as_bytes(), &merkle_tree.root());
568568

569-
let res = hex::encode(signable_state_root);
569+
let merkle_proof = hex::encode(signable_state_root);
570570

571-
Ok(Json(GetLeafResponse { merkle_proof: res }))
571+
Ok(Json(GetLeafResponse { merkle_proof }))
572572
}
573573

574574
/// POST `/v5/channel/dummy-deposit` request

0 commit comments

Comments
 (0)