alloy-rs / alloy

Transports, Middleware, and Networks for the Alloy project
https://alloy.rs
Apache License 2.0
445 stars 147 forks source link

[Bug] `sol!` macro bug #350

Closed tcoratger closed 3 months ago

tcoratger commented 3 months ago

Component

contract

What version of Alloy are you on?

0.6.4

Operating System

None

Describe the bug

I'm trying two different use cases using the sol! macro:

abigen!(
    StarknetMessagingLocal,
    "../primitives/contracts/messaging/solidity/IStarknetMessagingLocal_ABI.json",
    event_derives(serde::Serialize, serde::Deserialize)
);

in order to call the function in the following ABI:

[
  {
    "inputs": [
      {
        "internalType": "uint256[]",
        "name": "msgHashes",
        "type": "uint256[]"
      }
    ],
    "name": "addMessageHashesFromL2",
    "outputs": [],
    "stateMutability": "payable",
    "type": "function"
  }
]

For that I use following alloy approach

sol! {
    #[sol(rpc, rename_all = "camelcase")]
    #[derive(serde::Serialize, serde::Deserialize)]
    StarknetMessagingLocal,
    "../primitives/contracts/messaging/solidity/IStarknetMessagingLocal_ABI.json"
}

resulting in the following error during cargo build

error[E0107]: missing generics for trait `alloy_provider::Provider`
   --> crates/katana/core/src/service/messaging/ethereum.rs:33:1
    |
33  | / sol! {
34  | |     #[sol(rpc, rename_all = "camelcase")]
35  | |     #[derive(serde::Serialize, serde::Deserialize)]
36  | |     StarknetMessagingLocal,
37  | |     "../primitives/contracts/messaging/solidity/IStarknetMessagingLocal_ABI.json"
38  | | }
    | |_^ expected at least 1 generic argument
    |
note: trait defined here, with at least 1 generic parameter: `N`
   --> /Users/tcoratger/.cargo/git/checkouts/alloy-805bdb2c8d2cb5fa/410850b/crates/provider/src/provider.rs:178:11
    |
178 | pub trait Provider<N: Network, T: Transport + Clone = BoxTransport>: Send + Sync {
    |           ^^^^^^^^ -
    = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add missing generic argument
    |
38  | }<N>
    |  +++

error[E0107]: type alias takes 4 generic arguments but 2 generic arguments were supplied
  --> crates/katana/core/src/service/messaging/ethereum.rs:33:1
   |
33 | / sol! {
34 | |     #[sol(rpc, rename_all = "camelcase")]
35 | |     #[derive(serde::Serialize, serde::Deserialize)]
36 | |     StarknetMessagingLocal,
37 | |     "../primitives/contracts/messaging/solidity/IStarknetMessagingLocal_ABI.json"
38 | | }
   | | ^
   | | |
   | |_expected 4 generic arguments
   |   supplied 2 generic arguments
   |
note: type alias defined here, with 4 generic parameters: `N`, `T`, `P`, `C`
  --> /Users/tcoratger/.cargo/git/checkouts/alloy-805bdb2c8d2cb5fa/410850b/crates/contract/src/call.rs:18:10
   |
18 | pub type SolCallBuilder<N, T, P, C> = CallBuilder<N, T, P, PhantomData<C>>;
   |          ^^^^^^^^^^^^^^ -  -  -  -
   = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add missing generic arguments
   |
38 | }, P, C
   |  ++++++
sol! {
    #[sol(rpc)]
    contract LogMessageToL2 {
        #[derive(Debug, PartialEq)]
        event LogMessageToL2Event(address indexed, uint256 indexed, uint256 indexed, uint256[], uint256, uint256);
    }
}

and then calling with something like

 let event: Event<_, _, _, LogMessageToL2::LogMessageToL2Event> =
    Event::new(self.provider.into(), Filter::new());
let poller = event.watch().await.map_err(|e| {
    error!(target: LOG_TARGET, "Log parsing failed {e}");
    Error::GatherError
})?;

let mut parsed_log = poller.into_stream();

Resulting in the same error:

error[E0107]: missing generics for trait `alloy_provider::Provider`
   --> crates/katana/core/src/service/messaging/ethereum.rs:53:1
    |
53  | / sol! {
54  | |     #[sol(rpc)]
55  | |     contract LogMessageToL2 {
56  | |         #[derive(Debug, PartialEq)]
57  | |         event LogMessageToL2Event(address indexed, uint256 indexed, uint256 indexed, uint256[], uint256, uint256);
58  | |     }
59  | | }
    | |_^ expected at least 1 generic argument
    |
note: trait defined here, with at least 1 generic parameter: `N`
   --> /Users/tcoratger/.cargo/git/checkouts/alloy-805bdb2c8d2cb5fa/410850b/crates/provider/src/provider.rs:178:11
    |
178 | pub trait Provider<N: Network, T: Transport + Clone = BoxTransport>: Send + Sync {
    |           ^^^^^^^^ -
    = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add missing generic argument
    |
59  | }<N>
    |  +++

error[E0107]: type alias takes 4 generic arguments but 2 generic arguments were supplied
  --> crates/katana/core/src/service/messaging/ethereum.rs:53:1
   |
53 | / sol! {
54 | |     #[sol(rpc)]
55 | |     contract LogMessageToL2 {
56 | |         #[derive(Debug, PartialEq)]
57 | |         event LogMessageToL2Event(address indexed, uint256 indexed, uint256 indexed, uint256[], uint256, uint256);
58 | |     }
59 | | }
   | | ^
   | | |
   | |_expected 4 generic arguments
   |   supplied 2 generic arguments
   |
note: type alias defined here, with 4 generic parameters: `N`, `T`, `P`, `C`
  --> /Users/tcoratger/.cargo/git/checkouts/alloy-805bdb2c8d2cb5fa/410850b/crates/contract/src/call.rs:18:10
   |
18 | pub type SolCallBuilder<N, T, P, C> = CallBuilder<N, T, P, PhantomData<C>>;
   |          ^^^^^^^^^^^^^^ -  -  -  -
   = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add missing generic arguments
   |
59 | }, P, C
   |  ++++++

Is there something I didn't do right or is there something I need to fix in the repo? I did not find a perfectly equivalent example in the repo for the macro with the ABI but it seems to me that the second use case takes exactly the example found in the unit tests.

mattsse commented 3 months ago

@DaniPopes could this be an issue with outdated sol(rpc) expansion?

DaniPopes commented 3 months ago

This is fixed on main. As noted in the documentation, sol(rpc) and alloy-rs/alloy/alloy-contract are incomplete and unstable. You have to patch all alloy-core to latest git: https://github.com/alloy-rs/alloy/blob/f9c90dececc991486eb483f3f9398bb2714fb8a0/Cargo.toml#L109-L117