Skip to content

Commit bcbecb4

Browse files
committed
Documentation for channel accounting
1 parent 3921688 commit bcbecb4

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

primitives/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ postgres = ["bytes", "tokio-postgres", "deadpool-postgres"]
2020
# All Addresses and keystore files exist in the ganache-cli setup for testing with the EthereumAdapter
2121
test-util = []
2222

23+
[[example]]
24+
name = "accounting_response"
25+
2326
[[example]]
2427
name = "analytics_query"
2528

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use primitives::{sentry::AccountingResponse, balances::CheckedState};
2+
use serde_json::{from_value, json};
3+
4+
fn main() {
5+
6+
7+
// Empty balances
8+
{
9+
let json = json!({
10+
"earners": {},
11+
"spenders": {},
12+
});
13+
assert!(from_value::<AccountingResponse::<CheckedState>>(json).is_ok());
14+
}
15+
16+
// Non-empty balances
17+
{
18+
// earners sum and spenders sum should always match since balances are CheckedState
19+
let json = json!({
20+
"earners": {
21+
"0x0000000000000000000000000000000000000000": "10000000000",
22+
"0x1111111111111111111111111111111111111111": "20000000000",
23+
"0x2222222222222222222222222222222222222222": "30000000000",
24+
},
25+
"spenders": {
26+
"0x7777777777777777777777777777777777777777": "60000000000",
27+
},
28+
});
29+
assert!(from_value::<AccountingResponse::<CheckedState>>(json).is_ok());
30+
}
31+
}

primitives/src/sentry.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ pub use event::{Event, EventType, CLICK, IMPRESSION};
2424
#[serde(rename_all = "camelCase")]
2525
/// Channel Accounting response
2626
/// A collection of all `Accounting`s for a specific `Channel`
27+
///
28+
/// # Examples
29+
///
30+
/// ```
31+
#[doc = include_str!("../examples/accounting_response.rs")]
32+
/// ```
2733
pub struct AccountingResponse<S: BalancesState> {
2834
#[serde(flatten, bound = "S: BalancesState")]
2935
pub balances: Balances<S>,

sentry/src/routes.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@
5959
//!
6060
//! #### GET `/v5/channel/:id/accounting`
6161
//!
62+
//! Gets all of the accounting entries for a channel from the database and checks the balances.
63+
//!
6264
//! The route is handled by [`channel::get_accounting_for_channel()`].
6365
//!
64-
//! Response: [`AccountingResponse::<CheckedState>`](primitives::sentry::AccountingResponse)
66+
//! Response:
67+
//!
68+
//! ```
69+
#![doc = include_str!("../../primitives/examples/accounting_response.rs")]
70+
//! ```
6571
//!
6672
//! #### GET `/v5/channel/:id/spender/:addr` (auth required)
6773
//!

0 commit comments

Comments
 (0)