v0.2.11-pre.008
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-offchain-transport-lib/src/market_price_registry.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Provider-neutral registry projection for configured market-price providers.
|
||||
|
||||
@@ -25,6 +25,11 @@ impl crate::MarketPriceProviderRegistryEntry {
|
||||
return &self.state;
|
||||
}
|
||||
|
||||
/// Replaces this entry's generic availability projection for the owning runtime service.
|
||||
pub(crate) fn set_availability(&mut self, availability: crate::MarketPriceProviderAvailability) {
|
||||
self.state.set_availability(availability);
|
||||
}
|
||||
|
||||
/// Creates one generic registry entry while keeping descriptor and state identity synchronized.
|
||||
#[must_use]
|
||||
pub fn new(descriptor: crate::MarketPriceProviderDescriptor, availability: crate::MarketPriceProviderAvailability) -> Self {
|
||||
@@ -80,6 +85,20 @@ impl crate::MarketPriceProviderRegistry {
|
||||
return self.entry(provider_id).map(crate::MarketPriceProviderRegistryEntry::state);
|
||||
}
|
||||
|
||||
/// Updates one existing provider availability and reports whether the provider was present.
|
||||
pub(crate) fn set_availability(&mut self, provider_id: &crate::MarketPriceProviderId, availability: crate::MarketPriceProviderAvailability) -> bool {
|
||||
let index = self.entries.binary_search_by(|entry| return entry.descriptor().id().cmp(provider_id));
|
||||
let entry = match index {
|
||||
std::result::Result::Ok(value) => self.entries.get_mut(value),
|
||||
std::result::Result::Err(_) => std::option::Option::None,
|
||||
};
|
||||
if let std::option::Option::Some(entry) = entry {
|
||||
entry.set_availability(availability);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Builds one bounded deterministic registry and rejects duplicate provider identifiers.
|
||||
pub fn new(mut entries: std::vec::Vec<crate::MarketPriceProviderRegistryEntry>) -> ksp_core_lib::Result<Self> {
|
||||
if entries.len() > MARKET_PRICE_PROVIDER_REGISTRY_MAX_ENTRIES {
|
||||
|
||||
Reference in New Issue
Block a user