@@ -10,13 +10,13 @@ use acropolis_common::{
1010 accounts:: { AccountsStateQuery , AccountsStateQueryResponse } ,
1111 governance:: { GovernanceStateQuery , GovernanceStateQueryResponse } ,
1212 } ,
13- Credential , GovActionId , StakeAddress , TxHash , Voter ,
13+ Credential , GovActionId , TxHash , Voter ,
1414} ;
1515use anyhow:: { anyhow, Result } ;
1616use caryatid_sdk:: Context ;
1717use reqwest:: Client ;
1818use serde_json:: Value ;
19- use std:: { collections :: HashMap , sync:: Arc } ;
19+ use std:: sync:: Arc ;
2020
2121pub async fn handle_dreps_list_blockfrost (
2222 context : Arc < Context < Message > > ,
@@ -191,27 +191,6 @@ pub async fn handle_drep_delegators_blockfrost(
191191 Message :: StateQueryResponse ( StateQueryResponse :: Governance (
192192 GovernanceStateQueryResponse :: DRepDelegators ( delegators) ,
193193 ) ) => {
194- let stake_address_to_bech32: HashMap < StakeAddress , String > = match delegators
195- . addresses
196- . iter ( )
197- . map ( |addr| {
198- let credential = addr. get_credential ( ) ;
199- let bech32 = credential
200- . to_stake_bech32 ( )
201- . map_err ( |_| anyhow ! ( "Failed to encode stake address" ) ) ?;
202- Ok ( ( addr. clone ( ) , bech32) )
203- } )
204- . collect :: < Result < HashMap < _ , _ > > > ( )
205- {
206- Ok ( map) => map,
207- Err ( e) => {
208- return Ok ( RESTResponse :: with_text (
209- 500 ,
210- & format ! ( "Internal error: {e}" ) ,
211- ) ) ;
212- }
213- } ;
214-
215194 let msg = Arc :: new ( Message :: StateQuery ( StateQuery :: Accounts (
216195 AccountsStateQuery :: GetAccountsUtxoValuesMap {
217196 stake_addresses : delegators. addresses . clone ( ) ,
@@ -226,27 +205,31 @@ pub async fn handle_drep_delegators_blockfrost(
226205 Message :: StateQueryResponse ( StateQueryResponse :: Accounts (
227206 AccountsStateQueryResponse :: AccountsUtxoValuesMap ( map) ,
228207 ) ) => {
229- let mut response = Vec :: new ( ) ;
230-
231- for ( stake_address, amount) in map {
232- let Some ( bech32) = stake_address_to_bech32. get ( & stake_address) else {
233- return Ok ( RESTResponse :: with_text (
208+ let response: Result < Vec < _ > > = map
209+ . into_iter ( )
210+ . map ( |( stake_address, amount) | {
211+ let bech32 = stake_address
212+ . to_string ( )
213+ . map_err ( |e| anyhow ! ( "Failed to encode stake address {}" , e) ) ?;
214+
215+ Ok ( serde_json:: json!( {
216+ "address" : bech32,
217+ "amount" : amount. to_string( ) ,
218+ } ) )
219+ } )
220+ . collect ( ) ;
221+
222+ match response {
223+ Ok ( response) => match serde_json:: to_string_pretty ( & response) {
224+ Ok ( json) => Ok ( RESTResponse :: with_json ( 200 , & json) ) ,
225+ Err ( e) => Ok ( RESTResponse :: with_text (
234226 500 ,
235- "Internal error: missing Bech32 for stake key" ,
236- ) ) ;
237- } ;
238-
239- response. push ( serde_json:: json!( {
240- "address" : bech32,
241- "amount" : amount. to_string( ) ,
242- } ) ) ;
243- }
244-
245- match serde_json:: to_string_pretty ( & response) {
246- Ok ( json) => Ok ( RESTResponse :: with_json ( 200 , & json) ) ,
227+ & format ! ( "Failed to serialize DRep delegators: {e}" ) ,
228+ ) ) ,
229+ } ,
247230 Err ( e) => Ok ( RESTResponse :: with_text (
248231 500 ,
249- & format ! ( "Failed to serialize DRep delegators : {e}" ) ,
232+ & format ! ( "Internal error : {e}" ) ,
250233 ) ) ,
251234 }
252235 }
@@ -279,7 +262,6 @@ pub async fn handle_drep_delegators_blockfrost(
279262 _ => Ok ( RESTResponse :: with_text ( 500 , "Unexpected message type" ) ) ,
280263 }
281264}
282-
283265pub async fn handle_drep_metadata_blockfrost (
284266 context : Arc < Context < Message > > ,
285267 params : Vec < String > ,
0 commit comments