简体   繁体   中英

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

New to elrond contracts.

I am trying to figure what is the absolute minimum to get an elrond rust contract to successfully build when doing erdpy contract build .

To me, the contract would only be src/lib.rs .

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

The meta/src/main.rs file has:

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:

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. First you'r trait from your src is getting compiled. Then the meta subproject is getting invoked to generate your abi file and the sourcecode of the wasm subproject. Then the wasm subproject is compiled to actually get your wasm file.

By deleting the wasm subproject you have therefore destroyed that last compilation step and have not received a wasm file. 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.

So all of these are absolutely necessary and you can only safely delete the cargo.lock, the output and the target folder:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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