Skip to content

Commit

Permalink
opt: add tx hash in response. (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
blowcowbeer authored Jul 2, 2024
1 parent 62c8fc0 commit 669cfd4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 8 additions & 4 deletions indexer/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ pub async fn get_delegator_delegate_records(
(
format!("SELECT count(block_num) FROM evm_delegations WHERE delegator='{}'", delegator)
,
format!("SELECT block_id,validator,delegator,tm,amount FROM evm_delegations WHERE delegator='{}' ORDER BY tm DESC LIMIT {} OFFSET {}", delegator, page_size, (page-1)*page_size)
format!("SELECT tx_id,block_id,validator,delegator,tm,amount FROM evm_delegations WHERE delegator='{}' ORDER BY tm DESC LIMIT {} OFFSET {}", delegator, page_size, (page-1)*page_size)
)
} else {
(
"SELECT count(block_num) FROM evm_delegations".to_string()
,
format!("SELECT block_id,validator,delegator,tm,amount FROM evm_delegations ORDER BY tm DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size))
format!("SELECT tx_id,block_id,validator,delegator,tm,amount FROM evm_delegations ORDER BY tm DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size))
};

let row = sqlx::query(&sql_total).fetch_one(&mut *pool).await?;
Expand All @@ -43,13 +43,15 @@ pub async fn get_delegator_delegate_records(
let mut delegates: Vec<DelegateResponse> = vec![];
let rows = sqlx::query(&sql_query).fetch_all(&mut *pool).await?;
for r in rows {
let tx_hash: String = r.try_get("tx_id")?;
let block_hash: String = r.try_get("block_id")?;
let validator: String = r.try_get("validator")?;
let delegator: String = r.try_get("delegator")?;
let amount: BigDecimal = r.try_get("amount")?;
let tm: NaiveDateTime = r.try_get("tm")?;

delegates.push(DelegateResponse {
tx_hash,
block_hash,
validator,
delegator,
Expand Down Expand Up @@ -85,13 +87,13 @@ pub async fn get_validator_delegate_records(
(
format!("SELECT count(block_num) FROM evm_delegations WHERE validator='{}'", validator)
,
format!("SELECT block_id,validator,delegator,tm,amount FROM evm_delegations WHERE validator='{}' ORDER BY tm DESC LIMIT {} OFFSET {}", validator, page_size, (page-1)*page_size)
format!("SELECT tx_id,block_id,validator,delegator,tm,amount FROM evm_delegations WHERE validator='{}' ORDER BY tm DESC LIMIT {} OFFSET {}", validator, page_size, (page-1)*page_size)
)
} else {
(
"SELECT count(block_num) FROM evm_delegations".to_string()
,
format!("SELECT block_id,validator,delegator,tm,amount FROM evm_delegations ORDER BY tm DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size))
format!("SELECT tx_id,block_id,validator,delegator,tm,amount FROM evm_delegations ORDER BY tm DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size))
};

let row = sqlx::query(&sql_total).fetch_one(&mut *pool).await?;
Expand All @@ -100,13 +102,15 @@ pub async fn get_validator_delegate_records(
let mut delegates: Vec<DelegateResponse> = vec![];
let rows = sqlx::query(&sql_query).fetch_all(&mut *pool).await?;
for r in rows {
let tx_hash: String = r.try_get("tx_id")?;
let block_hash: String = r.try_get("block_id")?;
let validator: String = r.try_get("validator")?;
let delegator: String = r.try_get("delegator")?;
let amount: BigDecimal = r.try_get("amount")?;
let tm: NaiveDateTime = r.try_get("tm")?;

delegates.push(DelegateResponse {
tx_hash,
block_hash,
validator,
delegator,
Expand Down
2 changes: 2 additions & 0 deletions indexer/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub struct StakeResponse {

#[derive(Serialize, Deserialize)]
pub struct DelegateResponse {
pub tx_hash: String,
pub block_hash: String,
pub validator: String,
pub delegator: String,
Expand All @@ -121,6 +122,7 @@ pub struct DelegateResponse {

#[derive(Serialize, Deserialize)]
pub struct UndelegateResponse {
pub tx_hash: String,
pub block_hash: String,
pub validator: String,
pub delegator: String,
Expand Down
12 changes: 8 additions & 4 deletions indexer/src/undelegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ pub async fn get_delegator_undelegate_records(
(
format!("SELECT count(block_num) FROM evm_undelegations WHERE delegator='{}'", delegator)
,
format!("SELECT block_id,validator,delegator,tm,amount FROM evm_undelegations WHERE delegator='{}' ORDER BY tm DESC LIMIT {} OFFSET {}", delegator, page_size, (page-1)*page_size)
format!("SELECT tx_id,block_id,validator,delegator,tm,amount FROM evm_undelegations WHERE delegator='{}' ORDER BY tm DESC LIMIT {} OFFSET {}", delegator, page_size, (page-1)*page_size)
)
} else {
(
"SELECT count(block_num) FROM evm_undelegations".to_string()
,
format!("SELECT block_id,validator,delegator,tm,amount FROM evm_undelegations ORDER BY tm DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size))
format!("SELECT tx_id,block_id,validator,delegator,tm,amount FROM evm_undelegations ORDER BY tm DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size))
};

let row = sqlx::query(&sql_total).fetch_one(&mut *pool).await?;
Expand All @@ -43,13 +43,15 @@ pub async fn get_delegator_undelegate_records(
let mut delegates: Vec<UndelegateResponse> = vec![];
let rows = sqlx::query(&sql_query).fetch_all(&mut *pool).await?;
for r in rows {
let tx_hash: String = r.try_get("tx_id")?;
let block_hash: String = r.try_get("block_id")?;
let validator: String = r.try_get("validator")?;
let delegator: String = r.try_get("delegator")?;
let amount: BigDecimal = r.try_get("amount")?;
let tm: NaiveDateTime = r.try_get("tm")?;

delegates.push(UndelegateResponse {
tx_hash,
block_hash,
validator,
delegator,
Expand Down Expand Up @@ -85,13 +87,13 @@ pub async fn get_validator_undelegate_records(
(
format!("SELECT count(block_num) FROM evm_undelegations WHERE validator='{}'", validator)
,
format!("SELECT block_id,validator,delegator,tm,amount FROM evm_undelegations WHERE validator='{}' ORDER BY tm DESC LIMIT {} OFFSET {}", validator, page_size, (page-1)*page_size)
format!("SELECT tx_id,block_id,validator,delegator,tm,amount FROM evm_undelegations WHERE validator='{}' ORDER BY tm DESC LIMIT {} OFFSET {}", validator, page_size, (page-1)*page_size)
)
} else {
(
"SELECT count(block_num) FROM evm_undelegations".to_string()
,
format!("SELECT block_id,validator,delegator,tm,amount FROM evm_undelegations ORDER BY tm DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size))
format!("SELECT tx_id,block_id,validator,delegator,tm,amount FROM evm_undelegations ORDER BY tm DESC LIMIT {} OFFSET {}", page_size, (page-1)*page_size))
};

let row = sqlx::query(&sql_total).fetch_one(&mut *pool).await?;
Expand All @@ -100,13 +102,15 @@ pub async fn get_validator_undelegate_records(
let mut delegates: Vec<UndelegateResponse> = vec![];
let rows = sqlx::query(&sql_query).fetch_all(&mut *pool).await?;
for r in rows {
let tx_hash: String = r.try_get("tx_id")?;
let block_hash: String = r.try_get("block_id")?;
let validator: String = r.try_get("validator")?;
let delegator: String = r.try_get("delegator")?;
let amount: BigDecimal = r.try_get("amount")?;
let tm: NaiveDateTime = r.try_get("tm")?;

delegates.push(UndelegateResponse {
tx_hash,
block_hash,
validator,
delegator,
Expand Down

0 comments on commit 669cfd4

Please sign in to comment.