Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load contract bytes at runtime in deploy_native_contracts #267

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

noot
Copy link

@noot noot commented Mar 31, 2024

using the drk crate as a dep in an external repo led to these compilation errors:

error: couldn't read `/home/e/.cargo/git/checkouts/darkfi-a258e322f5e79994/bfcd383/src/validator/../contract/money/darkfi_money_contract.wasm`: No such file or directory (os error 2)
  --> /home/e/.cargo/git/checkouts/darkfi-a258e322f5e79994/bfcd383/src/validator/utils.rs:57:13
   |
57 |             include_bytes!("../contract/money/darkfi_money_contract.wasm").to_vec(),
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read `/home/e/.cargo/git/checkouts/darkfi-a258e322f5e79994/bfcd383/src/validator/../contract/dao/darkfi_dao_contract.wasm`: No such file or directory (os error 2)
  --> /home/e/.cargo/git/checkouts/darkfi-a258e322f5e79994/bfcd383/src/validator/utils.rs:63:13
   |
63 |             include_bytes!("../contract/dao/darkfi_dao_contract.wasm").to_vec(),
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read `/home/e/.cargo/git/checkouts/darkfi-a258e322f5e79994/bfcd383/src/validator/../contract/deployooor/darkfi_deployooor_contract.wasm`: No such file or directory (os error 2)
  --> /home/e/.cargo/git/checkouts/darkfi-a258e322f5e79994/bfcd383/src/validator/utils.rs:69:13
   |
69 |             include_bytes!("../contract/deployooor/darkfi_deployooor_contract.wasm").to_vec(),
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

the relative path used in include_bytes turned into /src/validator/../contract/money/darkfi_money_contract.wasm when darkfi is used as a lib, which is not a valid path.

this PR fixes the issue by loading the wasm bytes at runtime, using CARGO_MANIFEST_DIR to get a nonrelative path.

this was tested using a patch as follows + make clippy:

[patch."https://github.com/darkrenaissance/darkfi"]
darkfi = { git = "https://github.com/noot/darkfi", branch = "fix-include-bytes" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant