Changeset View
Changeset View
Standalone View
Standalone View
chronik/chronik-http/src/server.rs
Show First 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | ) -> Router { | ||||
.layer(Extension(node)) | .layer(Extension(node)) | ||||
.layer(Extension(pause_notify)) | .layer(Extension(pause_notify)) | ||||
.layer(Extension(settings)) | .layer(Extension(settings)) | ||||
} | } | ||||
} | } | ||||
async fn handle_blockchain_info( | async fn handle_blockchain_info( | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> Result<Protobuf<proto::BlockchainInfo>, ReportError> { | ) -> Result<Protobuf<proto::BlockchainInfo>, ReportError> { | ||||
let indexer = indexer.read().await; | let indexer = indexer.read().await; | ||||
let blocks = indexer.blocks(); | let blocks = indexer.blocks(&node); | ||||
Ok(Protobuf(blocks.blockchain_info()?)) | Ok(Protobuf(blocks.blockchain_info()?)) | ||||
} | } | ||||
async fn handle_chronik_info( | async fn handle_chronik_info( | ||||
) -> Result<Protobuf<proto::ChronikInfo>, ReportError> { | ) -> Result<Protobuf<proto::ChronikInfo>, ReportError> { | ||||
let this_chronik_version: String = env!("CARGO_PKG_VERSION").to_string(); | let this_chronik_version: String = env!("CARGO_PKG_VERSION").to_string(); | ||||
let chronik_info = proto::ChronikInfo { | let chronik_info = proto::ChronikInfo { | ||||
version: this_chronik_version, | version: this_chronik_version, | ||||
}; | }; | ||||
Ok(Protobuf(chronik_info)) | Ok(Protobuf(chronik_info)) | ||||
} | } | ||||
async fn handle_block_range( | async fn handle_block_range( | ||||
Path((start_height, end_height)): Path<(i32, i32)>, | Path((start_height, end_height)): Path<(i32, i32)>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> Result<Protobuf<proto::Blocks>, ReportError> { | ) -> Result<Protobuf<proto::Blocks>, ReportError> { | ||||
let indexer = indexer.read().await; | let indexer = indexer.read().await; | ||||
let blocks = indexer.blocks(); | let blocks = indexer.blocks(&node); | ||||
Ok(Protobuf(blocks.by_range(start_height, end_height)?)) | Ok(Protobuf(blocks.by_range(start_height, end_height)?)) | ||||
} | } | ||||
async fn handle_block( | async fn handle_block( | ||||
Path(hash_or_height): Path<String>, | Path(hash_or_height): Path<String>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> 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(&node); | ||||
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( | async fn handle_block_txs( | ||||
Path(hash_or_height): Path<String>, | Path(hash_or_height): Path<String>, | ||||
Query(query_params): Query<HashMap<String, String>>, | Query(query_params): Query<HashMap<String, String>>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> 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_block_txs(hash_or_height, &query_params, &indexer) | handlers::handle_block_txs( | ||||
hash_or_height, | |||||
&query_params, | |||||
&indexer, | |||||
&node, | |||||
) | |||||
.await?, | .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>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> 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(&node).tx_by_id(txid)?)) | ||||
} | } | ||||
async fn handle_token_info( | async fn handle_token_info( | ||||
Path(txid): Path<String>, | Path(txid): Path<String>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> Result<Protobuf<proto::TokenInfo>, ReportError> { | ) -> Result<Protobuf<proto::TokenInfo>, 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().token_info(&txid)?)) | Ok(Protobuf(indexer.txs(&node).token_info(&txid)?)) | ||||
} | } | ||||
async fn handle_broadcast_tx( | async fn handle_broadcast_tx( | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | Extension(node): Extension<NodeRef>, | ||||
Protobuf(request): Protobuf<proto::BroadcastTxRequest>, | Protobuf(request): Protobuf<proto::BroadcastTxRequest>, | ||||
) -> Result<Protobuf<proto::BroadcastTxResponse>, ReportError> { | ) -> Result<Protobuf<proto::BroadcastTxResponse>, ReportError> { | ||||
let indexer = indexer.read().await; | let indexer = indexer.read().await; | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | Ok(Protobuf( | ||||
.broadcast(node.as_ref()) | .broadcast(node.as_ref()) | ||||
.validate_tx(raw_tx.raw_tx)?, | .validate_tx(raw_tx.raw_tx)?, | ||||
)) | )) | ||||
} | } | ||||
async fn handle_raw_tx( | async fn handle_raw_tx( | ||||
Path(txid): Path<String>, | Path(txid): Path<String>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> Result<Protobuf<proto::RawTx>, ReportError> { | ) -> Result<Protobuf<proto::RawTx>, 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().raw_tx_by_id(&txid)?)) | Ok(Protobuf(indexer.txs(&node).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>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> 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( | ||||
&script_type, | &script_type, | ||||
&payload, | &payload, | ||||
&query_params, | &query_params, | ||||
&indexer, | &indexer, | ||||
&node, | |||||
) | ) | ||||
.await?, | .await?, | ||||
)) | )) | ||||
} | } | ||||
async fn handle_script_history( | async fn handle_script_history( | ||||
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>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> 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_history( | handlers::handle_script_history( | ||||
&script_type, | &script_type, | ||||
&payload, | &payload, | ||||
&query_params, | &query_params, | ||||
&indexer, | &indexer, | ||||
&node, | |||||
) | ) | ||||
.await?, | .await?, | ||||
)) | )) | ||||
} | } | ||||
async fn handle_script_unconfirmed_txs( | async fn handle_script_unconfirmed_txs( | ||||
Path((script_type, payload)): Path<(String, String)>, | Path((script_type, payload)): Path<(String, String)>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> 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_unconfirmed_txs( | handlers::handle_script_unconfirmed_txs( | ||||
&script_type, | &script_type, | ||||
&payload, | &payload, | ||||
&indexer, | &indexer, | ||||
&node, | |||||
) | ) | ||||
.await?, | .await?, | ||||
)) | )) | ||||
} | } | ||||
async fn handle_script_utxos( | async fn handle_script_utxos( | ||||
Path((script_type, payload)): Path<(String, String)>, | Path((script_type, payload)): Path<(String, String)>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
) -> Result<Protobuf<proto::ScriptUtxos>, ReportError> { | ) -> Result<Protobuf<proto::ScriptUtxos>, ReportError> { | ||||
let indexer = indexer.read().await; | let indexer = indexer.read().await; | ||||
Ok(Protobuf( | Ok(Protobuf( | ||||
handlers::handle_script_utxos(&script_type, &payload, &indexer).await?, | handlers::handle_script_utxos(&script_type, &payload, &indexer).await?, | ||||
)) | )) | ||||
} | } | ||||
async fn handle_token_id_confirmed_txs( | async fn handle_token_id_confirmed_txs( | ||||
Path(token_id_hex): Path<String>, | Path(token_id_hex): Path<String>, | ||||
Query(query_params): Query<HashMap<String, String>>, | Query(query_params): Query<HashMap<String, String>>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> 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_token_id_confirmed_txs( | handlers::handle_token_id_confirmed_txs( | ||||
&token_id_hex, | &token_id_hex, | ||||
&query_params, | &query_params, | ||||
&indexer, | &indexer, | ||||
&node, | |||||
) | ) | ||||
.await?, | .await?, | ||||
)) | )) | ||||
} | } | ||||
async fn handle_token_id_history( | async fn handle_token_id_history( | ||||
Path(token_id_hex): Path<String>, | Path(token_id_hex): Path<String>, | ||||
Query(query_params): Query<HashMap<String, String>>, | Query(query_params): Query<HashMap<String, String>>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> 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_token_id_history( | handlers::handle_token_id_history( | ||||
&token_id_hex, | &token_id_hex, | ||||
&query_params, | &query_params, | ||||
&indexer, | &indexer, | ||||
&node, | |||||
) | ) | ||||
.await?, | .await?, | ||||
)) | )) | ||||
} | } | ||||
async fn handle_token_id_unconfirmed_txs( | async fn handle_token_id_unconfirmed_txs( | ||||
Path(token_id_hex): Path<String>, | Path(token_id_hex): Path<String>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
Extension(node): Extension<NodeRef>, | |||||
) -> 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_token_id_unconfirmed_txs(&token_id_hex, &indexer) | handlers::handle_token_id_unconfirmed_txs( | ||||
&token_id_hex, | |||||
&indexer, | |||||
&node, | |||||
) | |||||
.await?, | .await?, | ||||
)) | )) | ||||
} | } | ||||
async fn handle_token_id_utxos( | async fn handle_token_id_utxos( | ||||
Path(token_id_hex): Path<String>, | Path(token_id_hex): Path<String>, | ||||
Extension(indexer): Extension<ChronikIndexerRef>, | Extension(indexer): Extension<ChronikIndexerRef>, | ||||
) -> Result<Protobuf<proto::Utxos>, ReportError> { | ) -> Result<Protobuf<proto::Utxos>, ReportError> { | ||||
let indexer = indexer.read().await; | let indexer = indexer.read().await; | ||||
Show All 34 Lines |