I use rust for programming and want to provide a method in canister to query canister’s own wasm data. What should I do?
This is a bit tricky: To include the wasm in the wasm would require a Quine, which might be a fun puzzle, but isn’t really practical.
Note that anyone get get the hash of your wasm code from the Internet Computer in a certified way (e.g. using dfx canister info
). So the pragmatic solution would be to store a copy of the wasm elsewhere (another canister, which could be a simple asset canister, or simply on your project’s webpage), and link to it.
By comparing the hash of the downloaded canister with the hash as provided by the Internet Computer (or shown on rocks.ic etc.), people can know for sure that the wasm is the one that’s deployed.
But, allow me to ask what your goal is?
I provide a query method in A canister to return the byte array of the built-in wasm file, such as vec. In B canister, through the cross-canister call, get the wasm file and deploy the new canister.
However, because of the size (2M) limit of canister deployment, the above method is not easy to implement.
Now expect another way, such as B canister to provide a storage method to hold the byte array of the wasm file. Subsequent to get the wasm byte array directly from the memory. For example, the wallet_store_wallet_wasm method in cycles wallet.
The question now becomes, how do I pass this parameter?
@jzxchiang Do you know how to solve this problem please? Appreciate it
Sorry, I don’t understand the problem. Why can’t you pass the parameter? FWIW, I’m also not an expert with the Rust CDK by any means…
Sorry my description was not very clear. I found a solution from motoko-cdn: format the buffer of the file and convert it into an array of u8.