Skip to content

Commit

Permalink
Fix bool query parameters (#2094)
Browse files Browse the repository at this point in the history
* Fix bool query parameters

* bump windows-targets

* else if

* Update test with bool and u64 types
  • Loading branch information
Thoralf-M authored Feb 29, 2024
1 parent 6e020c1 commit 2e34281
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
48 changes: 24 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions sdk/src/client/node_api/indexer/query_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ pub trait QueryParameter: Serialize + Send + Sync {

for (field, v) in value.as_object().unwrap().iter() {
if !v.is_null() {
if let Some(v_str) = v.as_str() {
if let Some(v_bool) = v.as_bool() {
if !query_string.is_empty() {
query_string.push('&');
}
query_string.push_str(&format!("{}={}", field, v_str));
}
if let Some(v_u64) = v.as_u64() {
query_string.push_str(&format!("{field}={v_bool}"));
} else if let Some(v_str) = v.as_str() {
if !query_string.is_empty() {
query_string.push('&');
}
query_string.push_str(&format!("{}={}", field, v_u64));
query_string.push_str(&format!("{field}={v_str}"));
} else if let Some(v_u64) = v.as_u64() {
if !query_string.is_empty() {
query_string.push('&');
}
query_string.push_str(&format!("{field}={v_u64}"));
}
}
}
Expand Down Expand Up @@ -322,16 +326,21 @@ mod tests {
Bech32Address::try_from_str("atoi1qzt0nhsf38nh6rs4p6zs5knqp6psgha9wsv74uajqgjmwc75ugupx3y7x0r")
.unwrap(),
)
.created_after(5.into())
.has_timelock(true)
.cursor("".into());
assert_eq!(
basic_outputs_query_parameters.to_query_string(),
Some("address=atoi1qzt0nhsf38nh6rs4p6zs5knqp6psgha9wsv74uajqgjmwc75ugupx3y7x0r&cursor=".into())
Some(
"address=atoi1qzt0nhsf38nh6rs4p6zs5knqp6psgha9wsv74uajqgjmwc75ugupx3y7x0r&createdAfter=5&cursor=&hasTimelock=true"
.into()
)
);

basic_outputs_query_parameters.replace_cursor("newCursor".into());
assert_eq!(
basic_outputs_query_parameters.to_query_string(),
Some("address=atoi1qzt0nhsf38nh6rs4p6zs5knqp6psgha9wsv74uajqgjmwc75ugupx3y7x0r&cursor=newCursor".into())
Some("address=atoi1qzt0nhsf38nh6rs4p6zs5knqp6psgha9wsv74uajqgjmwc75ugupx3y7x0r&createdAfter=5&cursor=newCursor&hasTimelock=true".into())
);
}
}

0 comments on commit 2e34281

Please sign in to comment.