Skip to content

Commit

Permalink
Include the total cycles topped up
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Dec 12, 2024
1 parent 719d306 commit 8a6a2d8
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ic_cdk::query;
use serde::Serialize;
use std::collections::{BTreeMap, HashMap};
use std::str::FromStr;
use types::{BuildVersion, CanisterId, HttpRequest, HttpResponse, TimestampMillis, UserId};
use types::{BuildVersion, CanisterId, Cycles, CyclesTopUp, HttpRequest, HttpResponse, TimestampMillis, UserId};

#[query]
fn http_request(request: HttpRequest) -> HttpResponse {
Expand All @@ -31,7 +31,12 @@ fn http_request(request: HttpRequest) -> HttpResponse {
return HttpResponse::not_found();
};

build_json_response(&user.cycle_top_ups)
let total = user.cycle_top_ups.iter().map(|c| c.amount).sum();

build_json_response(&TopUps {
total,
top_ups: &user.cycle_top_ups,
})
}

fn get_user_canister_versions(state: &RuntimeState) -> HttpResponse {
Expand Down Expand Up @@ -83,3 +88,9 @@ struct UserCanisterVersion {
count: u32,
users: Vec<UserId>,
}

#[derive(Serialize)]
struct TopUps<'a> {
total: Cycles,
top_ups: &'a [CyclesTopUp],
}

0 comments on commit 8a6a2d8

Please sign in to comment.