Skip to content

Commit f985fba

Browse files
authored
Document entire crate (#21)
1 parent 4cf167e commit f985fba

23 files changed

+2326
-568
lines changed

src/accounts/accounts_request.rs

Lines changed: 223 additions & 105 deletions
Large diffs are not rendered by default.

src/accounts/accounts_response.rs

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,159 @@ use serde::{Deserialize, Serialize};
33

44
use crate::models::Response;
55

6-
/// Struct defining the self link in the list all accounts response.
6+
/// Represents the self-link in the list of all accounts response.
7+
///
8+
/// This struct defines the structure of the self-link (`href`) found in the accounts response
9+
/// from the Horizon API. It contains the URL to the current resource or query.
10+
///
711
#[derive(Debug, Deserialize, Serialize, Clone, Getters)]
812
pub struct AccountsResponseSelfLink {
13+
/// A `String` representing the hyperlink reference to the current resource or query.
914
href: String,
1015
}
1116

12-
/// Struct defining the links in the list all accounts response.
17+
/// Represents the various links in the list of all accounts response.
18+
///
19+
/// This struct encapsulates the different types of navigational links (self, next, previous)
20+
/// in the accounts response. Each link is an instance of [`AccountsResponseSelfLink`].
21+
///
1322
#[derive(Debug, Deserialize, Serialize, Clone, Getters)]
1423
pub struct AccountsResponseLinks {
1524
#[serde(rename = "self")]
25+
/// The link to the current page of account records.
1626
self_link: AccountsResponseSelfLink,
27+
/// An optional link to the next page of account records.
1728
next: Option<AccountsResponseSelfLink>,
29+
/// An optional link to the previous page of account records.
1830
prev: Option<AccountsResponseSelfLink>,
1931
}
2032

21-
/// Struct defining a single balance in the list all accounts response.
33+
/// Represents a single balance within an account in the list of all accounts response.
34+
///
35+
/// This struct details the balance information for an account, including the type of asset
36+
/// and the associated liabilities.
37+
///
2238
#[derive(Debug, Deserialize, Serialize, Clone, Getters)]
2339
pub struct Balances {
40+
/// The total balance of the asset.
2441
balance: String,
42+
/// Buying liabilities associated with the asset.
2543
buying_liabilities: String,
44+
/// Selling liabilities associated with the asset.
2645
selling_liabilities: String,
46+
/// The type of asset (e.g., native, credit_alphanum4, credit_alphanum12).
2747
asset_type: String,
2848
}
2949

30-
/// Struct defining the thresholds in the list all accounts response.
50+
/// Represents the thresholds associated with an account in the list of all accounts response.
51+
///
52+
/// This struct encapsulates the various threshold values for different operations in an account.
53+
///
3154
#[derive(Debug, Deserialize, Serialize, Clone, Getters)]
3255
pub struct AccountsResponseThresholds {
56+
/// The threshold for low-level operations.
3357
low_threshold: i32,
58+
/// The threshold for medium-level operations.
3459
med_threshold: i32,
60+
/// The threshold for high-level operations.
3561
high_threshold: i32,
3662
}
3763

38-
/// Struct defining the flags in the list all accounts response.
64+
/// Represents the flags set on an account in the list of all accounts response.
65+
///
66+
/// This struct defines the various boolean flags that can be set on an account,
67+
/// indicating specific permissions or settings.
68+
///
3969
#[derive(Debug, Deserialize, Serialize, Clone, Getters)]
4070
pub struct AccountsResponseFlags {
71+
/// Indicates if authorization is required for transactions.
4172
auth_required: bool,
73+
/// Indicates if authorization can be revoked.
4274
auth_revocable: bool,
75+
/// Indicates if the account's authorization settings cannot be changed.
4376
auth_immutable: bool,
77+
/// Indicates if the clawback feature is enabled.
4478
auth_clawback_enabled: bool,
4579
}
4680

47-
/// Struct defining a single signer in the list all accounts response.
81+
/// Represents a signer associated with an account in the list of all accounts response.
82+
///
83+
/// This struct details the information about a signer for an account, including their
84+
/// key, type, and weight in authorization decisions.
85+
///
4886
#[derive(Debug, Deserialize, Serialize, Clone, Getters)]
4987
pub struct Signers {
88+
/// The weight of the signer's vote in authorization decisions.
5089
weight: i32,
90+
/// The key associated with the signer.
5191
key: String,
92+
/// The type of the signer (e.g., 'ed25519_public_key').
5293
#[serde(rename = "type")]
5394
signer_type: String,
5495
}
5596

56-
/// Struct defining a record of a single account in the list all accounts response.
97+
/// Represents a single account record in the list of all accounts response.
98+
///
99+
/// This struct encapsulates detailed information about an individual account as returned
100+
/// in the Horizon API response. It includes various fields like account identifiers,
101+
/// thresholds, flags, balances, and more.
102+
///
57103
#[derive(Debug, Deserialize, Serialize, Clone, Getters)]
58104
pub struct Record {
105+
/// Links associated with this account record.
59106
#[serde(rename = "_links")]
60107
links: AccountsResponseLinks,
108+
/// The unique identifier of the account.
61109
id: String,
110+
/// The public key of the account.
62111
account_id: String,
112+
/// The sequence number of the account.
63113
sequence: String,
114+
/// The number of subentries in the account.
64115
subentry_count: i32,
65116
last_modified_ledger: u64,
66117
last_modified_time: String,
118+
/// The thresholds for different operations in the account.
67119
thresholds: AccountsResponseThresholds,
120+
/// The flags set on the account.
68121
flags: AccountsResponseFlags,
122+
/// A list of balances for different assets held by the account.
69123
balances: Vec<Balances>,
124+
/// A list of signers associated with the account.
70125
signers: Vec<Signers>,
126+
/// Additional data associated with the account (in JSON format).
71127
data: serde_json::Value,
128+
/// The number of entries the account is sponsoring.
72129
num_sponsoring: i32,
130+
/// The number of entries the account is sponsored for.
73131
num_sponsored: i32,
132+
/// A token used for paging through results.
74133
paging_token: String,
75134
}
76135

77-
/// Struct defining the embedded object in the list all accounts response.
136+
/// Represents the embedded part of the list all accounts response.
137+
///
138+
/// This struct is used to hold the actual array of account records ([`Record`]) as part of
139+
/// the Horizon API response. It serves as a container for the data portion of the response.
140+
///
78141
#[derive(Debug, Deserialize, Serialize, Clone, Getters)]
79142
pub struct Embedded {
143+
/// * `records`: A vector of [`Record`] structs, each representing an individual account.
80144
records: Vec<Record>,
81145
}
82146

83-
/// Struct defining the list all accounts response.
147+
148+
/// Represents the entire response for the list all accounts query.
149+
///
150+
/// This struct defines the overall structure of the response returned from the Horizon API
151+
/// when querying for multiple accounts. It includes navigational links and the embedded data
152+
/// containing account records.
153+
///
84154
#[derive(Debug, Deserialize, Serialize, Clone, Getters)]
85155
pub struct AccountsResponse {
156+
/// Navigational links related to the response.
86157
_links: AccountsResponseLinks,
158+
/// The embedded object containing the actual account records.
87159
_embedded: Embedded,
88160
}
89161

src/accounts/mod.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,89 @@
1+
/// Provides the `AccountsRequest`.
2+
///
3+
/// This module provides the `AccountsRequest` struct, which is specifically designed
4+
/// for constructing requests to query for multiple accounts from the Horizon server. It is
5+
/// is meant to be used with the [`HorizonClient::get_accounts_list`](crate::horizon_client::HorizonClient::get_account_list)
6+
/// method.
7+
///
18
pub mod accounts_request;
9+
10+
11+
/// Provides the `AccountsResponse`.
12+
///
13+
/// This module provides a set of structures that represent the response received from the Horizon
14+
/// API when querying for accounts. These structures are designed to translate the JSON response
15+
/// from the Horizon server into proper Rust objects, facilitating the processing and utilization
16+
/// of account data within the client application.
17+
/// For a more elaborate overview of the returned values, please refer to the documentation of the
18+
/// <a href="https://developers.stellar.org/api/horizon/resources/list-all-accounts">List All Accounts endpoint</a>.
19+
///
20+
/// These structures are mainly used internally by the `HorizonClient` when processing responses from
21+
/// account-related API calls. The [`AccountsResponse`](crate::accounts::accounts_response::AccountsResponse) struct is of special importance here,
22+
/// as it is returned by the [`HorizonClient::get_accounts_list`](crate::horizon_client::HorizonClient::get_account_list) method,
23+
/// providing a user-friendly way to access account data.
24+
///
225
pub mod accounts_response;
26+
27+
28+
/// Provides the `SingleAccountRequest`.
29+
///
30+
/// This module provides the `SingleAccountRequest` struct, specifically designed for
31+
/// constructing requests to query information about a single account from the Horizon
32+
/// server. It is tailored for use with the [`HorizonClient::get_single_account`](crate::horizon_client::HorizonClient::get_single_account)
33+
/// method.
34+
///
335
pub mod single_account_request;
36+
37+
38+
/// Provides the `SingleAccountResponse`.
39+
///
40+
/// This module defines structures representing the response from the Horizon API when querying
41+
/// for a single account. The structures are designed to deserialize the JSON response into Rust
42+
/// objects, enabling straightforward access to various details of a single Stellar account.
43+
///
44+
/// These structures are equipped with serialization capabilities to handle the JSON data from the
45+
/// Horizon server and with getter methods for easy field access.
46+
///
447
pub mod single_account_response;
548

49+
/// The base path for account-related endpoints in the Horizon API.
50+
///
51+
/// # Usage
52+
/// This variable is intended to be used internally by the request-building logic
53+
/// to ensure consistent and accurate path construction for account-related API calls.
54+
///
655
static ACCOUNTS_PATH: &str = "accounts";
756

57+
/// The `prelude` module of the `accounts` module.
58+
///
59+
/// This module serves as a convenience for users of the Horizon Rust SDK, allowing for easy and
60+
/// ergonomic import of the most commonly used items across various modules. It re-exports
61+
/// key structs and traits from the sibling modules, simplifying access to these components
62+
/// when using the library.
63+
///
64+
/// By importing the contents of `prelude`, users can conveniently access the primary
65+
/// functionalities of the accounts-related modules without needing to import each item
66+
/// individually.
67+
///
68+
/// # Contents
69+
///
70+
/// The `prelude` includes the following re-exports:
71+
///
72+
/// * From `accounts_request`: All items (e.g., `AccountsRequest`).
73+
/// * From `accounts_response`: All items (e.g., `AccountsResponse`, `Record`, etc.).
74+
/// * From `single_account_request`: All items (e.g., `SingleAccountRequest`).
75+
/// * From `single_account_response`: All items (e.g., `SingleAccountResponse`, `Balance`, etc.).
76+
///
77+
/// # Example
78+
/// ```
79+
/// # use crate::stellar_rust_sdk::models::*;
80+
/// // Import the contents of the account prelude
81+
/// use stellar_rust_sdk::accounts::prelude::*;
82+
///
83+
/// // Now you can directly use AccountsRequest, SingleAccountResponse, etc.
84+
/// let account_request = AccountsRequest::new();
85+
/// ```
86+
///
887
pub mod prelude {
988
pub use super::accounts_request::*;
1089
pub use super::accounts_response::*;

src/accounts/single_account_request.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,55 @@
11
use crate::models::{is_public_key, Request};
22

3+
/// Represents a query parameter for the account's public key
34
#[derive(Default, Clone)]
45
pub struct AccountId(String);
6+
/// Represents the absence of a query parameter for the account's public key
57
#[derive(Default, Clone)]
68
pub struct NoAccountId;
79

8-
/// SingleAccountRequest is the request for the /accounts endpoint to get a single account.
9-
/// [More Details](https://developers.stellar.org/api/horizon/resources/retrieve-an-account "Accounts")
10+
/// Represents a request to fetch details of a single account from the Horizon API.
11+
///
12+
/// `SingleAccountRequest` is a struct tailored to querying details of a specific account
13+
/// on the Horizon API. This struct is designed to be used in conjunction with the
14+
/// [`HorizonClient::get_single_account`](crate::horizon_client::HorizonClient::get_single_account) method.
15+
///
16+
/// The struct matches the parameters necessary to construct a request for the
17+
/// <a href="https://developers.stellar.org/api/horizon/resources/retrieve-an-account">Retrieve An Account endpoint</a>
18+
/// of the Horizon API.
19+
///
20+
/// # Fields
21+
/// Required:
22+
/// * `account_id` - The account's public key.
23+
///
24+
/// ## Usage
25+
/// Instances of `SingleAccountRequest` are created and configured using setter methods for each
26+
/// parameter.
27+
/// ```
28+
/// # use stellar_rust_sdk::accounts::prelude::SingleAccountRequest;
29+
/// # use stellar_rust_sdk::models::Request;
30+
/// let request = SingleAccountRequest::new()
31+
/// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string())
32+
/// .unwrap();
33+
/// // Use with HorizonClient::get_single_account
34+
/// ```
35+
///
1036
#[derive(Default)]
1137
pub struct SingleAccountRequest<I> {
12-
/// Account ID of the sponsor. Every account in the response will either be sponsored by the given account ID or have a subentry (trustline, offer, or data entry) which is sponsored by the given account ID.
38+
/// The account's public key.
1339
account_id: I,
1440
}
1541

1642
impl SingleAccountRequest<NoAccountId> {
43+
/// Creates a new `SingleAccountRequest` with default parameters.
1744
pub fn new() -> Self {
1845
SingleAccountRequest::default()
1946
}
2047

21-
/// Sets the account ID of the account to get.
48+
/// Sets the account ID for the request.
49+
///
2250
/// # Arguments
23-
/// * `account_id` - The account ID of the account to get.
24-
/// # Returns
25-
/// The request object
26-
/// [SingleAccountRequest](struct.SingleAccountRequest.html)
51+
/// * `account_id` - A `String` specifying the account's public key.
52+
///
2753
pub fn set_account_id(
2854
self,
2955
account_id: String,

0 commit comments

Comments
 (0)