pub mod address;
pub mod constant;
pub mod network_type;
pub mod rpc_client;
pub mod types;
use async_trait::async_trait;
use ckb_types::H256;
use serde::{Deserialize, Serialize};
use types::{HeaderViewWithExtension, IndexerTip, Order, Pagination, SearchKey, Tx};
use ckb_jsonrpc_types::{
BlockNumber, BlockView, CellInfo, HeaderView, JsonBytes, OutPoint, TransactionView, Uint32,
};
#[derive(Serialize, Deserialize)]
pub struct Submit {
pub header: HeaderView,
pub inputs: Vec<OutPoint>,
pub outputs: Vec<(OutPoint, CellInfo)>,
}
pub trait TipState {
fn load(&self) -> &IndexerTip;
fn update(&mut self, current: IndexerTip);
}
#[async_trait]
pub trait SubmitProcess {
fn is_closed(&self) -> bool;
async fn submit_cells(&mut self, cells: Vec<Submit>) -> bool;
async fn submit_headers(&mut self, headers: Vec<HeaderViewWithExtension>) -> bool;
}
#[async_trait]
pub trait Rpc {
async fn get_transactions(
&self,
search_key: SearchKey,
order: Order,
limit: Uint32,
after: Option<JsonBytes>,
) -> Result<Pagination<Tx>, std::io::Error>;
async fn get_transaction(&self, hash: &H256)
-> Result<Option<TransactionView>, std::io::Error>;
async fn get_header_by_number(&self, number: BlockNumber)
-> Result<HeaderView, std::io::Error>;
async fn get_indexer_tip(&self) -> Result<IndexerTip, std::io::Error>;
async fn get_block_by_number(&self, number: BlockNumber) -> Result<BlockView, std::io::Error>;
}
impl TipState for IndexerTip {
fn load(&self) -> &IndexerTip {
self
}
fn update(&mut self, current: IndexerTip) {
*self = current
}
}