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

Cli: add a query for a range of pending snark work #16260

Open
wants to merge 2 commits into
base: al/snark-work-graphql
Choose a base branch
from

Conversation

anne-laure-s
Copy link
Member

No description provided.

Comment on lines 1098 to 1103
| 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
Copy link
Member

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.

Copy link
Member Author

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 =
Copy link
Member

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)
Copy link
Member

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.

Copy link
Member Author

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.

let end_idx =
flag "--end-idx" ~aliases:[ "end-idx" ]
~doc:"END_IDX first index of the range (excluded)"
(optional Cli_lib.Arg_type.int16)
Copy link
Member

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.

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

Successfully merging this pull request may close these issues.

2 participants