简体   繁体   English

为什么一个 elrond rust 合约需要一个 main.rs,以及为什么某个 function 调用它?

[英]Why does an elrond rust contract require a main.rs, and why a certain function call in it?

New to elrond contracts. elrond 合同的新手。

I am trying to figure what is the absolute minimum to get an elrond rust contract to successfully build when doing erdpy contract build .我试图弄清楚在进行erdpy contract build build 时获得 elrond rust 合约以成功构建的绝对最小值是多少。

To me, the contract would only be src/lib.rs .对我来说,合同只会是src/lib.rs

.
├── Cargo.toml
├── meta
│   ├── Cargo.toml
│   └── src
│       └── main.rs
└── src
    └── lib.rs

The meta/src/main.rs file has: meta/src/main.rs文件有:

fn main() {
    println!("hello");
    //elrond_wasm_debug::meta::perform::<crowdfunding::AbiProvider>();
}

If I comment out the elronad_wasm....blah..blah line in meta/src/main.rs , and I remove everything that is generated during a build:如果我注释掉meta/src/main.rs中的elronad_wasm....blah..blah行,并删除构建期间生成的所有内容:

rm -rf $(find . -name Cargo.lock;
         find . -type d -name target;
         find . -type d -name output;
         find . -type d -name wasm);

, then do the build, I get: ,然后进行构建,我得到:

CRITICAL:cli:No file matches pattern [*.wasm].

If I UN-comment that line, re-do all the 'cleaning', and build again, no errors.如果我取消注释该行,请重新执行所有“清理”,然后重新构建,没有错误。

Compiling an elrond contract is a multi-step process.编译 elrond 合约是一个多步骤的过程。 First you'r trait from your src is getting compiled.首先,您的 src 特征正在被编译。 Then the meta subproject is getting invoked to generate your abi file and the sourcecode of the wasm subproject.然后元子项目被调用以生成您的 abi 文件和 wasm 子项目的源代码。 Then the wasm subproject is compiled to actually get your wasm file.然后编译 wasm 子项目以实际获取您的 wasm 文件。

By deleting the wasm subproject you have therefore destroyed that last compilation step and have not received a wasm file.通过删除 wasm 子项目,您因此破坏了最后一个编译步骤并且没有收到 wasm 文件。 And commenting the line in the meta subproject will mean your abi file will no longer be refreshed and you will be missing methods in your compiled wasm.并且在 meta 子项目中注释该行将意味着您的 abi 文件将不再被刷新,并且您将在已编译的 wasm 中丢失方法。

So all of these are absolutely necessary and you can only safely delete the cargo.lock, the output and the target folder:)所以所有这些都是绝对必要的,你只能安全地删除 cargo.lock、output 和目标文件夹:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM