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

fix(proc-macros): make feature server-core compile #1360

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Apr 29, 2024

Similar to #1359 and kudos to @koushiro for detecting this but I prefer not re-export tokio

@niklasad1 niklasad1 requested a review from a team as a code owner April 29, 2024 07:53
@niklasad1 niklasad1 changed the title fix(proc-macros): feature server-core fix(proc-macros): make feature server-core compile Apr 29, 2024
@koushiro
Copy link
Contributor

But there are already some reexports in the existing code, such as

let serde = self.jrps_server_item(quote! { core::__reexports::serde });
and
let async_trait = self.jrps_client_item(quote! { core::__reexports::async_trait });

@niklasad1
Copy link
Member Author

Yes you are correct but we have a couple of re-exports there but these should be as few a possible IMO.

@niklasad1 niklasad1 merged commit b2ed47b into master Apr 29, 2024
11 checks passed
@niklasad1 niklasad1 deleted the na-rexport-core-only branch April 29, 2024 08:26
@koushiro
Copy link
Contributor

@niklasad1 There is still a problem when using the subscription attribute

error[E0433]: failed to resolve: could not find `tokio` in `jsonrpsee`
  --> client/rpc/api/src/eth/pubsub.rs:28:1
   |
28 | #[rpc(client, server, namespace = "eth")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `tokio` in `jsonrpsee`
   |
note: found an item that was configured out
  --> /Users/qinxuan/Code/jsonrpsee/jsonrpsee/src/lib.rs:81:10
   |
81 |     pub use tokio;
   |             ^^^^^
   = note: the item is gated behind the `server` feature
   = note: this error originates in the attribute macro `rpc` (in Nightly builds, run with -Z macro-backtrace for more info)

@koushiro
Copy link
Contributor

koushiro commented Apr 29, 2024

And I found another issue about the params name when using subscription attribute

[package]
name = "rpc-demo"
version = "0.1.0"
edition = "2021"

[dependencies]
jsonrpsee = { version = "0.22.4", features = ["client-core", "server-core", "macros"] }
serde = { version = "1.0", features = ["derive"] }

[patch.crates-io]
jsonrpsee = { path = "../parity/jsonrpsee/jsonrpsee" }
use jsonrpsee::{core::SubscriptionResult, proc_macros::rpc};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub enum PubSubKind {
    A,
    B,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PubSubParams {
    params: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PubSubItem {
    result: String,
}

#[rpc(client, server, namespace = "foo")]
#[async_trait]
pub trait FooPubSubApi {
   // Error 
    #[subscription(name = "subscribe" => "subscription", unsubscribe = "unsubscribe", item = PubSubItem)]
    async fn sub(&self, kind: PubSubKind, params: Option<PubSubParams>) -> SubscriptionResult;

    // Ok
    // #[subscription(name = "subscribe" => "subscription", unsubscribe = "unsubscribe", item = PubSubItem)]
    // async fn sub(&self, kind: PubSubKind, pubsub_params: Option<PubSubParams>) -> SubscriptionResult;
}

Error:

    Checking rpc-demo v0.1.0 (/Users/qinxuan/Code/rpc-demo)
error[E0433]: failed to resolve: could not find `tokio` in `jsonrpsee`
  --> src/lib.rs:20:1
   |
20 | #[rpc(client, server, namespace = "foo")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `tokio` in `jsonrpsee`
   |
note: found an item that was configured out
  --> /Users/qinxuan/Code/parity/jsonrpsee/jsonrpsee/src/lib.rs:81:10
   |
81 |     pub use tokio;
   |             ^^^^^
   = note: the item is gated behind the `server` feature
   = note: this error originates in the attribute macro `rpc` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `ArrayParams: Serialize` is not satisfied
   --> src/lib.rs:24:40
    |
20  | #[rpc(client, server, namespace = "foo")]
    | ----------------------------------------- required by a bound introduced by this call
...
24  |     async fn sub(&self, kind: PubSubKind, params: Option<PubSubParams>) -> Subscript...
    |                                           ^^^^^^ the trait `Serialize` is not implemented for `ArrayParams`
    |
    = help: the following other types implement trait `Serialize`:
              bool
              char
              isize
              i8
              i16
              i32
              i64
              i128
            and 148 others
note: required by a bound in `ArrayParams::insert`
   --> /Users/qinxuan/Code/parity/jsonrpsee/core/src/params.rs:200:19
    |
200 |     pub fn insert<P: Serialize>(&mut self, value: P) -> Result<(), serde_json::Error> {
    |                      ^^^^^^^^^ required by this bound in `ArrayParams::insert`

Some errors have detailed explanations: E0277, E0433.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `rpc-demo` (lib) due to 2 previous errors

@niklasad1
Copy link
Member Author

You should be unblocked after I merged #1361 but please open issues if something doesn't work

@koushiro
Copy link
Contributor

koushiro commented Apr 29, 2024

@niklasad1 there is still a problem about the parameter name, although I can use other names to avoid this issue.

ParamKind::Array => {
// Throw away the type.
let params = params.iter().map(|(param, _param_type)| param);
quote!({
let mut params = #jsonrpsee::core::params::ArrayParams::new();
#(
if let Err(err) = params.insert( #params ) {
panic!("Parameter `{}` cannot be serialized: {:?}", stringify!( #params ), err);
}
)*
params
})
}

error[E0277]: the trait bound `ArrayParams: Serialize` is not satisfied
   --> src/lib.rs:24:40
    |
20  | #[rpc(client, server, namespace = "foo")]
    | ----------------------------------------- required by a bound introduced by this call
...
24  |     async fn sub(&self, kind: PubSubKind, params: Option<PubSubParams>) -> Subscript...
    |                                           ^^^^^^ the trait `Serialize` is not implemented for `ArrayParams`
    |
    = help: the following other types implement trait `Serialize`:
              bool
              char
              isize
              i8
              i16
              i32
              i64
              i128
            and 148 others
note: required by a bound in `ArrayParams::insert`
   --> /Users/qinxuan/Code/parity/jsonrpsee/core/src/params.rs:200:19
    |
200 |     pub fn insert<P: Serialize>(&mut self, value: P) -> Result<(), serde_json::Error> {
    |                      ^^^^^^^^^ required by this bound in `ArrayParams::insert`

Some errors have detailed explanations: E0277, E0433.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `rpc-demo` (lib) due to 2 previous errors

@niklasad1
Copy link
Member Author

@koushiro I can't reproduce that please open an issue how to reproduce it....

@koushiro
Copy link
Contributor

@koushiro I can't reproduce that please open an issue how to reproduce it....

#1362

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.

None yet

2 participants