-
Notifications
You must be signed in to change notification settings - Fork 256
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
feat(providers): event, polling and streaming methods #274
Conversation
crates/providers/src/new.rs
Outdated
/// | ||
/// The return value depends on what stream `id` corresponds to. | ||
/// See [`FilterChanges`] for all possible return values. | ||
#[auto_impl(keep_default_for(&, &mut, Rc, Arc, Box))] |
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.
TIL this is necessary for dyn Provider
to work, because otherwise auto_impl
puts U: Provider + Sized
bounds on the generic implementations if Self: Sized
methods are not marked with keep_default_for
. I added a test for this in this file
looks ossome |
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.
gg so far so good
crates/providers/src/new.rs
Outdated
self.client().prepare("eth_getTransactionCount", (address, tag.unwrap_or_default())).await | ||
} | ||
|
||
/// Get a block by its number. | ||
/// | ||
/// TODO: Network associate | ||
// TODO: Network associate |
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.
not a blocker
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.
There is no network block RPC type, not really related to this PR
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.
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 think the pending tx type should take a clone
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.
generally like this, although we need to figure out a way to make transport layering work again. i think let's get this in, think on it, and if it's not possible, maybe we can move most use cases into provider layers? (retry logic etc)
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.
Great!!! I am comfortable moving forward with this, let's get all the ethers examples ported now @yash-atreya @zerosnacks and please flag missing pieces to Dani as needed.
/// .watch() | ||
/// .await?; |
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.
OK I am fine with this API -- let's open issue for potentially auto-registering if possible, but we can move forward.
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.
Not sure what this means
let t = self.transport() as &dyn std::any::Any; | ||
t.downcast_ref::<PubSubFrontend>() | ||
.or_else(|| { | ||
t.downcast_ref::<BoxTransport>() | ||
.and_then(|t| t.as_any().downcast_ref::<PubSubFrontend>()) | ||
}) | ||
.ok_or_else(TransportErrorKind::pubsub_unavailable) | ||
} |
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.
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 probably improve this, but for now this seems fine
/// let poller = provider.watch_blocks().await?; | ||
/// let mut stream = poller.into_stream().flat_map(futures::stream::iter).take(5); | ||
/// while let Some(block_hash) = stream.next().await { |
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.
Can we get rid of the into_stream().flat_map(futures::stream::iter)
? When do we want to use the stream vs the iter? https://docs.rs/futures/latest/futures/stream/fn.iter.html
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.
flat_map(futures::stream::iter)
is .flatten()
for streams of vecs (turns the vec into a stream, then flattens it), as discussed eth_getFilterChanges
returns a Vec when we poll it
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.
progress 💪
with_provider
) since we cannot return a value that references&Self
in theProvider
trait, see below feat(providers): event, polling and streaming methods #274 (comment)boxed
to root provider and rpc clientswatch*
,subscribe
(TODO),filter*
provider methods and related structsEvent
API from ethers, including event*filter
methods insol!
(feat(sol-macro): add event filters to contracts core#563)subscribe
andsubscribe_with_meta
have been merged into one,watch
, which is a flattened stream over theVec<Log>
responses ofeth_getFilterChanges
. The stream returns(E: SolEvent, Log)
Arc::unwrap_or_clone
Closes #264
Ref #270 (no rename, but doc alias)
Closes #293