Skip to content

Commit cacbaa9

Browse files
committed
fix: return historical epochs info even when store-spdd is disabled
1 parent 04b5c29 commit cacbaa9

File tree

1 file changed

+9
-8
lines changed
  • modules/rest_blockfrost/src/handlers

1 file changed

+9
-8
lines changed

modules/rest_blockfrost/src/handlers/epochs.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ pub async fn handle_epoch_info_blockfrost(
100100

101101
// For the latest epoch, query accounts-state for the stake pool delegation distribution (SPDD)
102102
// Otherwise, fall back to SPDD module to fetch historical epoch totals
103+
// if spdd_storage is not enabled, return NULL for active_stakes
103104
let epoch_number = response.epoch;
104-
let total_active_stakes: u64 = if is_latest {
105+
let total_active_stakes = if is_latest {
105106
let total_active_stakes_msg = Arc::new(Message::StateQuery(StateQuery::Accounts(
106107
AccountsStateQuery::GetActiveStakes {},
107108
)));
@@ -112,10 +113,10 @@ pub async fn handle_epoch_info_blockfrost(
112113
|message| match message {
113114
Message::StateQueryResponse(StateQueryResponse::Accounts(
114115
AccountsStateQueryResponse::ActiveStakes(total_active_stake),
115-
)) => Ok(total_active_stake),
116+
)) => Ok(Some(total_active_stake)),
116117
Message::StateQueryResponse(StateQueryResponse::Accounts(
117-
AccountsStateQueryResponse::Error(e),
118-
)) => Err(e),
118+
AccountsStateQueryResponse::Error(_),
119+
)) => Ok(None),
119120
_ => Err(QueryError::internal_error(
120121
"Unexpected message type while retrieving the latest total active stakes",
121122
)),
@@ -136,17 +137,17 @@ pub async fn handle_epoch_info_blockfrost(
136137
|message| match message {
137138
Message::StateQueryResponse(StateQueryResponse::SPDD(
138139
SPDDStateQueryResponse::EpochTotalActiveStakes(total_active_stakes),
139-
)) => Ok(total_active_stakes),
140+
)) => Ok(Some(total_active_stakes)),
140141
Message::StateQueryResponse(StateQueryResponse::SPDD(
141-
SPDDStateQueryResponse::Error(e),
142-
)) => Err(e),
142+
SPDDStateQueryResponse::Error(_),
143+
)) => Ok(None),
143144
_ => Err(QueryError::internal_error(
144145
format!("Unexpected message type while retrieving total active stakes for epoch: {epoch_number}"),
145146
)),
146147
},
147148
)
148149
.await?
149-
};
150+
}.unwrap_or(0);
150151

151152
if total_active_stakes == 0 {
152153
response.active_stake = None;

0 commit comments

Comments
 (0)