-
Notifications
You must be signed in to change notification settings - Fork 254
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
added at_latest #900
added at_latest #900
Conversation
subxt/src/blocks/blocks_client.rs
Outdated
/// Obtain block details given the provided block hash, or the latest block if `None` is | ||
/// provided. |
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.
/// Obtain block details given the provided block hash, or the latest block if `None` is | |
/// provided. | |
/// Obtain block details of the latest block hash. |
subxt/src/blocks/blocks_client.rs
Outdated
/// | ||
/// # Warning | ||
/// | ||
/// This call only supports blocks produced since the most recent |
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.
We can remove this warning from the documentation since we are always operating with the latest block.
And therefore, users have no way to utilize an older and incompatible block here.
subxt/src/blocks/blocks_client.rs
Outdated
/// Obtain block details given the provided block hash, or the latest block if `None` is | ||
/// provided. | ||
/// | ||
/// # Warning |
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: Since this function is not publically exposed by subxt, we could also remove the warning message.
I believe we placed that warning to explicitly state in the documentation that older blocks may not be supported, just to set up the user expectations.
@@ -48,6 +48,36 @@ where | |||
/// runtime upgrade. You can attempt to retrieve older blocks, | |||
/// but may run into errors attempting to work with them. | |||
pub fn at( | |||
&self, |
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.
We could also change the documentation of this function to state /// Obtain block details given the block hash.
The code looks good, just a few nits regarding the documentation! 👍 I wonder if we could also remove the need to have the For the |
subxt/src/blocks/blocks_client.rs
Outdated
|
||
/// Obtain block details given the provided block hash, or the latest block if `None` is | ||
/// provided. | ||
#[inline] |
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 would like some consistency here w.r.t. to inline
here as this method is marked as "inline" but the wrappers on top of this are not.
@lexnv what do you prefer?
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.
@niklasad1 I wanted to keep consistency to how it was before. Before, the pub method was also not inlined. Now the inline will just generate two pub functions at()
and at_latest()
that are both not inlined (like before).
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 see, makes sense but let's hear what @lexnv thinks :)
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 wouldn't have the #[inline]
here myself (if anything I'd have it on at()
and at_latest()
because they are trivially inlineable at the call site and would have a similar effect with less code duplication).
But more to the point, at()
no longer needs to be async
, so I think that this implementation should be split up and the relevant part of it put in each of at()
and at_latest()
, so that only the latter needs to be declared async
now.
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.
Ah I see; it would have to be async anyway! In that case let';s just remove the #[inline]
(if anything it's be best on at()
and at_latest()
I think) and this looks good to me!
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 like it and makes the code more readable, all good.
Some comments about "inline attributes" these are in general added by the rust compiler but if we want to use them in these functions we should use them in the entire call tree. not just in the leaf methods.
subxt/src/events/events_client.rs
Outdated
/// runtime upgrade. You can attempt to retrieve events from older blocks, | ||
/// but may run into errors attempting to work with them. | ||
#[inline] | ||
fn at_optional_block_hash( |
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.
As above, let's put this code directly into at()
and at_latest()
so that the former no longer needs to be async
, and no need for #[inline]
:)
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.
Ah I see; both have to be async
anyway actually!
In this case, let's just remove the #[inline]
and it's all good :)
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.
A couple of comments to tweak per Alex's comments, and I'd remove the #[inline]
s, but otherwise looks great!
resolves #899 by providing a simplified API for
.at(Option<Hash>)
by specialization into.at_latest()
and.at(Hash)
in various places: