Skip to content

Commit

Permalink
optimize address count. (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssuchichan authored Jun 26, 2024
1 parent 577efd9 commit 2426fe1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
14 changes: 13 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

## Chain
* [3.1 统计交易量](#3.1)

* [3.2 地址总量](#3.2)
## Asset
* [4.1 获取资产信息](#4.1)

Expand Down Expand Up @@ -415,6 +415,18 @@
}
```

<h3 id="3.2">3.2 地址总量</h3>

* `GET /api/chain/address/count`
* 无参数
* Request: `/api/chain/address/count`
* Response:
```json
{
"count": 125003
}
```

<h3 id="4.1">4.1 获取资产信息</h3>

* `GET /api/assets`
Expand Down
19 changes: 11 additions & 8 deletions explorer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ mod service;
use crate::service::api::Api;
use crate::service::v2::asset::get_assets;
use crate::service::v2::block::{
get_block_by_hash, get_block_by_num, get_blocks, get_full_block_by_hash,
get_full_block_by_height, get_simple_block_by_hash, get_simple_block_by_height,
get_block_by_hash, get_blocks, get_full_block_by_hash, get_full_block_by_height,
get_simple_block_by_hash, get_simple_block_by_height,
};
use crate::service::v2::claim::{get_claim_by_tx_hash, get_claims};
use crate::service::v2::delegation::{get_delegation_by_tx_hash, get_delegations};
Expand Down Expand Up @@ -56,20 +56,21 @@ async fn main() -> Result<()> {
.allow_headers(Any);
let addr = format!("{}:{}", config.server.addr, config.server.port);
let app = Router::new()
// chain
.route("/api/chain/address/count", get(get_address_count))
.route("/api/chain/statistics", get(get_statistics))
// block
.route("/api/block/hash/:hash", get(get_simple_block_by_hash))
.route("/api/block/full/hash/:hash", get(get_full_block_by_hash))
.route("/api/block/height/:num", get(get_simple_block_by_height))
.route("/api/block/full/height/:num", get(get_full_block_by_height))
.route("/api/address/count", get(get_address_count))
.route("/api/chain/statistics", get(get_statistics))
.route("/api/txs/distribute", get(get_tx_distribute))
.route("/api/chain/statistic", get(get_statistics))
.route("/api/number/block", get(get_block_by_num))
.route("/api/block", get(get_block_by_hash))
.route("/api/blocks", get(get_blocks))
// tx
.route("/api/tx", get(get_tx_by_hash))
.route("/api/txs", get(get_txs))
.route("/api/assets", get(get_assets))
.route("/api/txs/distribute", get(get_tx_distribute))
// staking
.route("/api/claim", get(get_claim_by_tx_hash))
.route("/api/claims", get(get_claims))
.route("/api/delegation", get(get_delegation_by_tx_hash))
Expand All @@ -80,6 +81,8 @@ async fn main() -> Result<()> {
.route("/api/n2es", get(get_n2e_txs))
.route("/api/e2n", get(get_e2n_by_tx_hash))
.route("/api/e2ns", get(get_e2n_txs))
// asset
.route("/api/assets", get(get_assets))
.layer(cors)
.with_state(app_state);
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
Expand Down
1 change: 1 addition & 0 deletions explorer/src/service/v2/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub struct GetBlockByHeightParams {
pub num: i64,
}

#[allow(dead_code)]
pub async fn get_block_by_num(
State(state): State<Arc<AppState>>,
Query(params): Query<GetBlockByHeightParams>,
Expand Down
4 changes: 2 additions & 2 deletions explorer/src/service/v2/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub struct AddressCountParams {
}
#[derive(Serialize, Deserialize)]
pub struct AddressCountResponse {
address_count: i64,
count: i64,
}

pub async fn get_address_count(
Expand Down Expand Up @@ -223,6 +223,6 @@ pub async fn get_address_count(
let evm_count: i64 = row_evm.try_get("count").map_err(internal_error)?;

Ok(Json(AddressCountResponse {
address_count: native_count + evm_count,
count: native_count + evm_count,
}))
}

0 comments on commit 2426fe1

Please sign in to comment.