Skip to content

Commit 75b56d6

Browse files
committed
get-leaf documentation
1 parent eb4d517 commit 75b56d6

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

primitives/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ name = "modify_campaign_request"
6363
[[example]]
6464
name = "spender_response"
6565

66+
[[example]]
67+
name = "get_leaf_response"
68+
6669
[[example]]
6770
name = "validator_messages_create_request"
6871

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use primitives::sentry::GetLeafResponse;
2+
use serde_json::{from_value, json};
3+
4+
fn main() {
5+
let json = json!({
6+
"merkleProof": "8ea7760ca2dbbe00673372afbf8b05048717ce8a305f1f853afac8c244182e0c",
7+
});
8+
9+
assert!(from_value::<GetLeafResponse>(json).is_ok());
10+
}

primitives/src/sentry.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,13 @@ pub struct ValidationErrorResponse {
722722
pub validation: Vec<String>,
723723
}
724724

725+
/// Returns the merkle_proof for the spender/earner
726+
///
727+
/// # Examples
728+
///
729+
/// ```
730+
#[doc = include_str!("../examples/get_leaf_response.rs")]
731+
/// ```
725732
#[derive(Serialize, Deserialize, Debug)]
726733
#[serde(rename_all = "camelCase")]
727734
pub struct GetLeafResponse {

sentry/src/routes.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,27 +237,32 @@
237237
//! ```
238238
//!
239239
//!
240-
//! #### GET `/v5/channel/:id/get-leaf`
241-
//!
242-
//! TODO: implement and document as part of issue #382
240+
//! #### GET `/v5/channel/:id/get-leaf/spender` and GET `/v5/channel/:id/get-leaf/earner`
243241
//!
244242
//! This route gets the latest approved state ([`NewState`]/[`ApproveState`] pair),
245243
//! and finds the given `spender`/`earner` in the balances tree, and produce a merkle proof for it.
246244
//! This is useful for the Platform to verify if a spender leaf really exists.
247245
//!
248-
//! The route is handled by `todo`.
249-
//!
250-
//! Request query parameters:
251-
//!
252-
//! - `spender=[0x...]` or `earner=[0x...]` (required)
246+
//! The route is handled by [`channel::get_leaf()`].
253247
//!
254248
//! Example Spender:
255249
//!
256-
//! `/get-leaf?spender=0x...`
250+
//! `/get-leaf/spender/0x...`
257251
//!
258252
//! Example Earner:
259253
//!
260-
//! `/get-leaf?earner=0x....`
254+
//! `/get-leaf/earner/0x....`
255+
//!
256+
//! Response: [`GetLeafResponse`](primitives::sentry::GetLeafResponse)
257+
//!
258+
//! ##### Examples:
259+
//!
260+
//! Response:
261+
//!
262+
//! ```
263+
#![doc = include_str!("../../primitives/examples/spender_response.rs")]
264+
//! ```
265+
//!
261266
//! This module includes all routes for `Sentry` and the documentation of each Request/Response.
262267
//!
263268
//! #### POST `/v5/channel/dummy-deposit` (auth required)

sentry/src/routes/channel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ 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
509+
///
510+
/// Response: [`GetLeafResponse`]
507511
pub async fn get_leaf<C: Locked + 'static>(
508512
Extension(app): Extension<Arc<Application<C>>>,
509513
Extension(channel_context): Extension<ChainOf<Channel>>,

0 commit comments

Comments
 (0)