Skip to content

Commit 06522b6

Browse files
committed
documentation for SpenderResponse + examples
1 parent 4100734 commit 06522b6

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

primitives/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ required-features = ["test-util"]
4848
[[example]]
4949
name = "modify_campaign"
5050

51+
[[example]]
52+
name = "spender_response"
53+
5154
[dependencies]
5255
# (De)Serialization
5356
serde = { version = "1.0", features = ["derive"] }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use primitives::{sentry::SpenderResponse};
2+
use serde_json::{from_value, json};
3+
4+
fn main() {
5+
let json = json!({
6+
"spender": {
7+
"totalDeposited": "10000000000",
8+
"totalSpent": "100000000",
9+
},
10+
});
11+
assert!(from_value::<SpenderResponse>(json).is_ok());
12+
}

primitives/src/sentry.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,13 @@ pub struct SuccessResponse {
598598
pub success: bool,
599599
}
600600

601+
/// Spender limits for a spender on a channel.
602+
///
603+
/// # Examples
604+
///
605+
/// ```
606+
#[doc = include_str!("../examples/spender_response.rs")]
607+
/// ```
601608
#[derive(Serialize, Deserialize, Debug)]
602609
#[serde(rename_all = "camelCase")]
603610
pub struct SpenderResponse {

sentry/src/routes.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,19 @@
7070
//! ```
7171
//!
7272
//! #### GET `/v5/channel/:id/spender/:addr` (auth required)
73+
//!
74+
//! Gets the spender limits for a spender on a channel. It does so by fetching the
75+
//! latest Spendable entry from the database (or creating one if it doesn't exist yet) from which
76+
//! the total deposited amount is retrieved, and the latest NewState from which the total spent
77+
//! amount is retrieved.
7378
//!
7479
//! The route is handled by [`channel::get_spender_limits()`].
7580
//!
76-
//! Response: [`SpenderResponse`](primitives::sentry::SpenderResponse)
81+
//! Response:
82+
//!
83+
//! ```
84+
#![doc = include_str!("../../primitives/examples/spender_response.rs")]
85+
//! ```
7786
//!
7887
//! #### POST `/v5/channel/:id/spender/:addr` (auth required)
7988
//!

0 commit comments

Comments
 (0)