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

refactor: make optional BlockId params required in provider functions #516

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

EmperorOrokuSaki
Copy link
Contributor

@EmperorOrokuSaki EmperorOrokuSaki commented Apr 12, 2024

Motivation

This issue #514

Solution

Make the BlockId optional and use the default value if it's None.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tag is a required argument,

I think the option does not improve the API, because None is equal to Default::default() or BlockId::latest()

@EmperorOrokuSaki
Copy link
Contributor Author

the tag is a required argument,

I think the option does not improve the API, because None is equal to Default::default() or BlockId::latest()

That is true, it is a required parameter in the RPC specification, but the other examples provided in the original issue have the same condition so it's a case of inconsistency a bit. I checked those methods and for those it's also required in the specification.

@mattsse
Copy link
Member

mattsse commented Apr 12, 2024

I see, then we should change all Option<BlockId> to BlockId

@EmperorOrokuSaki
Copy link
Contributor Author

I see, then we should change all Option<BlockId> to BlockId
Sounds good. I'll change them in this pr.

@EmperorOrokuSaki EmperorOrokuSaki changed the title refactor: make blockId optional in get_code_at and get_uncle methods of provider refactor: make optional BlockId params required in provider functions Apr 12, 2024
@EmperorOrokuSaki
Copy link
Contributor Author

In some files previously None was supplied when the arg was of the type Option<BlockId>, I changed those to BlockId::default() since that was the final value.

@prestwich
Copy link
Member

I think the option does not improve the API, because None is equal to Default::default() or BlockId::latest()

The only improvement is writing None is fewer characters than Default::default(). Seems kinda pointless. in favor of this change

@prestwich
Copy link
Member

alternate API designs would be to bifurcate, which seems ok-but-verbose on our end

fn call_with_block(..., block_id: BlockId)
fn call(...) { self.call_with_block(..., Default::default()) }

or to switch to a rpc builder pattern for return values of those types. which seems bad

@prestwich prestwich merged commit 3ac4df3 into alloy-rs:main Apr 16, 2024
18 checks passed
@EmperorOrokuSaki EmperorOrokuSaki deleted the feat/optional-blockid branch April 16, 2024 10:50
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
…alloy-rs#516)

* refactor: make blockId optional in getCode and getUncle

* feat: change all Option<BlockId> types to BlockId
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.

3 participants