Add endpoint for fetching address-specific pow puzzle
This commit is contained in:
parent
67962a5d12
commit
1d8aa52902
@ -11,6 +11,7 @@ use neptune_explorer::model::app_state::AppState;
|
||||
use neptune_explorer::neptune_rpc;
|
||||
use neptune_explorer::rpc::block_digest::block_digest;
|
||||
use neptune_explorer::rpc::block_info::block_info;
|
||||
use neptune_explorer::rpc::pow_puzzle::pow_puzzle;
|
||||
use neptune_explorer::rpc::utxo_digest::utxo_digest;
|
||||
use tower_http::services::ServeDir;
|
||||
use tracing::info;
|
||||
@ -53,6 +54,7 @@ pub fn setup_routes(app_state: AppState) -> Router {
|
||||
.route("/rpc/block_info/*selector", get(block_info))
|
||||
.route("/rpc/block_digest/*selector", get(block_digest))
|
||||
.route("/rpc/utxo_digest/:index", get(utxo_digest))
|
||||
.route("/rpc/pow_puzzle/*address", get(pow_puzzle))
|
||||
// -- Dynamic HTML pages --
|
||||
.route("/", get(root))
|
||||
.route("/block/*selector", get(block_page))
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
pub mod block_digest;
|
||||
pub mod block_info;
|
||||
pub mod pow_puzzle;
|
||||
pub mod utxo_digest;
|
||||
|
||||
36
src/rpc/pow_puzzle.rs
Normal file
36
src/rpc/pow_puzzle.rs
Normal file
@ -0,0 +1,36 @@
|
||||
use axum::extract::Path;
|
||||
use axum::extract::State;
|
||||
use axum::response::IntoResponse;
|
||||
use axum::response::Json;
|
||||
use neptune_cash::models::state::wallet::address::generation_address::GenerationReceivingAddress;
|
||||
use neptune_cash::rpc_server::error::RpcError;
|
||||
use neptune_cash::rpc_server::ProofOfWorkPuzzle;
|
||||
use std::sync::Arc;
|
||||
use tarpc::context;
|
||||
|
||||
use crate::http_util::not_found_err;
|
||||
use crate::http_util::rpc_err;
|
||||
use crate::http_util::rpc_method_err;
|
||||
use crate::model::app_state::AppState;
|
||||
|
||||
#[axum::debug_handler]
|
||||
pub async fn pow_puzzle(
|
||||
Path(address): Path<String>,
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> Result<Json<ProofOfWorkPuzzle>, impl IntoResponse> {
|
||||
let s = state.load();
|
||||
let Ok(receiving_address) = GenerationReceivingAddress::from_bech32m(&address, s.network)
|
||||
else {
|
||||
return Err(rpc_method_err(RpcError::Failed(address)));
|
||||
};
|
||||
match s
|
||||
.rpc_client
|
||||
.pow_puzzle_external_key(context::current(), s.token(), receiving_address.into())
|
||||
.await
|
||||
.map_err(rpc_err)?
|
||||
.map_err(rpc_method_err)?
|
||||
{
|
||||
Some(pow_puzzle) => Ok(Json(pow_puzzle)),
|
||||
None => Err(not_found_err()),
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user