rialo_api_types/lib.rs
1// Copyright (c) Subzero Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! # Rialo API Types
5//!
6//! This crate provides strongly-typed, validated data structures for all Rialo RPC endpoints.
7//! It implements the JSON-RPC 2.0 specification with full Solana compatibility.
8//!
9//! ## Features
10//!
11//! - **Type Safety**: Strongly typed request and response structures for all RPC endpoints
12//! - **Input Validation**: Built-in validation using the `validator` crate with custom rules
13//! - **JSON-RPC 2.0**: Full compliance with JSON-RPC 2.0 specification
14//! - **Solana Compatibility**: Compatible with Solana RPC client libraries and tools
15//! - **Comprehensive Documentation**: Each endpoint includes examples and usage patterns
16//!
17//! ## Quick Start
18//!
19//! ```rust
20//! use rialo_api_types::{
21//! messages::get_account_info::{GetAccountInfoRequest, GetAccountInfoConfig},
22//! validation::validate_request
23//! };
24//!
25//! // Create a request
26//! let request = GetAccountInfoRequest {
27//! address: "7xB9i2AcjLNJ6M8iZ3LZJvLm7xpSmH7T5uZzR3DeVXWi".to_string(),
28//! config: Some(GetAccountInfoConfig {
29//! data_slice: None,
30//! min_context_slot: None,
31//! })
32//! };
33//!
34//! // Serialize to JSON
35//! let json = serde_json::to_string(&request).unwrap();
36//! ```
37//!
38//! ## Validation
39//!
40//! All request types support comprehensive input validation:
41//!
42//! ```rust
43//! use rialo_api_types::{
44//! messages::request_airdrop::RequestAirdropRequest,
45//! validation::validate_request
46//! };
47//!
48//! let request = RequestAirdropRequest::new(
49//! "7xB9i2AcjLNJ6M8iZ3LZJvLm7xpSmH7T5uZzR3DeVXWi".to_string(),
50//! 1_000_000_000 // 1 RLO in kelvins
51//! );
52//!
53//! // This validates the pubkey format and amount constraints
54//! let validated = validate_request(request).unwrap();
55//! ```
56//!
57//! ## Supported RPC Methods
58//!
59//! ### Account Operations
60//! - `getAccountInfo` - Get account information and data
61//! - `getBalance` - Get account balance in kelvins
62//! - `getMultipleAccounts` - Get information for multiple accounts
63//!
64//! ### Transaction Operations
65//! - `sendTransaction` - Submit a signed transaction to the network
66//! - `getTransaction` - Get transaction details and metadata
67//! - `getSignatureStatuses` - Get confirmation status of transactions
68//! - `getSignaturesForAddress` - Get transaction signatures for an address
69//!
70//! ### Block Operations
71//! - `getBlock` - Get confirmed block information
72//!
73//! ### Health & Status
74//! - `getHealth` - Node health check endpoint
75//! - `getValidatorHealth` - Validator-specific health check
76//! - `getConnectedFullNodes` - Get full nodes connected to validator
77//! - `getEpochInfo` - Get current epoch information
78//!
79//! ### Utility Operations
80//! - `requestAirdrop` - Request test tokens (devnet/testnet only)
81//! - `getMinimumBalanceForRentExemption` - Get minimum balance for rent exemption
82//! - `getFeeForMessage` - Calculate transaction fees
83//! - `isBlockhashValid` - Check if a blockhash is still valid
84//!
85//! ### Rialo-Specific Operations
86//! - `getWorkflowLineage` - Get workflow transaction lineage and relationships
87//! - `getTriggeredTransactions` - Get transactions triggered by events
88//! - `getSubscription` - Get subscription by subscriber and nonce
89//! - `getTransactionCount` - Get total transaction count
90//!
91//! ## Error Handling
92//!
93//! ```rust
94//! use rialo_api_types::validation::{ValidationError, ValidationResult};
95//! use rialo_api_types::messages::request_airdrop::RequestAirdropRequest;
96//!
97//! fn handle_validation_error(result: ValidationResult<RequestAirdropRequest>) {
98//! match result {
99//! Ok(data) => { /* Use validated data */ }
100//! Err(ValidationError::InvalidPublicKey(msg)) => {
101//! println!("Invalid public key: {}", msg);
102//! }
103//! Err(ValidationError::Multiple(msg)) => {
104//! println!("Multiple validation errors: {}", msg);
105//! }
106//! Err(err) => {
107//! println!("Validation failed: {}", err);
108//! }
109//! }
110//! }
111//! ```
112//!
113//! ## JSON-RPC 2.0 Format
114//!
115//! All requests follow the JSON-RPC 2.0 specification:
116//!
117//! ```json
118//! {
119//! "jsonrpc": "2.0",
120//! "id": 1,
121//! "method": "getAccountInfo",
122//! "params": [
123//! "7xB9i2AcjLNJ6M8iZ3LZJvLm7xpSmH7T5uZzR3DeVXWi"
124//! ]
125//! }
126//! ```
127//!
128//! Responses include context information and follow the same format:
129//!
130//! ```json
131//! {
132//! "jsonrpc": "2.0",
133//! "id": 1,
134//! "result": {
135//! "context": {
136//! "slot": 1234567
137//! },
138//! "value": {
139//! "kelvins": 1000000000,
140//! "data": ["SGVsbG8gV29ybGQ=", "base64"],
141//! "owner": "11111111111111111111111111111111",
142//! "executable": false,
143//! "rentEpoch": 200
144//! }
145//! }
146//! }
147//! ```
148
149pub mod constants;
150pub mod messages;
151pub mod parameters;
152pub mod requests;
153pub mod validation;
154
155#[cfg(test)]
156mod validation_test;
157
158#[cfg(test)]
159mod integration_test;
160
161// Re-export commonly used types for convenience
162pub use messages::{
163 get_block::{GetBlockRequest, GetBlockResponse},
164 get_connected_full_nodes::GetConnectedFullNodesResponse,
165 get_health::GetHealthResponse,
166 get_signature_statuses::GetSignatureStatusesRequest,
167 get_transaction_count::GetTransactionCountResponse,
168 get_validator_health::{GetValidatorHealthResponse, ValidatorHealthStatus},
169 get_workflow_lineage::{GetWorkflowLineageRequest, GetWorkflowLineageResponse},
170 request_airdrop::{RequestAirdropRequest, RequestAirdropResponse},
171 rpc_response_context::RpcResponseContext,
172};