|
| 1 | +use anyhow::{anyhow, Context}; |
1 | 2 | use mithril_aggregator::{
|
2 | 3 | dependency_injection::DependenciesBuilder,
|
3 | 4 | entities::OpenMessage,
|
4 | 5 | services::{CertifierService, TickerService},
|
5 | 6 | };
|
6 | 7 | use mithril_common::{
|
7 | 8 | entities::{Beacon, Epoch, SignedEntityType, SignedEntityTypeDiscriminants},
|
8 |
| - BeaconProvider, |
| 9 | + BeaconProvider, StdResult, |
9 | 10 | };
|
10 | 11 | use std::sync::Arc;
|
11 | 12 |
|
@@ -43,39 +44,37 @@ impl AggregatorObserver {
|
43 | 44 | pub async fn get_current_open_message(
|
44 | 45 | &self,
|
45 | 46 | discriminant: SignedEntityTypeDiscriminants,
|
46 |
| - ) -> Result<Option<OpenMessage>, String> { |
| 47 | + ) -> StdResult<Option<OpenMessage>> { |
47 | 48 | let signed_entity_type = self.build_current_signed_entity_type(discriminant).await?;
|
48 | 49 |
|
49 | 50 | self.certifier_service
|
50 | 51 | .get_open_message(&signed_entity_type)
|
51 | 52 | .await
|
52 |
| - .map_err(|e| { |
53 |
| - format!( |
54 |
| - "Requesting current open message of type CardanoImmutableFilesFull should be not fail: {e:?}" |
55 |
| - ) |
56 |
| - }) |
| 53 | + .with_context(|| "Requesting current open message of type CardanoImmutableFilesFull should be not fail") |
57 | 54 | }
|
58 | 55 |
|
59 | 56 | // Get the [entity type][SignedEntityType::CardanoImmutableFilesFull] of the current current open message
|
60 | 57 | pub async fn get_current_signed_entity_type(
|
61 | 58 | &self,
|
62 | 59 | discriminant: SignedEntityTypeDiscriminants,
|
63 |
| - ) -> Result<SignedEntityType, String> { |
| 60 | + ) -> StdResult<SignedEntityType> { |
64 | 61 | match self.get_current_open_message(discriminant).await? {
|
65 |
| - None => Err("An open message should be available for cardano immutables".to_string()), |
| 62 | + None => Err(anyhow!( |
| 63 | + "An open message should be available for cardano immutables" |
| 64 | + )), |
66 | 65 | Some(message) => Ok(message.signed_entity_type),
|
67 | 66 | }
|
68 | 67 | }
|
69 | 68 |
|
70 | 69 | async fn build_current_signed_entity_type(
|
71 | 70 | &self,
|
72 | 71 | discriminant: SignedEntityTypeDiscriminants,
|
73 |
| - ) -> Result<SignedEntityType, String> { |
| 72 | + ) -> StdResult<SignedEntityType> { |
74 | 73 | let beacon = self
|
75 | 74 | .beacon_provider
|
76 | 75 | .get_current_beacon()
|
77 | 76 | .await
|
78 |
| - .map_err(|e| format!("Querying the current beacon should not fail: {e:?}"))?; |
| 77 | + .with_context(|| "Querying the current beacon should not fail")?; |
79 | 78 |
|
80 | 79 | match discriminant {
|
81 | 80 | SignedEntityTypeDiscriminants::MithrilStakeDistribution => {
|
|
0 commit comments