Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitfix(jsonrpc): read simple positional argument in getBalance #2395

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

Tommytrg
Copy link
Member

The initial suggestion was:

  simple = params.get(1).unwrap_or(false);

But, we also have to call parse over the possible String so the one-liner would be:

  simple = params.get(1).and_then(|v| v.as_str().map(|s| s.parse().unwrap_or(false))).unwrap_or(false);

As the previous line looks a bit hard to read, I have used an if let which seems more readable.

@aesedepece
Copy link
Member

aesedepece commented Sep 19, 2023

  simple = params.get(1).and_then(|v| v.as_str().map(|s| s.parse().unwrap_or(false))).unwrap_or(false);

As the previous line looks a bit hard to read, I have used an if let which seems more readable.

@Tommytrg It doesn't look that bad if you leverage the and_then magic and parse from Value instead of str:

simple = params.get(1).and_then(Value::as_bool).unwrap_or(false);

@Tommytrg
Copy link
Member Author

close #2390

@Tommytrg Tommytrg merged commit b9530af into witnet:master Sep 22, 2023
1 check passed
@Tommytrg Tommytrg deleted the getBalance-args branch September 22, 2023 10:43
@Tommytrg
Copy link
Member Author

close #2390

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants