Skip to main content

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//!     version: 0,
28//!     address: "7xB9i2AcjLNJ6M8iZ3LZJvLm7xpSmH7T5uZzR3DeVXWi".to_string(),
29//!     config: Some(GetAccountInfoConfig {
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 RLO in kelvins
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 kelvins
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//!
74//! ### Health & Status
75//! - `getHealth` - Node health check endpoint
76//! - `getValidatorHealth` - Validator-specific health check
77//! - `getConnectedFullNodes` - Get full nodes connected to validator
78//! - `getEpochInfo` - Get current epoch information
79//!
80//! ### Utility Operations
81//! - `requestAirdrop` - Request test tokens (devnet/testnet only)
82//! - `getMinimumBalanceForRentExemption` - Get minimum balance for rent exemption
83//! - `getFeeForMessage` - Calculate transaction fees
84//! - `isBlockhashValid` - Check if a blockhash is still valid
85//!
86//! ### Rialo-Specific Operations
87//! - `getWorkflowLineage` - Get workflow transaction lineage and relationships
88//! - `getTriggeredTransactions` - Get transactions triggered by events
89//! - `getSubscription` - Get subscription by subscriber and nonce
90//! - `getTransactionCount` - Get total transaction count
91//!
92//! ## Error Handling
93//!
94//! ```rust
95//! use rialo_api_types::validation::{ValidationError, ValidationResult};
96//! use rialo_api_types::messages::request_airdrop::RequestAirdropRequest;
97//!
98//! fn handle_validation_error(result: ValidationResult<RequestAirdropRequest>) {
99//!     match result {
100//!         Ok(data) => { /* Use validated data */ }
101//!         Err(ValidationError::InvalidPublicKey(msg)) => {
102//!             println!("Invalid public key: {}", msg);
103//!         }
104//!         Err(ValidationError::Multiple(msg)) => {
105//!             println!("Multiple validation errors: {}", msg);
106//!         }
107//!         Err(err) => {
108//!             println!("Validation failed: {}", err);
109//!         }
110//!     }
111//! }
112//! ```
113//!
114//! ## JSON-RPC 2.0 Format
115//!
116//! All requests follow the JSON-RPC 2.0 specification:
117//!
118//! ```json
119//! {
120//!   "jsonrpc": "2.0",
121//!   "id": 1,
122//!   "method": "getAccountInfo",
123//!   "params": [
124//!     "7xB9i2AcjLNJ6M8iZ3LZJvLm7xpSmH7T5uZzR3DeVXWi"
125//!   ]
126//! }
127//! ```
128//!
129//! Responses include context information and follow the same format:
130//!
131//! ```json
132//! {
133//!   "jsonrpc": "2.0",
134//!   "id": 1,
135//!   "result": {
136//!     "context": {
137//!       "slot": 1234567
138//!     },
139//!     "value": {
140//!       "kelvins": 1000000000,
141//!       "data": ["SGVsbG8gV29ybGQ=", "base64"],
142//!       "owner": "11111111111111111111111111111111",
143//!       "executable": false,
144//!       "rentEpoch": 200
145//!     }
146//!   }
147//! }
148//! ```
149
150pub mod constants;
151pub mod messages;
152pub mod parameters;
153pub mod requests;
154pub mod validation;
155
156#[cfg(test)]
157mod validation_test;
158
159#[cfg(test)]
160mod integration_test;
161
162// Re-export commonly used types for convenience
163pub use messages::{
164    get_block::{GetBlockRequest, GetBlockResponse},
165    get_connected_full_nodes::GetConnectedFullNodesResponse,
166    get_health::GetHealthResponse,
167    get_signature_statuses::GetSignatureStatusesRequest,
168    get_transaction_count::GetTransactionCountResponse,
169    get_validator_health::{GetValidatorHealthResponse, ValidatorHealthStatus},
170    get_workflow_lineage::{GetWorkflowLineageRequest, GetWorkflowLineageResponse},
171    request_airdrop::{RequestAirdropRequest, RequestAirdropResponse},
172    rpc_response_context::RpcResponseContext,
173};