我有两个非常基本rust-ink
的 dapp 合约:
应用程序 1
#![cfg_attr(not(feature = "std"), no_std)]
use ink_lang as ink;
use dapp2;
#[ink::contract]
pub mod dapp1 {
use dapp2::dapp2::Dapp2;
#[ink(storage)]
pub struct Dapp1 {
dapp2_instance: Dapp2
}
impl Dapp1 {
/// Get existing `Dapp2` contract at `address`
#[ink(constructor)]
pub fn new(address: AccountId) -> Self {
let dapp2_instance: Dapp2 = ink_env::call::FromAccountId::from_account_id(address);
Self {
dapp2_instance
}
}
/// Calls the Dapp2 contract.
#[ink(message)]
pub fn dapp2_do_something(&mut self) -> u8 {
self.dapp2_instance.do_something()
}
}
}
Dapp 1 将 dapp2 指定为toml
:
dapp2 = { version = "3.0.0-rc7", path ="../dapp2", default-features = false, features = ["ink-as-dependency"] }
应用程序 2
#![cfg_attr(not(feature = "std"), no_std)]
use ink_lang as ink;
#[ink::contract]
pub mod dapp2 {
#[ink(storage)]
pub struct Dapp2 {
pub what: u8,
}
impl Dapp2 {
#[ink(constructor)]
pub fn new() -> Self {
let what = 2.into();
Self {
what
}
}
#[ink(message)]
pub fn do_something(&mut self) -> u8 {
ink_env::debug_println!("{}", self.what);
self.what
}
}
}
当我运行这个构建时,dapp2
编译但dapp1
失败了
error[E0432]: unresolved import `dapp2`
--> /home/usr/dev/dapp-example/dapp1/lib.rs:4:5
|
4 | use dapp2;
| ^^^^^ no external crate `dapp2`
甚至我的 IDE 在单击时也能找到dapp2
,那么这种导入样式有什么问题?
我已经看到了其他示例(1、2、3),其中合同只是导入到模块中,但这似乎对我不起作用。如果我这样做,我会得到:
7 | use dapp2::Dapp2Ref;
| ^^^^^ use of undeclared crate or module `dapp2`
墨水设置为master
分支。Rust nightly 是最新的。版本是2021。示例代码在github上