Light Client
LightClient는 기본적인 체인 조회와 트랜잭션 전송만 필요한 경량 소비자를 위한 간소화된 API를 제공합니다.
설정
use savitri_sdk::LightClient;
let client = LightClient::new("http://localhost:8545")?;
API
// Connection check
let connected: bool = client.is_connected().await;
// Health
let health = client.health().await?;
println!("{} - {}", health.mode, health.status);
// Block height
let height: u64 = client.get_block_number().await?;
// Block by height
let block = client.get_block(42).await?;
// Account info
let account = client.get_account("address_hex").await?;
println!("Balance: {}, Nonce: {}", account.balance, account.nonce);
// Balance only
let balance: String = client.get_balance("address_hex").await?;
// Submit transaction
let result = client.send_raw_transaction("signed_tx_hex").await?;
println!("TX hash: {}", result.tx_hash);
// PoU status
let pou = client.pou_local().await?;
LightClient와 RpcClient 비교
| 기능 | LightClient | RpcClient |
|---|---|---|
| 상태/핑 | 예 | 예 |
| 블록 조회 | 높이 + 높이별 조회 | 모든 블록 메서드 |
| 계정 조회 | 잔액 + 계정 | 잔액, 논스, 토큰 |
| 트랜잭션 | raw 전송 | raw 전송 + 조회 + 영수증 |
| PoU | 로컬만 | 로컬, 피어, 그룹, masternode |
| 멤풀 | 아니요 | 크기, 상태, 대기 중 |
| 토큰 | 아니요 | 정보, 잔액, 전송 |
| 배치 요청 | 아니요 | 예 |
| raw JSON-RPC | 아니요 | 예 (call_raw) |
단순한 통합에는 LightClient를 사용하세요. 전체 API 표면이 필요할 때는 RpcClient를 직접 사용하세요. 고급 작업을 위해 client.rpc()를 통해 내부 RpcClient에 접근할 수 있습니다.