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//!         encoding: Some("base64".to_string()),
30//!         data_slice: None,
31//!         min_context_slot: None,
32//!     })
33//! };
34//!
35//! // Serialize to JSON
36//! let json = serde_json::to_string(&request).unwrap();
37//! ```
38//!
39//! ## Validation
40//!
41//! All request types support comprehensive input validation:
42//!
43//! ```rust
44//! use rialo_api_types::{
45//!     messages::request_airdrop::RequestAirdropRequest,
46//!     validation::validate_request
47//! };
48//!
49//! let request = RequestAirdropRequest::new(
50//!     "7xB9i2AcjLNJ6M8iZ3LZJvLm7xpSmH7T5uZzR3DeVXWi".to_string(),
51//!     1_000_000_000 // 1 SOL in lamports
52//! );
53//!
54//! // This validates the pubkey format and amount constraints
55//! let validated = validate_request(request).unwrap();
56//! ```
57//!
58//! ## Supported RPC Methods
59//!
60//! ### Account Operations
61//! - `getAccountInfo` - Get account information and data
62//! - `getBalance` - Get account balance in lamports  
63//! - `getMultipleAccounts` - Get information for multiple accounts
64//!
65//! ### Transaction Operations  
66//! - `sendTransaction` - Submit a signed transaction to the network
67//! - `getTransaction` - Get transaction details and metadata
68//! - `getSignatureStatuses` - Get confirmation status of transactions
69//! - `getSignaturesForAddress` - Get transaction signatures for an address
70//!
71//! ### Block Operations
72//! - `getBlock` - Get confirmed block information
73//! - `getLatestBlockhash` - Get the latest blockhash
74//!
75//! ### Health & Status
76//! - `getHealth` - Node health check endpoint
77//! - `getValidatorHealth` - Validator-specific health check
78//! - `getConnectedFullNodes` - Get full nodes connected to validator
79//! - `getEpochInfo` - Get current epoch information
80//!
81//! ### Utility Operations
82//! - `requestAirdrop` - Request test tokens (devnet/testnet only)
83//! - `getMinimumBalanceForRentExemption` - Get minimum balance for rent exemption
84//! - `getFeeForMessage` - Calculate transaction fees
85//! - `isBlockhashValid` - Check if a blockhash is still valid
86//!
87//! ### Rialo-Specific Operations
88//! - `getWorkflowLineage` - Get workflow transaction lineage and relationships
89//! - `getTriggeredTransactions` - Get transactions triggered by events
90//! - `getSubscriptions` - Get active WebSocket subscriptions
91//! - `getTransactionCount` - Get total transaction count
92//!
93//! ## Error Handling
94//!
95//! ```rust
96//! use rialo_api_types::validation::{ValidationError, ValidationResult};
97//! use rialo_api_types::messages::request_airdrop::RequestAirdropRequest;
98//!
99//! fn handle_validation_error(result: ValidationResult<RequestAirdropRequest>) {
100//!     match result {
101//!         Ok(data) => { /* Use validated data */ }
102//!         Err(ValidationError::InvalidPublicKey(msg)) => {
103//!             println!("Invalid public key: {}", msg);
104//!         }
105//!         Err(ValidationError::Multiple(msg)) => {
106//!             println!("Multiple validation errors: {}", msg);
107//!         }
108//!         Err(err) => {
109//!             println!("Validation failed: {}", err);
110//!         }
111//!     }
112//! }
113//! ```
114//!
115//! ## JSON-RPC 2.0 Format
116//!
117//! All requests follow the JSON-RPC 2.0 specification:
118//!
119//! ```json
120//! {
121//!   "jsonrpc": "2.0",
122//!   "id": 1,
123//!   "method": "getAccountInfo",
124//!   "params": [
125//!     "7xB9i2AcjLNJ6M8iZ3LZJvLm7xpSmH7T5uZzR3DeVXWi",
126//!     {
127//!       "encoding": "base64"
128//!     }
129//!   ]
130//! }
131//! ```
132//!
133//! Responses include context information and follow the same format:
134//!
135//! ```json
136//! {
137//!   "jsonrpc": "2.0",
138//!   "id": 1,
139//!   "result": {
140//!     "context": {
141//!       "slot": 1234567
142//!     },
143//!     "value": {
144//!       "lamports": 1000000000,
145//!       "data": ["SGVsbG8gV29ybGQ=", "base64"],
146//!       "owner": "11111111111111111111111111111111",
147//!       "executable": false,
148//!       "rentEpoch": 200
149//!     }
150//!   }
151//! }
152//! ```
153
154pub mod constants;
155pub mod messages;
156pub mod parameters;
157pub mod requests;
158pub mod validation;
159
160#[cfg(test)]
161mod validation_test;
162
163#[cfg(test)]
164mod integration_test;
165
166// Re-export commonly used types for convenience
167pub use messages::{
168    get_block::{GetBlockRequest, GetBlockResponse},
169    get_connected_full_nodes::GetConnectedFullNodesResponse,
170    get_health::GetHealthResponse,
171    get_signature_statuses::GetSignatureStatusesRequest,
172    get_transaction_count::GetTransactionCountResponse,
173    get_validator_health::{GetValidatorHealthResponse, ValidatorHealthStatus},
174    get_workflow_lineage::{GetWorkflowLineageRequest, GetWorkflowLineageResponse},
175    request_airdrop::{RequestAirdropRequest, RequestAirdropResponse},
176    rpc_response_context::RpcResponseContext,
177};