Search code examples
rustenumsrpcnearprotocol

How to fix "expected enum QueryRequest, found enum QueryRequest" when using near-json-rpc and near-primitives?


I am trying to use near-json-rpc and when I build the RpcQueryRequest I get the following errors related to the near-primitives types:

expected enum near_primitives::types::BlockReference, found enum BlockReference
expected enum near_primitives::views::QueryRequest, found enum QueryRequest

The BlockReference and QueryRequest enums are imported. Here is the code that builds the request:

use near_primitives::types::Finality::DoomSlug;
use near_primitives::types::BlockReference::Finality;
use near_primitives::views::QueryRequest::ViewAccount;

...

let request = ViewAccount {
    account_id: "address.near".parse().unwrap()
};

let block_reference = Finality(DoomSlug);

let status_request = RpcQueryRequest {
    block_reference,
    request
};

The errors are generated in the last 3 lines when creating status_request, using the block_reference and request variables.

Here are my dependencies inside Cargo.toml:

[dependencies]
near-jsonrpc-client = "0.3.0"
futures = "0.3.24"
tokio = { version = "1.21.1", features = ["full"] }
near-primitives = "0.15.0"

Any ideas about how to fix this?


Solution

  • You are using near-primitives version 0.15, but near-jsonrpc-client version 0.3 depends on near-primitives version 0.12. Those two are incompatible so using one version's types in place of another won't work.

    You should downgrade your dependency on near-primitives to match:

    near-primitives = "0.12.0"