From 1a76934aac5f7d8b3ab834e9627e797c44f7a0c0 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Mon, 14 Oct 2024 18:05:59 -0400 Subject: [PATCH] get_output_histogram --- binaries/cuprated/src/rpc/json.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs index a370156f..883a8334 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/json.rs @@ -38,7 +38,7 @@ use cuprate_rpc_types::{ SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse, SyncInfoRequest, SyncInfoResponse, }, - misc::{BlockHeader, GetBan, Status}, + misc::{BlockHeader, GetBan, HistogramEntry, Status}, CORE_RPC_VERSION, }; @@ -512,12 +512,31 @@ async fn flush_transaction_pool( /// async fn get_output_histogram( - state: CupratedRpcHandler, + mut state: CupratedRpcHandler, request: GetOutputHistogramRequest, ) -> Result { + let input = cuprate_types::OutputHistogramInput { + amounts: request.amounts, + min_count: request.min_count, + max_count: request.max_count, + unlocked: request.unlocked, + recent_cutoff: request.recent_cutoff, + }; + + let histogram = blockchain::output_histogram(&mut state.blockchain_read, input) + .await? + .into_iter() + .map(|entry| HistogramEntry { + amount: entry.amount, + total_instances: entry.total_instances, + unlocked_instances: entry.unlocked_instances, + recent_instances: entry.recent_instances, + }) + .collect(); + Ok(GetOutputHistogramResponse { base: AccessResponseBase::ok(), - histogram: todo!(), + histogram, }) }