Skip to content

Commit

Permalink
Merge pull request #267 from freak12techno/filter-out-empty-delegatio…
Browse files Browse the repository at this point in the history
…ns-in-rest

Filter out empty delegations in REST server
  • Loading branch information
mappum authored Feb 2, 2024
2 parents d0b427f + 08232f5 commit 8b3f3cd
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion rest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ async fn staking_delegators_delegations(address: &str) -> Value {
let mut entries = vec![];

for (validator_address, delegation) in delegations {
if delegation.staked == 0 {
continue;
}

entries.push(json!({
"delegation": {
"delegator_address": address.to_string(),
Expand Down Expand Up @@ -530,6 +534,10 @@ async fn staking_delegators_unbonding_delegations(address: &str) -> Value {
let mut unbonds = vec![];

for (val_address, delegation) in delegations {
if delegation.unbonding.len() == 0 {
continue;
}

let mut entries = vec![];
for unbond in delegation.unbonding {
let t = Utc.timestamp_opt(unbond.start_seconds, 0).unwrap();
Expand All @@ -547,7 +555,10 @@ async fn staking_delegators_unbonding_delegations(address: &str) -> Value {
}))
}

json!({ "unbonding_responses": unbonds, "pagination": { "next_key": null, "total": unbonds.len().to_string() } })
json!({
"unbonding_responses": unbonds,
"pagination": { "next_key": null, "total": unbonds.len().to_string() }
})
}

#[get("/staking/delegators/<_address>/unbonding_delegations")]
Expand All @@ -566,6 +577,10 @@ async fn staking_validators_delegations(address: &str) -> Value {
let mut entries = vec![];

for (delegator_address, delegation) in delegations {
if delegation.staked == 0 {
continue;
}

entries.push(json!({
"delegation": {
"delegator_address": delegator_address.to_string(),
Expand Down

0 comments on commit 8b3f3cd

Please sign in to comment.