Changeset View
Changeset View
Standalone View
Standalone View
chronik/chronik-http/src/server.rs
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | pub async fn serve(self) -> Result<()> { | ||||
result?; | result?; | ||||
Ok(()) | Ok(()) | ||||
} | } | ||||
fn make_router(indexer: ChronikIndexerRef) -> Router { | fn make_router(indexer: ChronikIndexerRef) -> Router { | ||||
Router::new() | Router::new() | ||||
.route("/blockchain-info", routing::get(handle_blockchain_info)) | .route("/blockchain-info", routing::get(handle_blockchain_info)) | ||||
.route("/block/:hash_or_height", routing::get(handle_block)) | .route("/block/:hash_or_height", routing::get(handle_block)) | ||||
.route("/block-txs/:hash_or_height", routing::get(handle_block_txs)) | |||||
.route("/blocks/:start/:end", routing::get(handle_block_range)) | .route("/blocks/:start/:end", routing::get(handle_block_range)) | ||||
.route("/tx/:txid", routing::get(handle_tx)) | .route("/tx/:txid", routing::get(handle_tx)) | ||||
.route("/raw-tx/:txid", routing::get(handle_raw_tx)) | .route("/raw-tx/:txid", routing::get(handle_raw_tx)) | ||||
.route( | .route( | ||||
"/script/:type/:payload/confirmed-txs", | "/script/:type/:payload/confirmed-txs", | ||||
routing::get(handle_script_confirmed_txs), | routing::get(handle_script_confirmed_txs), | ||||
) | ) | ||||
.route( | .route( | ||||
Show All 35 Lines | async fn handle_block( | ||||
Path(hash_or_height): Path<String>, | Path(hash_or_height): Path<String>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
) -> Result<Protobuf<proto::Block>, ReportError> { | ) -> Result<Protobuf<proto::Block>, ReportError> { | ||||
let indexer = indexer.read().await; | let indexer = indexer.read().await; | ||||
let blocks = indexer.blocks(); | let blocks = indexer.blocks(); | ||||
Ok(Protobuf(blocks.by_hash_or_height(hash_or_height)?)) | Ok(Protobuf(blocks.by_hash_or_height(hash_or_height)?)) | ||||
} | } | ||||
async fn handle_block_txs( | |||||
Path(hash_or_height): Path<String>, | |||||
Query(query_params): Query<HashMap<String, String>>, | |||||
Extension(indexer): Extension<ChronikIndexerRef>, | |||||
) -> Result<Protobuf<proto::TxHistoryPage>, ReportError> { | |||||
let indexer = indexer.read().await; | |||||
Ok(Protobuf( | |||||
handlers::handle_block_txs(hash_or_height, &query_params, &indexer) | |||||
.await?, | |||||
)) | |||||
} | |||||
async fn handle_tx( | async fn handle_tx( | ||||
Path(txid): Path<String>, | Path(txid): Path<String>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
) -> Result<Protobuf<proto::Tx>, ReportError> { | ) -> Result<Protobuf<proto::Tx>, ReportError> { | ||||
let indexer = indexer.read().await; | let indexer = indexer.read().await; | ||||
let txid = txid.parse::<TxId>().wrap_err(NotTxId(txid))?; | let txid = txid.parse::<TxId>().wrap_err(NotTxId(txid))?; | ||||
Ok(Protobuf(indexer.txs().tx_by_id(txid)?)) | Ok(Protobuf(indexer.txs().tx_by_id(txid)?)) | ||||
} | } | ||||
▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines |