Skip to content

Commit

Permalink
optimize: query tx by time. (#269)
Browse files Browse the repository at this point in the history
* optimize: query tx by time.
  • Loading branch information
s1q1ch4n authored Jun 27, 2024
1 parent 7f8a7a1 commit 667a60a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 9 additions & 7 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@

<h3 id="1.2">1.2 获取交易列表</h3>

| 参数 | 类型 | 必传 | 说明 |
|-----------|--------|----|------------|
| from | string | N | 发送者 |
| to | string | N | 接收者 |
| ty | number | N | 类型 |
| page | number | N | 页码,缺省值为1 |
| page_size | number | N | 页大小,缺省值为10 |
| 参数 | 类型 | 必传 | 说明 |
|------------|--------|----|------------|
| from | string | N | 发送者 |
| to | string | N | 接收者 |
| ty | number | N | 类型 |
| start_time | number | N | 开始时间戳 |
| end_time | number | N | 结束时间戳 |
| page | number | N | 页码,缺省值为1 |
| page_size | number | N | 页大小,缺省值为10 |

* Request: `/api/txs?page=2&page_size=2`
* Response:
Expand Down
8 changes: 8 additions & 0 deletions explorer/src/service/v2/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct GetTxsParams {
pub from: Option<String>,
pub to: Option<String>,
pub ty: Option<i32>,
pub start_time: Option<i64>,
pub end_time: Option<i64>,
pub page: Option<i32>,
pub page_size: Option<i32>,
}
Expand All @@ -40,6 +42,12 @@ pub async fn get_txs(
if let Some(ty) = params.ty {
query_params.push(format!("ty={} ", ty));
}
if let Some(start_time) = params.start_time {
query_params.push(format!("timestamp>={} ", start_time));
}
if let Some(end_time) = params.end_time {
query_params.push(format!("timestamp<={} ", end_time));
}
if !query_params.is_empty() {
sql_query = sql_query
.add("WHERE ")
Expand Down

0 comments on commit 667a60a

Please sign in to comment.