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

feat(providers): event, polling and streaming methods #274

Merged
merged 46 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7d6f5f8
feat(providers): event, polling and streaming methods
DaniPopes Mar 8, 2024
f2dac32
update
DaniPopes Mar 11, 2024
bc5fa21
feat: better pending transaction
DaniPopes Mar 11, 2024
4d3046b
feat: test event polling
DaniPopes Mar 11, 2024
b63d5f3
rm subscribe
DaniPopes Mar 11, 2024
7111f00
chore: bump MSRV to 1.76
DaniPopes Mar 11, 2024
14a797b
feat: implement sol! event filters
DaniPopes Mar 11, 2024
2ac273f
comment
DaniPopes Mar 12, 2024
b8912bd
chore: rename, better docs
DaniPopes Mar 12, 2024
6edd8fe
stuff
DaniPopes Mar 12, 2024
188669f
typos
DaniPopes Mar 12, 2024
1218bb2
reorder
DaniPopes Mar 12, 2024
7f9454e
docs: add an example to PollerBuilder
DaniPopes Mar 12, 2024
025415d
docs: add examples to watch functions
DaniPopes Mar 12, 2024
6159a67
feat: make `RawProvider` object-safe
DaniPopes Mar 12, 2024
40b561a
fix: clippy, ci
DaniPopes Mar 12, 2024
069814d
chore: rename to config
DaniPopes Mar 12, 2024
48072de
fix: deserialize `Transaction`s in `FilterChanges`
DaniPopes Mar 12, 2024
1e1a7eb
Merge branch 'main' into dani/provider-streams
DaniPopes Mar 12, 2024
bd0d19d
lints
DaniPopes Mar 12, 2024
2c6f1d0
Merge branch 'main' into dani/provider-streams
DaniPopes Mar 12, 2024
6c6932b
morelints
DaniPopes Mar 12, 2024
acc2544
more const
DaniPopes Mar 12, 2024
87963a7
feat: return ptx builder in send_transaction
DaniPopes Mar 12, 2024
f1adb8e
some more docs
DaniPopes Mar 12, 2024
6845bd8
chore: clippy
DaniPopes Mar 12, 2024
e6a5587
wip: streams
DaniPopes Mar 12, 2024
8adaa41
Merge branch 'main' into dani/provider-streams
DaniPopes Mar 12, 2024
5d8c267
chore: update nonce manager
DaniPopes Mar 12, 2024
240d506
test: ignore box test for now
DaniPopes Mar 12, 2024
168b0c3
docs
DaniPopes Mar 12, 2024
3743e18
fix: expose box transport as any
DaniPopes Mar 12, 2024
12a421f
docs: readme
DaniPopes Mar 12, 2024
ceb8725
chore: note on pub provider field
DaniPopes Mar 12, 2024
eb0ee46
feat: return `PendingTransactionBuilder` in `CallBuilder::send`
DaniPopes Mar 12, 2024
8ddf18c
feat: flatten `Option<Receipt>` into the result
DaniPopes Mar 12, 2024
98fd3f6
chore: make `TransportErrorKind` non exhaustive
DaniPopes Mar 12, 2024
738a8ae
chore: slightly better API
DaniPopes Mar 13, 2024
1e81c8c
docs: add an example for sol! with contracts
DaniPopes Mar 13, 2024
512e15f
fix
DaniPopes Mar 13, 2024
70dd850
docs: show constructor arguments
DaniPopes Mar 13, 2024
19e43b3
word
DaniPopes Mar 13, 2024
2ed0440
feat: more docs and examples, add watch full pending txs
DaniPopes Mar 13, 2024
0dacfb0
feat: remove lag error from subscription streams
DaniPopes Mar 13, 2024
215d6e9
fix
DaniPopes Mar 13, 2024
c76fb8c
docs: mention subscription limitation
DaniPopes Mar 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
strategy:
fail-fast: false
matrix:
rust: ["stable", "nightly", "1.75"] # MSRV
rust: ["stable", "nightly", "1.76"] # MSRV
flags: ["--no-default-features", "", "--all-features"]
exclude:
# Some features have higher MSRV.
- rust: "1.75" # MSRV
- rust: "1.76" # MSRV
flags: "--all-features"
steps:
- uses: actions/checkout@v3
Expand All @@ -43,13 +43,13 @@ jobs:
cache-on-failure: true
# Only run tests on latest stable and above
- name: Install cargo-nextest
if: ${{ matrix.rust != '1.75' }} # MSRV
if: ${{ matrix.rust != '1.76' }} # MSRV
uses: taiki-e/install-action@nextest
- name: build
if: ${{ matrix.rust == '1.75' }} # MSRV
if: ${{ matrix.rust == '1.76' }} # MSRV
run: cargo build --workspace ${{ matrix.flags }}
- name: test
if: ${{ matrix.rust != '1.75' }} # MSRV
if: ${{ matrix.rust != '1.76' }} # MSRV
run: cargo nextest run --workspace ${{ matrix.flags }}

doctest:
Expand Down Expand Up @@ -80,6 +80,7 @@ jobs:
run: |
cargo hack check --workspace --target wasm32-unknown-unknown \
--exclude alloy-contract \
--exclude alloy-internal-test-utils \
--exclude alloy-network \
--exclude alloy-node-bindings \
--exclude alloy-provider \
Expand Down
32 changes: 11 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.package]
version = "0.1.0"
edition = "2021"
rust-version = "1.75"
rust-version = "1.76"
authors = ["Alloy Contributors"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/alloy-rs/next"
Expand Down Expand Up @@ -41,19 +41,13 @@ alloy-transport-http = { version = "0.1.0", default-features = false, path = "cr
alloy-transport-ipc = { version = "0.1.0", default-features = false, path = "crates/transport-ipc" }
alloy-transport-ws = { version = "0.1.0", default-features = false, path = "crates/transport-ws" }

test-utils = { version = "0.1.0", default-features = false, path = "crates/internal-test-utils", package = "alloy-internal-test-utils" }

alloy-core = { version = "0.6.4", default-features = false, features = ["std"] }
alloy-dyn-abi = { version = "0.6.4", default-features = false, features = [
"std",
] }
alloy-json-abi = { version = "0.6.4", default-features = false, features = [
"std",
] }
alloy-primitives = { version = "0.6.4", default-features = false, features = [
"std",
] }
alloy-sol-types = { version = "0.6.4", default-features = false, features = [
"std",
] }
alloy-dyn-abi = { version = "0.6.4", default-features = false, features = ["std"] }
alloy-json-abi = { version = "0.6.4", default-features = false, features = ["std"] }
alloy-primitives = { version = "0.6.4", default-features = false, features = ["std"] }
alloy-sol-types = { version = "0.6.4", default-features = false, features = ["std"] }

alloy-rlp = "0.3"

Expand All @@ -62,13 +56,8 @@ ethereum_ssz_derive = "0.5"
ethereum_ssz = "0.5"

# crypto
elliptic-curve = { version = "0.13", default-features = false, features = [
"std",
] }
k256 = { version = "0.13", default-features = false, features = [
"ecdsa",
"std",
] }
elliptic-curve = { version = "0.13", default-features = false, features = ["std"] }
k256 = { version = "0.13", default-features = false, features = ["ecdsa", "std"] }
sha2 = { version = "0.10", default-features = false, features = ["std"] }
spki = { version = "0.7", default-features = false, features = ["std"] }

Expand Down Expand Up @@ -117,4 +106,5 @@ tempfile = "3.10"
# TODO: Keep around until alloy-contract is stable.
# This should only be used in `alloy-contract` tests.
[patch.crates-io]
alloy-sol-macro = { git = "https://github.com/alloy-rs/core", rev = "ab0cab1047a088be6cffa4e7a2fcde7cf77aa460" }
# alloy-sol-macro = { git = "https://github.com/alloy-rs/core", rev = "ab0cab1047a088be6cffa4e7a2fcde7cf77aa460" }
alloy-sol-macro = { git = "https://github.com/alloy-rs/core", branch = "dani/sol-event-filters" }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ When updating this, also update:

Alloy will keep a rolling MSRV (minimum supported rust version) policy of **at
least** 6 months. When increasing the MSRV, the new Rust version must have been
released at least six months ago. The current MSRV is 1.75.
released at least six months ago. The current MSRV is 1.76.

Note that the MSRV is not increased automatically, and only as part of a minor
release.
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.75"
msrv = "1.76"
3 changes: 2 additions & 1 deletion crates/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ alloy-primitives.workspace = true
alloy-sol-types.workspace = true

futures-util.workspace = true

futures.workspace = true
thiserror.workspace = true

[dev-dependencies]
alloy-rpc-client.workspace = true
alloy-transport-http.workspace = true
alloy-node-bindings.workspace = true
test-utils.workspace = true
reqwest.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
31 changes: 21 additions & 10 deletions crates/contract/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ pub struct CallBuilder<N: Network, T, P, D> {
request: N::TransactionRequest,
block: Option<BlockId>,
state: Option<StateOverride>,
provider: P,
/// The provider.
pub provider: P,
DaniPopes marked this conversation as resolved.
Show resolved Hide resolved
decoder: D,
transport: PhantomData<T>,
}
Expand All @@ -218,14 +219,18 @@ impl<N: Network, T: Transport + Clone, P: Provider<N, T>> DynCallBuilder<N, T, P
}
}

impl<N: Network, T: Transport + Clone, P: Provider<N, T>, C: SolCall> SolCallBuilder<N, T, P, C> {
#[doc(hidden)]
impl<'a, N: Network, T: Transport + Clone, P: Provider<N, T>, C: SolCall>
SolCallBuilder<N, T, &'a P, C>
{
// `sol!` macro constructor, see `#[sol(rpc)]`. Not public API.
// NOTE: please avoid changing this function due to its use in the `sol!` macro.
#[doc(hidden)]
pub fn new_sol(provider: P, address: &Address, call: &C) -> Self {
pub fn new_sol(provider: &'a P, address: &Address, call: &C) -> Self {
Self::new_inner(provider, call.abi_encode().into(), PhantomData::<C>).to(Some(*address))
}
}

impl<N: Network, T: Transport + Clone, P: Provider<N, T>, C: SolCall> SolCallBuilder<N, T, P, C> {
/// Clears the decoder, returning a raw call builder.
#[inline]
pub fn clear_decoder(self) -> RawCallBuilder<N, T, P> {
Expand Down Expand Up @@ -393,13 +398,13 @@ impl<N: Network, T: Transport + Clone, P: Provider<N, T>, D: CallDecoder> CallBu
}
DaniPopes marked this conversation as resolved.
Show resolved Hide resolved

/// Broadcasts the underlying transaction to the network.
// TODO: more docs referring to customizing PendingTransaction
///
/// See [`Provider::send_transaction`] for more information.
pub async fn send(
&self,
) -> Result<impl IntoFuture<Output = Result<Option<N::ReceiptResponse>>> + '_> {
let pending = self.provider.send_transaction(self.request.clone()).await?;

Ok(pending.and_then(|hash| self.provider.get_transaction_receipt(hash)).map_err(Into::into))
) -> Result<impl Future<Output = Result<Option<N::ReceiptResponse>>> + '_> {
let builder = self.provider.send_transaction(self.request.clone()).await?;
Ok(builder.get_receipt().map_err(Into::into))
}

/// Calculates the address that will be created by the transaction, if any.
Expand Down Expand Up @@ -428,6 +433,13 @@ impl<N: Network, T: Transport, P: Clone, D> CallBuilder<N, T, &P, D> {
/// [`CallBuilder`] can be turned into a [`Future`] automatically with `.await`.
///
/// Defaults to calling [`CallBuilder::call`].
///
/// # Note
///
/// This requires `Self: 'static` due to a current limitation in the Rust type system, namely that
/// the associated future type, the returned future, must be a concrete type (`Box<dyn Future ...>`)
/// and cannot be an opaque type (`impl Future ...`) because `impl Trait` in this position is not
/// stable yet. See [rust-lang/rust#63063](https://github.com/rust-lang/rust/issues/63063).
impl<N, T, P, D> IntoFuture for CallBuilder<N, T, P, D>
where
N: Network,
Expand Down Expand Up @@ -554,7 +566,6 @@ mod tests {
);
}

// TODO: send_transaction, PendingTransaction
#[tokio::test(flavor = "multi_thread")]
async fn deploy_and_call() {
let (provider, anvil) = spawn_anvil();
Expand Down
7 changes: 7 additions & 0 deletions crates/contract/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ pub enum Error {
#[error(transparent)]
TransportError(#[from] TransportError),
}

impl From<alloy_sol_types::Error> for Error {
#[inline]
fn from(e: alloy_sol_types::Error) -> Self {
Self::AbiError(e.into())
}
}
Loading
Loading