Changeset View
Changeset View
Standalone View
Standalone View
chronik/chronik-http/src/server.rs
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | impl ChronikServer { | ||||
} | } | ||||
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("/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( | .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( | ||||
"/script/:type/:payload/history", | "/script/:type/:payload/history", | ||||
routing::get(handle_script_history), | routing::get(handle_script_history), | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | 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)?)) | ||||
} | } | ||||
async fn handle_raw_tx( | |||||
Path(txid): Path<String>, | |||||
Extension(indexer): Extension<ChronikIndexerRef>, | |||||
) -> Result<Protobuf<proto::RawTx>, ReportError> { | |||||
let indexer = indexer.read().await; | |||||
let txid = txid.parse::<TxId>().wrap_err(NotTxId(txid))?; | |||||
Ok(Protobuf(indexer.txs().raw_tx_by_id(&txid)?)) | |||||
} | |||||
async fn handle_script_confirmed_txs( | async fn handle_script_confirmed_txs( | ||||
Path((script_type, payload)): Path<(String, String)>, | Path((script_type, payload)): Path<(String, String)>, | ||||
Query(query_params): Query<HashMap<String, String>>, | Query(query_params): Query<HashMap<String, String>>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
) -> Result<Protobuf<proto::TxHistoryPage>, ReportError> { | ) -> Result<Protobuf<proto::TxHistoryPage>, ReportError> { | ||||
let indexer = indexer.read().await; | let indexer = indexer.read().await; | ||||
Ok(Protobuf( | Ok(Protobuf( | ||||
handlers::handle_script_confirmed_txs( | handlers::handle_script_confirmed_txs( | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |