use nym_credentials::ecash::bandwidth::serialiser::keys::EpochVerificationKey;
use nym_credentials::ecash::bandwidth::serialiser::signatures::{
AggregatedCoinIndicesSignatures, AggregatedExpirationDateSignatures,
};
use nym_ecash_time::Date;
use nym_validator_client::nym_api::EpochId;
use crate::traits::{CredentialFetcherError, CredentialPublicDataFetcher};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) enum GlobalDataRequest {
MasterVerificationKey(EpochId),
CoinIndexSignatures(EpochId),
ExpirationDateSignatures {
epoch_id: EpochId,
expiration_date: Date,
},
}
impl GlobalDataRequest {
pub(crate) fn for_ticketbook(
epoch_id: EpochId,
expiration_date: Date,
) -> [GlobalDataRequest; 3] {
[
GlobalDataRequest::MasterVerificationKey(epoch_id),
GlobalDataRequest::CoinIndexSignatures(epoch_id),
GlobalDataRequest::ExpirationDateSignatures {
epoch_id,
expiration_date,
},
]
}
pub(crate) async fn fetch(
&self,
fetcher: &dyn CredentialPublicDataFetcher,
) -> Result<GlobalData, CredentialFetcherError> {
match *self {
GlobalDataRequest::MasterVerificationKey(epoch_id) => fetcher
.fetch_master_verification_key(epoch_id)
.await
.map(Box::new)
.map(GlobalData::MasterVerificationKey),
GlobalDataRequest::CoinIndexSignatures(epoch_id) => fetcher
.fetch_coin_index_signatures(epoch_id)
.await
.map(GlobalData::CoinIndexSignatures),
GlobalDataRequest::ExpirationDateSignatures {
epoch_id,
expiration_date,
} => fetcher
.fetch_expiration_date_signatures(expiration_date, epoch_id)
.await
.map(GlobalData::ExpirationDateSignatures),
}
}
}
#[derive(Clone)]
pub(crate) enum GlobalData {
MasterVerificationKey(Box<EpochVerificationKey>),
CoinIndexSignatures(AggregatedCoinIndicesSignatures),
ExpirationDateSignatures(AggregatedExpirationDateSignatures),
}