Fix all Rust clippy warnings that were causing CI failures when built with RUSTFLAGS=-Dwarnings. Changes include: - Replace derivable_impls with derive macros for BlockBody, Network, etc. - Use div_ceil() instead of manual implementation - Fix should_implement_trait by renaming from_str to parse - Add type aliases for type_complexity warnings - Use or_default(), is_some_and(), is_multiple_of() where appropriate - Remove needless borrows and redundant closures - Fix manual_strip with strip_prefix() - Add allow attributes for intentional patterns (too_many_arguments, needless_range_loop in cryptographic code, assertions_on_constants) - Remove unused imports, mut bindings, and dead code in tests
90 lines
4.1 KiB
Rust
90 lines
4.1 KiB
Rust
//! JSON-RPC API for Synor blockchain node.
|
|
//!
|
|
//! Provides HTTP and WebSocket endpoints for:
|
|
//! - Block and transaction queries
|
|
//! - UTXO management
|
|
//! - Mining operations
|
|
//! - Network information
|
|
//! - Smart contract interaction
|
|
//!
|
|
//! # Architecture
|
|
//!
|
|
//! ```text
|
|
//! ┌─────────────────────────────────────────────────────────────────┐
|
|
//! │ RPC SERVER │
|
|
//! ├─────────────────────────────────────────────────────────────────┤
|
|
//! │ │
|
|
//! │ ┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐ │
|
|
//! │ │ HTTP │ │ WebSocket │ │ Methods │ │
|
|
//! │ │ Server │ │ Server │ │ (JSON-RPC 2.0) │ │
|
|
//! │ └──────┬───────┘ └──────┬───────┘ └──────────┬───────────┘ │
|
|
//! │ │ │ │ │
|
|
//! │ └─────────────────┼──────────────────────┘ │
|
|
//! │ │ │
|
|
//! │ ┌────────────────────────▼─────────────────────────────────┐ │
|
|
//! │ │ API Handlers │ │
|
|
//! │ ├───────────┬───────────┬───────────┬───────────┬──────────┤ │
|
|
//! │ │ Blocks │ Txns │ Mining │ Network │ Contracts│ │
|
|
//! │ └───────────┴───────────┴───────────┴───────────┴──────────┘ │
|
|
//! │ │
|
|
//! └─────────────────────────────────────────────────────────────────┘
|
|
//! ```
|
|
|
|
#![allow(dead_code)]
|
|
|
|
pub mod api;
|
|
pub mod pool;
|
|
pub mod server;
|
|
pub mod types;
|
|
|
|
pub use api::{
|
|
BlockApiServer, ContractApiServer, MiningApiServer, NetworkApiServer, SubscriptionApiServer,
|
|
TransactionApiServer, UtxoApiServer,
|
|
};
|
|
pub use pool::{
|
|
global_pool, init_global_pool, ConnectionPool, ConnectionPoolExt, PoolConfig, PoolError,
|
|
PoolStats, PoolStatsSnapshot, PooledHttpClient, PooledHttpClientGuard, PooledWsClient,
|
|
PooledWsClientGuard,
|
|
};
|
|
pub use server::{RpcConfig, RpcServer};
|
|
pub use types::*;
|
|
|
|
/// Default RPC port.
|
|
pub const DEFAULT_RPC_PORT: u16 = 16110;
|
|
|
|
/// Default WebSocket port.
|
|
pub const DEFAULT_WS_PORT: u16 = 16111;
|
|
|
|
/// Maximum batch request size.
|
|
pub const MAX_BATCH_SIZE: usize = 100;
|
|
|
|
/// Maximum response size (10 MB).
|
|
pub const MAX_RESPONSE_SIZE: usize = 10 * 1024 * 1024;
|
|
|
|
/// RPC method namespaces.
|
|
pub mod namespaces {
|
|
/// Block-related methods.
|
|
pub const BLOCK: &str = "synor";
|
|
/// Transaction methods.
|
|
pub const TX: &str = "synor";
|
|
/// UTXO methods.
|
|
pub const UTXO: &str = "synor";
|
|
/// Mining methods.
|
|
pub const MINING: &str = "synor";
|
|
/// Network methods.
|
|
pub const NET: &str = "net";
|
|
/// Contract methods.
|
|
pub const CONTRACT: &str = "contract";
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
#[allow(clippy::assertions_on_constants)]
|
|
fn test_constants() {
|
|
assert!(DEFAULT_RPC_PORT > 0);
|
|
assert!(MAX_BATCH_SIZE > 0);
|
|
}
|
|
}
|