0

Updating to new version of substrate, of the branch = "polkadot-v0.9.42", it giving error,

impl<C, Block, AccountId> ProfileValidationApi<<Block as BlockT>::Hash, AccountId> for ProfileValidation<C, Block>
where
    Block: BlockT,
    AccountId: Codec,
    C: Send + Sync + 'static,
    C: ProvideRuntimeApi<Block>,
    C: HeaderBackend<Block>,
    C::Api: ProfileValidationRuntimeApi<Block, AccountId>,
{
    fn get_challengers_evidence(
        &self,
        profile_user_account: AccountId,
        offset: u64,
        limit: u16,
        at: Option<<Block as BlockT>::Hash>,
    ) -> Result<Vec<ChallengePostId>> {
        let api = self.client.runtime_api();
        let at = BlockId::hash(at.unwrap_or_else(||
            // If the block hash is not supplied assume the best block.
            self.client.info().best_hash));

        let runtime_api_result =
            api.get_challengers_evidence(&at, profile_user_account, offset, limit);
        runtime_api_result.map_err(|e| RpcError {
            code: ErrorCode::ServerError(9876), // No real reason for this value
            message: "Something wrong".into(),
            data: Some(format!("{:?}", e).into()),
        })
    }

The error:


error[E0308]: mismatched types
   --> pallets/profile-validation/profile-validation-rpc/src/lib.rs:90:33
    |
90  |             api.get_challengers_evidence(&at, profile_user_account, offset, limit);
    |                 ------------------------ ^^^ expected associated type, found `&BlockId<_>`
    |                 |
    |                 arguments to this method are incorrect
    |                 here the type of `api` is inferred to be `<C as ProvideRuntimeApi<Block>>::Api`
    |
    = note: expected associated type `<Block as sp_api::BlockT>::Hash`
                     found reference `&BlockId<_>`
help: a method is available that returns `<Block as sp_api::BlockT>::Hash`
   --> /home/amiya/.cargo/git/checkouts/substrate-7e08433d4c370a21/ff24c60/primitives/runtime/src/traits.rs:951:2
    |
951 |     fn hash(&self) -> Self::Hash {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ consider calling `sp_api::BlockT::hash`
note: method defined here
   --> /home/amiya/Documents/workspace/shivarthu/working_directory/substrate-node-template/pallets/profile-validation/profile-validation-runtime-api/src/lib.rs:11:6
    |
11  |         fn get_challengers_evidence(profile_user_account: AccountId, offset: u64, limit: u16) -> Vec<ChallengePostId>;
    |            ^^^^^^^^^^^^^^^^^^^^^^^^

1 Answer 1

1

New example code is present in transaction-payment rpc that uses jsonrpsee

https://github.com/paritytech/substrate/blob/master/frame/transaction-payment/rpc/src/lib.rs

impl<C, Block, AccountId> ProfileValidationApiServer<<Block as BlockT>::Hash, AccountId> for ProfileValidation<C, Block>
where
    Block: BlockT,
    AccountId: Codec,
    C: Send + Sync + 'static,
    C: ProvideRuntimeApi<Block>,
    C: HeaderBackend<Block>,
    C::Api: ProfileValidationRuntimeApi<Block, AccountId>,
{
    fn get_challengers_evidence(
        &self,
        profile_user_account: AccountId,
        offset: u64,
        limit: u16,
        at: Option<Block::Hash>,
    ) -> RpcResult<Vec<ChallengePostId>> {
        let api = self.client.runtime_api();
        let at = at.unwrap_or_else(||
            // If the block hash is not supplied assume the best block.
            self.client.info().best_hash);

        let runtime_api_result =
            api.get_challengers_evidence(at, profile_user_account, offset, limit);
            fn map_err(error: impl ToString, desc: &'static str) -> CallError {
                CallError::Custom(ErrorObject::owned(
                    Error::RuntimeError.into(),
                    desc,
                    Some(error.to_string()),
                ))
            }
            let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
            Ok(res)
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.