我知道链上有一个移动模块(智能契约),其功能如下所示:
public entry fun do_nothing() {}我知道它部署在6286dfd5e2778ec069d5906cd774efdba93ab2bec71550fa69363482fbd814e7::other::do_nothing,您可以在资源管理器这里中看到模块。
我有一个自己的移动模块,看起来像这样。
Move.toml
[package]
name = 'mine'
version = '1.0.0'
[dependencies.AptosFramework]
git = 'https://github.com/aptos-labs/aptos-core.git'
rev = 'main'
subdir = 'aptos-move/framework/aptos-framework'
[addresses]
my_addr = "81e2e2499407693c81fe65c86405ca70df529438339d9da7a6fc2520142b591e"
other_addr = "6286dfd5e2778ec069d5906cd774efdba93ab2bec71550fa69363482fbd814e7"sources/mine.move
module my_addr::mine {
use other_addr::other::do_nothing;
public entry fun do_stuff() {
do_nothing();
}
}正如您所看到的,我通过设置other模块来告诉编译器other_addr = "6286dfd5e2778ec069d5906cd774efdba93ab2bec71550fa69363482fbd814e7"模块在哪里。然而,当我试图编译我的移动模块时,它失败了,它说"unbound模块“,这意味着它不知道什么是”其他“模块。
$ aptos move compile --named-addresses my_addr="`yq .profiles.default.account < .aptos/config.yaml`"
Compiling, may take a little while to download git dependencies...
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING mine
error[E03002]: unbound module
┌─ /Users/dport/github/move-examples/call_other_module/mine/sources/mine.move:2:9
│
2 │ use other_addr::other::do_nothing;
│ ^^^^^^^^^^^^^^^^^ Invalid 'use'. Unbound module: '(other_addr=0x6286DFD5E2778EC069D5906CD774EFDBA93AB2BEC71550FA69363482FBD814E7)::other'
error[E03005]: unbound unscoped name
┌─ /Users/dport/github/move-examples/call_other_module/mine/sources/mine.move:5:9
│
5 │ do_nothing();
│ ^^^^^^^^^^ Unbound function 'do_nothing' in current scope
{
"Error": "Move compilation failed: Compilation error"
}为什么编译失败?为什么编译器不能根据它在other_addr on chain上找到的Move模块的ABI来计算它呢?
发布于 2022-12-01 10:36:46
问题所在
为了发布一个在另一个移动模块中调用函数的移动模块,您需要它的源代码。这对所有移动模块都是正确的,而不仅仅是您自己的。您会注意到,在Move.toml中,已经存在对AptosFramework的依赖。这允许您调用所有框架函数,例如与硬币、令牌、签名者、时间戳等相关的函数。
因此,要使这一工作,您需要有访问源代码。
资料来源: Git依赖关系。
如果您可以访问另一个git存储库中的源代码,则可以通过将其添加到other中来告诉编译器在哪里找到Move.toml模块:
[dependencies.other]
git = 'https://github.com/banool/move-examples.git'
rev = 'main'
subdir = 'call_other_module/other'这告诉编译器,“other的源代码可以在git的call_other_module/other/目录中找到”。
资料来源:当地
如果本地有源代码,则可以这样做:
[dependencies.other]
local = "../other"其中local的参数是指向源代码的路径。
资料来源:我没有?
如果你没有源代码,你可以尝试下载它。默认情况下,当某人发布移动模块时,它们会在它旁边包含源代码。
首先,尝试下载代码:
cd /tmp
aptos move download --account 6286dfd5e2778ec069d5906cd774efdba93ab2bec71550fa69363482fbd814e7 --package other如果源代码确实部署在链上,您应该会看到以下内容:
Saved package with 1 module(s) to `/tmp/other`
{
"Result": "Download succeeded"
}在/tmp/other中,您可以找到完整的源代码,包括Move.toml和sources/。
从这里开始,您只需按照上面的Source: Local步骤操作即可。
备注:--package的值应该与部署代码的Move.toml中的name字段相匹配。接下来更多的是如何根据链数据来确定这一点.
资料来源:下载失败?
如果您运行aptos move download并看到以下内容:
module without code: other
Saved package with 1 module(s) to `/private/tmp/other_code/other`
{
"Result": "Download succeeded"
}您会发现sources/other.move是空的。
这意味着作者用这个CLI参数集发布了代码:
--included-artifacts none意思是他们故意不把源头包括在链子上。
不幸的是你现在运气不好。编译的一个困难要求是,如果要在另一个移动模块中调用函数,则必须拥有该模块的源代码。正在进行的工作应该支持移动字节码的反编译,但这还没有准备好。
希望这有帮助,快乐编码!
在这个答案中使用的代码可以在这里找到:模块。
https://stackoverflow.com/questions/74640493
复制相似问题