CLI prints on stdout and seller serializes to json

rendezvous-demo
Daniel Karzel 3 years ago
parent 2bdfc58ed7
commit 23ee6c1bae
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E

@ -291,10 +291,18 @@ async fn main() -> Result<()> {
.await?;
for seller in sellers {
// TODO: Do not use tracing for printing this information
// TODO: Print on stdout
// TODO: Decide if the json flag should still be honoured
tracing::info!(peer_id=%seller.peer_id, multiaddr=%seller.multiaddr, price=%seller.quote.price, max_quantity=%seller.quote.max_quantity, min_quantity=%seller.quote.min_quantity);
if json {
println!("{}", serde_json::to_string(&seller)?);
} else {
println!(
"Seller: peer-id={}, addr={}, price={}, min_quantity={}, max_quantity={}",
seller.peer_id,
seller.multiaddr,
seller.quote.price,
seller.quote.min_quantity,
seller.quote.max_quantity
);
}
}
}
};

@ -9,6 +9,8 @@ use libp2p::rendezvous::{Namespace, Rendezvous};
use libp2p::request_response::{RequestResponseEvent, RequestResponseMessage};
use libp2p::swarm::SwarmEvent;
use libp2p::{identity, rendezvous, Multiaddr, PeerId, Swarm};
use serde::Serialize;
use serde_with::{serde_as, DisplayFromStr};
use std::collections::HashMap;
use std::time::Duration;
@ -43,7 +45,10 @@ pub async fn list_sellers(
Ok(sellers)
}
#[serde_as]
#[derive(Debug, Serialize)]
pub struct Seller {
#[serde_as(as = "DisplayFromStr")]
pub peer_id: PeerId,
pub multiaddr: Multiaddr,
pub quote: BidQuote,

Loading…
Cancel
Save