Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

rpc: the arguments for api method are incorrect #14728

Open
2 tasks done
Snikko opened this issue Aug 8, 2023 · 7 comments
Open
2 tasks done

rpc: the arguments for api method are incorrect #14728

Snikko opened this issue Aug 8, 2023 · 7 comments
Labels
J2-unconfirmed Issue might be valid, but it’s not yet known.

Comments

@Snikko
Copy link

Snikko commented Aug 8, 2023

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Description of bug

I want to add rpc function in my substrate blockchain to supply restful apis for others.But some mistake occur when the project is built.The errors show like this:

45 | api.get_value(&at,v).map_err(runtime_error_into_rpc_err)
| --------- ^^^ expected associated type, found &BlockId<_>
| |
| arguments to this method are incorrect

1691463385285

Steps to reproduce

1、add rpc configuration to the prject correctly
2、build the project
3、errors like this:

45 | api.get_value(&at,v).map_err(runtime_error_into_rpc_err)
| --------- ^^^ expected associated type, found &BlockId<_>
| |
| arguments to this method are incorrect

@github-actions github-actions bot added the J2-unconfirmed Issue might be valid, but it’s not yet known. label Aug 8, 2023
@ggwpez
Copy link
Member

ggwpez commented Aug 8, 2023

Did you follow some tutorial or how did you add it to the template?
Where did you get the code from?

@Snikko
Copy link
Author

Snikko commented Aug 8, 2023

Did you follow some tutorial or how did you add it to the template? Where did you get the code from?

yeah,I followed some tutorials to add it to my template,sunch as https://substrate.stackexchange.com/questions/5554/how-to-add-custom-rpcs and https://github.com/AlexD10S/susbtrate-node-template/blob/rpc-custom-methods/pallets/template/rpc/src/lib.rs#L9 and others. I compared the codes among them and found that they did the same thing.But ,when I added the codes in my project, errors occured like that when it is built.So,maybe,I think wether the newest codes causing the problem,I am not sure.

@ggwpez
Copy link
Member

ggwpez commented Aug 8, 2023

@AlexD10S do you know if the tutorial maybe needs an update?

@Snikko
Copy link
Author

Snikko commented Aug 9, 2023

@AlexD10S do you know if the tutorial maybe needs an update?
yeah,I know.I download the newest version of substrate-node-template and add the rpc configuration to it following the tutorial,changing the version to the newest in the file Cargo.toml of rpc.The version is v1.0.0.(branch = "polkadot-v1.0.0")


error[E0308]: mismatched types
--> pallets/template/src/rpc/src/lib.rs:45:23
|
45 | api.get_value(&at,v).map_err(runtime_error_into_rpc_err)
| --------- ^^^ expected associated type, found &BlockId<_>
| |
| arguments to this method are incorrect
|
= note: expected associated type <Block as BlockT>::Hash
found reference &BlockId<_>
help: a method is available that returns <Block as BlockT>::Hash
--> /root/.cargo/git/checkouts/substrate-7e08433d4c370a21/948fbd2/primitives/runtime/src/traits.rs:1274:2
|
1274 | fn hash(&self) -> Self::Hash {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ consider calling sp_api::BlockT::hash
note: method defined here
--> /home/nikko/substrate-node-template/pallets/template/src/rpc/runtime-api/src/lib.rs:7:12
|
7 | fn get_value(v: u32) -> bool;
| ^^^^^^^^^

For more information about this error, try rustc --explain E0308.


1691546791033

@Snikko
Copy link
Author

Snikko commented Aug 9, 2023

@AlexD10S do you know if the tutorial maybe needs an update?

I have found the answer.Thanks.

@AlexD10S
Copy link
Contributor

AlexD10S commented Aug 9, 2023

I am going to take a look, probably it needs an update. The tutorial was done with polkadot-v0.9.28.

@Snikko If you have found an answer, can you share your solution here or in the StackExchange question with a new answer or editing mine. The community will benefit if you share your solution there.

@Snikko
Copy link
Author

Snikko commented Aug 18, 2023

I am going to take a look, probably it needs an update. The tutorial was done with polkadot-v0.9.28.

@Snikko If you have found an answer, can you share your solution here or in the StackExchange question with a new answer or editing mine. The community will benefit if you share your solution there.

In recent versions,we have to change some codes in the file pallets/template/src/rpc/src/lib.rs,as follows:

impl<C, Block> TemplateApiServer<::Hash> for TemplatePallet<C, Block>
where
Block: BlockT,
C: Send + Sync + 'static + ProvideRuntimeApi + HeaderBackend,
C::Api: TemplateRuntimeApi,
{
fn get_value(&self, at: Option<::Hash>) -> RpcResult

{
    let api = self.client.runtime_api();
    let at = at.unwrap_or_else(||self.client.info().best_hash);

    api.get_value(at).map_err(runtime_error_into_rpc_err)
}

}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J2-unconfirmed Issue might be valid, but it’s not yet known.
Projects
None yet
Development

No branches or pull requests

3 participants