Skip to content

Commit 6b35ce4

Browse files
committed
chore(client): update capabilities to required capabilities
1 parent 426aa37 commit 6b35ce4

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

internal/mithril-aggregator-discovery/src/capabilities_discoverer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ impl Iterator for CapableAggregatorDiscovererIterator {
8787
type Item = AggregatorEndpoint;
8888

8989
fn next(&mut self) -> Option<Self::Item> {
90-
while let Some(aggregator_endpoint) = self.inner_iterator.next() {
90+
for aggregator_endpoint in self.inner_iterator.by_ref() {
9191
let aggregator_endpoint_clone = aggregator_endpoint.clone();
9292
let aggregator_capabilities = tokio::task::block_in_place(move || {
9393
tokio::runtime::Handle::current().block_on(async move {
9494
aggregator_endpoint_clone.retrieve_capabilities().await
9595
})
9696
});
97-
if let Ok(aggregator_capabilities) = aggregator_capabilities {
98-
if self.required_capabilities.matches(&aggregator_capabilities) {
99-
return Some(aggregator_endpoint);
100-
}
97+
if let Ok(aggregator_capabilities) = aggregator_capabilities
98+
&& self.required_capabilities.matches(&aggregator_capabilities)
99+
{
100+
return Some(aggregator_endpoint);
101101
}
102102
}
103103

mithril-client/src/client.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ use std::sync::Arc;
1010

1111
use mithril_aggregator_discovery::{
1212
AggregatorDiscoverer, CapableAggregatorDiscoverer, HttpConfigAggregatorDiscoverer,
13-
MithrilNetwork,
13+
MithrilNetwork, RequiredAggregatorCapabilities,
1414
};
1515
use mithril_common::api_version::APIVersionProvider;
16-
use mithril_common::messages::AggregatorCapabilities;
1716
use mithril_common::{MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER};
1817

1918
use crate::MithrilResult;
@@ -179,7 +178,7 @@ impl Client {
179178
/// Builder than can be used to create a [Client] easily or with custom dependencies.
180179
pub struct ClientBuilder {
181180
aggregator_discovery: AggregatorDiscoveryType,
182-
aggregator_capabilities: Option<AggregatorCapabilities>,
181+
aggregator_capabilities: Option<RequiredAggregatorCapabilities>,
183182
aggregator_discoverer: Option<Arc<dyn AggregatorDiscoverer>>,
184183
genesis_verification_key: Option<GenesisVerificationKey>,
185184
origin_tag: Option<String>,
@@ -207,6 +206,18 @@ impl ClientBuilder {
207206
)
208207
}
209208

209+
/// Constructs a new `ClientBuilder` that automatically discovers the aggregator for the given
210+
/// Mithril network and with the given genesis verification key.
211+
pub fn automatic(network: &str, genesis_verification_key: &str) -> ClientBuilder {
212+
Self::new(AggregatorDiscoveryType::Automatic(MithrilNetwork::new(
213+
network.to_string(),
214+
)))
215+
.with_genesis_verification_key(GenesisVerificationKey::JsonHex(
216+
genesis_verification_key.to_string(),
217+
))
218+
.with_default_aggregator_discoverer()
219+
}
220+
210221
/// Constructs a new `ClientBuilder` without any dependency set.
211222
pub fn new(aggregator_discovery: AggregatorDiscoveryType) -> ClientBuilder {
212223
Self {
@@ -242,7 +253,10 @@ impl ClientBuilder {
242253
}
243254

244255
/// Sets the aggregator capabilities expected to be matched by the aggregator with which the client will interact.
245-
pub fn with_capabilities(mut self, capabilities: AggregatorCapabilities) -> ClientBuilder {
256+
pub fn with_capabilities(
257+
mut self,
258+
capabilities: RequiredAggregatorCapabilities,
259+
) -> ClientBuilder {
246260
self.aggregator_capabilities = Some(capabilities);
247261

248262
self

0 commit comments

Comments
 (0)