我的Cargo.toml文件中有以下依赖项:
[package]
name = "api-client-tutorial"
version = "0.1.0"
authors = ["Supercomputing Systems AG <info@scs.ch>"]
edition = "2018"
[dependencies]
substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git" }
codec = { package = "parity-scale-codec", features = ["derive"], version = "1.0.0", default-features = false }
[dependencies.primitives]
git = "https://github.com/paritytech/substrate"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "substrate-primitives"
[dependencies.keyring]
git = "https://github.com/paritytech/substrate"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "substrate-keyring"我不确定dependencies节和dependencies.primitives节之间的区别,但是包substrate-primitives包含在原语部分中。
我见过 substrate_primitives有我需要使用的模块sr25519,但是当我试图在代码中导入它时:
use substrate_api_client::{Api, node_metadata};
use substrate_primitives::sr25519;
fn main() {
// instantiate an Api that connects to the given address
let url = "127.0.0.1:9944";
// if no signer is set in the whole program, we need to give to Api a specific type instead of an associated type
// as during compilation the type needs to be defined.
let api = Api::<sr25519::Pair>::new(format!("ws://{}", url));
let meta = api.get_metadata();
println!("Metadata:\n {}", node_metadata::pretty_format(&meta).unwrap());
}我得到以下错误:
unresolved import `substrate_primitives`
use of undeclared type or module `substrate_primitives`rustc(E0432)
main.rs(2, 5): use of undeclared type or module `substrate_primitives`如何导入sr25519,以便在代码中使用以下行?
let api = Api::<sr25519::Pair>::new(format!("ws://{}", url));发布于 2020-03-01 09:49:19
[dependencies]下的表与[dependencies.primitives]表下的表之间的区别是,primitives依赖项的表没有内联。您还可以内联primitives依赖项,并将其放在[dependencies]下,如下所示:
primitives = { git = "https://github.com/paritytech/substrate", rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5", package = "substrate-primitives" }toml文档可以为您提供有关表和内联表的更多详细信息。
关于你的问题。您不能像这样导入机箱,因为它被重命名为primitives。package字段指定依赖项的实名,表名定义用于在项目中导入它的新名称。有关详细信息,请看一下货物单据。
因此,您的导入应该如下所示:use primitives::sr25519;
https://stackoverflow.com/questions/60458851
复制相似问题