cln-grpc: Skip serializing fields when Option<Vec<T>> is empty too

The CLN API is rather strict about the fact that we should skip
providing a field whenever it is empty. Checking for `is_none` would
still include empty arrays.

Changelog-Fixed cln-rpc: Optional empty arrays will no longer be serialized in requests
This commit is contained in:
Christian Decker
2022-06-30 13:44:37 +02:00
committed by Rusty Russell
parent 77f5eb556b
commit 12275d0bfe
3 changed files with 32 additions and 22 deletions

View File

@@ -106,6 +106,16 @@ impl ClnRpc {
}
}
/// Used to skip optional arrays when serializing requests.
fn is_none_or_empty<T>(f: &Option<Vec<T>>) -> bool
where
T: Clone,
{
// TODO Find a better way to check, possibly without cloning
let f = f.clone();
f.is_none() || f.unwrap().is_empty()
}
#[cfg(test)]
mod test {
use super::*;