kad merge: return everything if count isn't provided
@@ -333,12 +333,13 @@ impl<C: Clone + Send + Sync + 'static + AsRef<KademliaApi> + AsRef<ConnectionPoo
}
/// Merge, sort by distance to first key, return top K
+ /// K is optional. If not passed, all elements are returned.
fn kad_merge(&self, args: Vec<serde_json::Value>) -> Result<JValue, JError> {
let mut args = args.into_iter();
let target: String = Args::next("target", &mut args)?;
let left: Vec<String> = Args::next("left", &mut args)?;
let right: Vec<String> = Args::next("right", &mut args)?;
- let count: usize = Args::maybe_next("count", &mut args)?.unwrap_or(20);
+ let count: Option<usize> = Args::maybe_next("count", &mut args)?;
let target = bs58::decode(target).into_vec().map_err(DecodeBase58)?;
let target = Key::from(target);
@@ -357,9 +358,13 @@ impl<C: Clone + Send + Sync + 'static + AsRef<KademliaApi> + AsRef<ConnectionPoo
let keys = keys
.into_iter()
- .map(|k| bs58::encode(k.into_preimage()).into_string())
- .take(count)
- .collect::<Vec<_>>();
+ .map(|k| bs58::encode(k.into_preimage()).into_string());
+
+ let keys: Vec<_> = if let Some(count) = count {
+ keys.take(count).collect()
+ } else {
+ keys.collect()
+ };
Ok(json!(keys))
}
