Skip to content

Commit

Permalink
modification for rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanYuan committed Dec 17, 2023
1 parent 3d68e50 commit 95fba3b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 38 deletions.
61 changes: 37 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions rpc/src/module/indexer_r.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::error::RPCError;
use ckb_indexer_r::IndexerRHandle;
use async_trait::async_trait;
use ckb_indexer_r::AsyncIndexerRHandle;
use ckb_jsonrpc_types::IndexerTip;
use jsonrpc_core::Result;
use jsonrpc_derive::rpc;
use jsonrpc_utils::rpc;

/// RPC Module Indexer.
#[rpc(server)]
#[rpc]
#[async_trait]
pub trait IndexerRRpc {
/// Returns the indexed tip
///
Expand Down Expand Up @@ -38,23 +40,26 @@ pub trait IndexerRRpc {
/// }
/// ```
#[rpc(name = "get_indexer_r_tip")]
fn get_indexer_r_tip(&self) -> Result<Option<IndexerTip>>;
async fn get_indexer_r_tip(&self) -> Result<Option<IndexerTip>>;
}

#[derive(Clone)]
pub(crate) struct IndexerRRpcImpl {
pub(crate) handle: IndexerRHandle,
pub(crate) handle: AsyncIndexerRHandle,
}

impl IndexerRRpcImpl {
pub fn new(handle: IndexerRHandle) -> Self {
pub fn new(handle: AsyncIndexerRHandle) -> Self {
IndexerRRpcImpl { handle }
}
}

#[async_trait]
impl IndexerRRpc for IndexerRRpcImpl {
fn get_indexer_r_tip(&self) -> Result<Option<IndexerTip>> {
async fn get_indexer_r_tip(&self) -> Result<Option<IndexerTip>> {
self.handle
.get_indexer_tip()
.query_indexer_tip()
.await
.map_err(|e| RPCError::custom(RPCError::Indexer, e))
}
}
13 changes: 7 additions & 6 deletions rpc/src/service_builder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#![allow(deprecated)]
use crate::module::{
add_alert_rpc_methods, add_chain_rpc_methods, add_debug_rpc_methods,
add_experiment_rpc_methods, add_indexer_rpc_methods, add_integration_test_rpc_methods,
add_miner_rpc_methods, add_net_rpc_methods, add_pool_rpc_methods, add_stats_rpc_methods,
add_subscription_rpc_methods, AlertRpcImpl, ChainRpcImpl, DebugRpcImpl, ExperimentRpcImpl,
IndexerRpcImpl, IntegrationTestRpcImpl, MinerRpcImpl, NetRpcImpl, PoolRpcImpl, StatsRpcImpl,
add_experiment_rpc_methods, add_indexer_r_rpc_methods, add_indexer_rpc_methods,
add_integration_test_rpc_methods, add_miner_rpc_methods, add_net_rpc_methods,
add_pool_rpc_methods, add_stats_rpc_methods, add_subscription_rpc_methods, AlertRpcImpl,
ChainRpcImpl, DebugRpcImpl, ExperimentRpcImpl, IndexerRRpcImpl, IndexerRpcImpl,
IntegrationTestRpcImpl, MinerRpcImpl, NetRpcImpl, PoolRpcImpl, StatsRpcImpl,
SubscriptionRpcImpl,
};
use crate::{IoHandler, RPCError};
Expand Down Expand Up @@ -210,7 +211,7 @@ impl<'a> ServiceBuilder<'a> {
pool_service.index_tx_pool(shared.notify_controller().clone());
}
}
set_rpc_module_methods!(
self = set_rpc_module_methods!(
self,
"Indexer",
indexer_enable,
Expand All @@ -225,7 +226,7 @@ impl<'a> ServiceBuilder<'a> {
indexer_config,
shared.async_handle().clone(),
);
let indexer_r_handle = indexer_r.handle();
let indexer_r_handle = indexer_r.async_handle();
let indexer_r_methods = IndexerRRpcImpl::new(indexer_r_handle);
if self.config.indexer_r_enable() {
indexer_r.spawn_poll(shared.notify_controller().clone());
Expand Down
1 change: 1 addition & 0 deletions util/indexer-r/src/indexer_handle/async_indexer_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use sqlx::{any::AnyRow, Row};
use std::sync::{Arc, RwLock};

/// Async handle to the indexer-r.
#[derive(Clone)]
pub struct AsyncIndexerRHandle {
store: SQLXPool,
_pool: Option<Arc<RwLock<Pool>>>,
Expand Down
1 change: 1 addition & 0 deletions util/indexer-r/src/indexer_handle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::sync::{Arc, RwLock};
///
/// The handle is internally reference-counted and can be freely cloned.
/// A handle can be obtained using the IndexerRService::handle method.
#[derive(Clone)]
pub struct IndexerRHandle {
async_handle: AsyncIndexerRHandle,
async_runtime: Handle,
Expand Down

0 comments on commit 95fba3b

Please sign in to comment.