-
Notifications
You must be signed in to change notification settings - Fork 529
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
Cli: add a query for a range of pending snark work #16260
base: al/snark-work-graphql
Are you sure you want to change the base?
Conversation
src/app/cli/src/init/client.ml
Outdated
| Some end_idx -> | ||
let len = | ||
if len_response <= end_idx then len_response - start_idx | ||
else max 0 (end_idx - start_idx) | ||
in | ||
Array.sub ~pos:start_idx ~len pending_snark_work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer having a when clause in the match statement that verifies if start_idx <= end_idx <= len_response. And then having a catchall statement in the end that returns empty list.
Also I think this logic breaks if negative indexes are passed, which is technically possible rn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a a new version that checks if indexes are positives. If not, it now returns [||]
@@ -1029,6 +1029,38 @@ let to_signed_fee_exn sign magnitude = | |||
let sgn = match sign with `PLUS -> Sgn.Pos | `MINUS -> Neg in | |||
Currency.Fee.Signed.create ~sgn ~magnitude | |||
|
|||
let format_pending_snark_work ?(f = Fun.id) graphql_endpoint = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrmr1993 has sent me nits,about passing in functions like this instead of piping, but I don't really mind.
let start_idx = | ||
flag "--start-idx" ~aliases:[ "start-idx" ] | ||
~doc:"START_IDX first index of the range (included)" | ||
(required Cli_lib.Arg_type.int16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
making this an int allows this to be negative, ik it's a cli command but still seems a bit foot gunny.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the int, but it is now checked in the function that the indexes are positive.
2d977f5
to
d5882ba
Compare
bd6931b
to
fecdf86
Compare
let end_idx = | ||
flag "--end-idx" ~aliases:[ "end-idx" ] | ||
~doc:"END_IDX first index of the range (excluded)" | ||
(optional Cli_lib.Arg_type.int16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
i still prefer to enforce this as positive through the
type system instead of runtime, but your logic is good so I will approve. I’m also generally more a fan of returning empty list when the user inputs an extremely high end index instead of treating as a none case, but again the logic is fine.
No description provided.