LEVI_104
LEVI_104

Reputation: 11

Rust dependency inconsistency: The versions on crates.io and GitHub match, but the code fails to compile

I have a dependency in cargo.toml.:

alloy-dyn-abi = { version = "=0.8.22", default-features = false }

Its cargo.lock is:

name = "alloy-dyn-abi"
version = "0.8.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00e08c581811006021970bf07f2ecf3213f6237c125f7fd99607004b23627b61"

The original repository for this dependency is: https://github.com/alloy-rs/core/tree/main

So I want to use dependencies like this:

alloy-dyn-abi = { git = "https://github.com/alloy-rs/core.git", tag = "v0.8.22", default-features = false }

However, the compilation reported errors, indicating that some libraries are incompatible, suggesting version inconsistencies. log:

error[E0277]: the trait bound `alloy_json_abi::Function: FunctionExt` is not satisfied
   --> crates/contract/src/eth_call.rs:196:40
    |
196 |         FunctionExt::abi_decode_output(self, &data, validate)
    |         ------------------------------ ^^^^ the trait `FunctionExt` is not implemented for `alloy_json_abi::Function`
    |         |
    |         required by a bound introduced by this call
    |
    = help: the trait `FunctionExt` is implemented for `alloy_json_abi::item::Function`

error[E0277]: the trait bound `alloy_dyn_abi::Error: From<alloy_sol_types::Error>` is not satisfied
   --> crates/contract/src/eth_call.rs:212:63
    |
212 |             .map_err(|e| Error::decode(C::SIGNATURE, &data, e.into()))
    |                                                               ^^^^ the trait `From<alloy_sol_types::Error>` is not implemented for `alloy_dyn_abi::Error`
    |
    = help: the following other types implement trait `From<T>`:
              `alloy_dyn_abi::Error` implements `From<TryReserveError>`
              `alloy_dyn_abi::Error` implements `From<alloy_dyn_abi::alloy_sol_type_parser::Error>`
              `alloy_dyn_abi::Error` implements `From<alloy_primitives::const_hex::FromHexError>`
              `alloy_dyn_abi::Error` implements `From<alloy_sol_types::errors::Error>`
    = note: required for `alloy_sol_types::Error` to implement `Into<alloy_dyn_abi::Error>`

error[E0277]: the trait bound `alloy_dyn_abi::Error: From<alloy_sol_types::Error>` is not satisfied
  --> crates/contract/src/error.rs:43:26
   |
43 |         Self::AbiError(e.into())
   |                          ^^^^ the trait `From<alloy_sol_types::Error>` is not implemented for `alloy_dyn_abi::Error`
   |
   = help: the following other types implement trait `From<T>`:
             `alloy_dyn_abi::Error` implements `From<TryReserveError>`
             `alloy_dyn_abi::Error` implements `From<alloy_dyn_abi::alloy_sol_type_parser::Error>`
             `alloy_dyn_abi::Error` implements `From<alloy_primitives::const_hex::FromHexError>`
             `alloy_dyn_abi::Error` implements `From<alloy_sol_types::errors::Error>`
   = note: required for `alloy_sol_types::Error` to implement `Into<alloy_dyn_abi::Error>`

error[E0599]: no method named `abi_encode_input` found for reference `&alloy_json_abi::Function` in the current scope
   --> crates/contract/src/interface.rs:33:35
    |
33  |         self.get_from_name(name)?.abi_encode_input(args).map_err(Into::into)
    |                                   ^^^^^^^^^^^^^^^^
    |
help: there is a method `abi_decode_output` with a similar name, but with different arguments
   --> crates/contract/src/eth_call.rs:185:5
    |
185 |     fn abi_decode_output(&self, data: Bytes, validate: bool) -> Result<Self::CallOutput>;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0599]: no method named `abi_encode_input` found for reference `&alloy_json_abi::Function` in the current scope
   --> crates/contract/src/interface.rs:43:43
    |
43  |         self.get_from_selector(selector)?.abi_encode_input(args).map_err(Into::into)
    |                                           ^^^^^^^^^^^^^^^^
    |
help: there is a method `abi_decode_output` with a similar name, but with different arguments
   --> crates/contract/src/eth_call.rs:185:5
    |
185 |     fn abi_decode_output(&self, data: Bytes, validate: bool) -> Result<Self::CallOutput>;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0599]: no method named `abi_decode_input` found for reference `&alloy_json_abi::Function` in the current scope
  --> crates/contract/src/interface.rs:58:35
   |
58 |         self.get_from_name(name)?.abi_decode_input(data, validate).map_err(Into::into)
   |                                   ^^^^^^^^^^^^^^^^
   |
help: there is a method `abi_decode_output` with a similar name
   |
58 -         self.get_from_name(name)?.abi_decode_input(data, validate).map_err(Into::into)
58 +         self.get_from_name(name)?.abi_decode_output(data, validate).map_err(Into::into)
   |

error[E0599]: no method named `abi_decode_input` found for reference `&alloy_json_abi::Function` in the current scope
  --> crates/contract/src/interface.rs:68:43
   |
68 |         self.get_from_selector(selector)?.abi_decode_input(data, validate).map_err(Into::into)
   |                                           ^^^^^^^^^^^^^^^^
   |
help: there is a method `abi_decode_output` with a similar name
   |
68 -         self.get_from_selector(selector)?.abi_decode_input(data, validate).map_err(Into::into)
68 +         self.get_from_selector(selector)?.abi_decode_output(data, validate).map_err(Into::into)
   |

error[E0599]: no method named `abi_decode_output` found for reference `&alloy_json_abi::Function` in the current scope
  --> crates/contract/src/interface.rs:84:35
   |
84 |         self.get_from_name(name)?.abi_decode_output(data, validate).map_err(Into::into)
   |                                   ^^^^^^^^^^^^^^^^^ method not found in `&Function`
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `CallDecoder` which provides `abi_decode_output` is implemented but not in scope; perhaps you want to import it
   |
1  + use crate::eth_call::CallDecoder;
   |

error[E0599]: no method named `abi_decode_output` found for reference `&alloy_json_abi::Function` in the current scope
  --> crates/contract/src/interface.rs:94:43
   |
94 |         self.get_from_selector(selector)?.abi_decode_output(data, validate).map_err(Into::into)
   |                                           ^^^^^^^^^^^^^^^^^ method not found in `&Function`
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `CallDecoder` which provides `abi_decode_output` is implemented but not in scope; perhaps you want to import it
   |
1  + use crate::eth_call::CallDecoder;
   |

error[E0599]: no method named `abi_encode_input` found for reference `&alloy_json_abi::Function` in the current scope
   --> crates/contract/src/call.rs:156:22
    |
156 |             function.abi_encode_input(args)?.into(),
    |                      ^^^^^^^^^^^^^^^^
    |
help: there is a method `abi_decode_output` with a similar name, but with different arguments
   --> crates/contract/src/eth_call.rs:185:5
    |
185 |     fn abi_decode_output(&self, data: Bytes, validate: bool) -> Result<Self::CallOutput>;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `alloy-contract` (lib) due to 10 previous errors

Here is its cargo.lock:

name = "alloy-dyn-abi"
version = "0.8.22"
source = "git+https://github.com/alloy-rs/core.git?tag=v0.8.22#2531372340397cccc7894d3b3578505f4da78b0d"

How should I use the GitHub approach instead of the one on crates.io? Specifically, how can I find the corresponding version of a crate on GitHub?

This is a standardized project, so the version on GitHub should match the one on the crate, right?

Upvotes: 0

Views: 58

Answers (2)

LEVI_104
LEVI_104

Reputation: 11

you want to do it in [patch.crates-io] section since what you're doing doesn't change transitive dependencies to alloy core

So I fix it by adding new content but not replace them:

[patch.crates-io]
alloy-core = { git = "https://github.com/alloy-rs/core.git", tag = "v0.8.22" }
alloy-dyn-abi = { git = "https://github.com/alloy-rs/core.git", tag = "v0.8.22" }
alloy-json-abi = { git = "https://github.com/alloy-rs/core.git", tag = "v0.8.22" }
alloy-primitives = { git = "https://github.com/alloy-rs/core.git", tag = "v0.8.22" }
alloy-sol-types = { git = "https://github.com/alloy-rs/core.git", tag = "v0.8.22" }

Upvotes: 1

birch
birch

Reputation: 1

Ensure that the tags of related dependencies are consistent

Upvotes: -1

Related Questions