feat(rpc): add nu_listValidators endpoint
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ec8af8d1c7
commit
ca388b4bc2
2 changed files with 16 additions and 0 deletions
|
|
@ -7,6 +7,11 @@ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.9.0] — 2026-04-24
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `nu_listValidators` RPC handler — tüm validatörleri döner; `params[0] = true` ile yalnızca aktifler filtrelenir
|
||||||
|
|
||||||
## [0.8.0] — 2026-04-24
|
## [0.8.0] — 2026-04-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ pub async fn dispatch(req: JsonRpcRequest, state: &AppState) -> JsonRpcResponse
|
||||||
"nu_sendRawTx" => handle_send_raw_tx(&req, state).await,
|
"nu_sendRawTx" => handle_send_raw_tx(&req, state).await,
|
||||||
"nu_getBlock" => handle_get_block(&req, state).await,
|
"nu_getBlock" => handle_get_block(&req, state).await,
|
||||||
"nu_getValidator" => handle_get_validator(&req, state).await,
|
"nu_getValidator" => handle_get_validator(&req, state).await,
|
||||||
|
"nu_listValidators" => handle_list_validators(&req, state).await,
|
||||||
"nu_getTx" => not_implemented(&req, "nu_getTx"),
|
"nu_getTx" => not_implemented(&req, "nu_getTx"),
|
||||||
"nu_getStory" => not_implemented(&req, "nu_getStory"),
|
"nu_getStory" => not_implemented(&req, "nu_getStory"),
|
||||||
"nu_getNode" => not_implemented(&req, "nu_getNode"),
|
"nu_getNode" => not_implemented(&req, "nu_getNode"),
|
||||||
|
|
@ -126,6 +127,16 @@ async fn handle_get_validator(req: &JsonRpcRequest, state: &AppState) -> JsonRpc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn handle_list_validators(req: &JsonRpcRequest, state: &AppState) -> JsonRpcResponse {
|
||||||
|
let only_active = req.params.get(0).and_then(|v| v.as_bool()).unwrap_or(false);
|
||||||
|
let db = state.db.lock().await;
|
||||||
|
let mut validators: Vec<ValidatorState> = db.scan_prefix("validator:");
|
||||||
|
if only_active {
|
||||||
|
validators.retain(|v| v.is_active);
|
||||||
|
}
|
||||||
|
JsonRpcResponse::ok(req.id.clone(), serde_json::to_value(validators).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
fn not_implemented(req: &JsonRpcRequest, method: &str) -> JsonRpcResponse {
|
fn not_implemented(req: &JsonRpcRequest, method: &str) -> JsonRpcResponse {
|
||||||
JsonRpcResponse::err(req.id.clone(), -32000, format!("{method} not implemented yet"))
|
JsonRpcResponse::err(req.id.clone(), -32000, format!("{method} not implemented yet"))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue