From 6abf83f4adfe02178b6133a402d099e0aa8d83cc Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Thu, 8 Jul 2021 12:42:26 +1000 Subject: [PATCH] Sort seller list inside of `list_sellers` By sorting the list inside we have a more deterministic output that makes processing in JSON easier. --- swap/src/bin/swap.rs | 3 +-- swap/src/cli/list_sellers.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index 5c39af1d..a497cbd9 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -285,7 +285,7 @@ async fn main() -> Result<()> { .context("Failed to read in seed file")?; let identity = seed.derive_libp2p_identity(); - let mut sellers = list_sellers( + let sellers = list_sellers( rendezvous_node_peer_id, rendezvous_point, namespace, @@ -293,7 +293,6 @@ async fn main() -> Result<()> { identity, ) .await?; - sellers.sort(); if json { for seller in sellers { diff --git a/swap/src/cli/list_sellers.rs b/swap/src/cli/list_sellers.rs index 3a05a150..315f1b64 100644 --- a/swap/src/cli/list_sellers.rs +++ b/swap/src/cli/list_sellers.rs @@ -15,6 +15,12 @@ use std::collections::hash_map::Entry; use std::collections::HashMap; use std::time::Duration; +/// Returns sorted list of sellers, with [Online](Status::Online) listed first. +/// +/// First uses the rendezvous node to discover peers in the given namespace, +/// then fetches a quote from each peer that was discovered. If fetching a quote +/// from a discovered peer fails the seller's status will be +/// [Unreachable](Status::Unreachable). pub async fn list_sellers( rendezvous_node_peer_id: PeerId, rendezvous_node_addr: Multiaddr, @@ -289,7 +295,10 @@ impl EventLoop { .collect::, _>>(); match all_quotes_fetched { - Ok(sellers) => break sellers, + Ok(mut sellers) => { + sellers.sort(); + break sellers; + } Err(StillPending {}) => continue, } }