Code injection: new code injection for directly using `CREATE_CONTRACT` + `of_file`
Motivation and Context
Currently, a contract can be created from a .tz
file by using of_file
in addition to a Michelson injection (or a Michelson injection and the usage of #include
).
However, this usage is still complex for users.
Description
This MR tries a simpler approach for the user, by creating a new code injection environment that does the work for the user.
As a side-effect, we add error handling for of_file
, which was missing, and a test case for it.
Component
-
compiler -
website -
webide -
vscode-plugin -
debugger
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
A new code injection is available for calling CREATE_CONTRACT
of a .tz
file.
In CameLIGO, [%create_contract_of_file "file.tz"]
will be expanded to a function of type key_hash option -> tez -> 's -> operation * address
. It can be used as follows:
[@entry]
let main (u : unit) (_ : unit) : operation list * unit =
let op, _addr = [%create_contract_of_file "./interpreter_tests/contract_under_test/compiled.tz"] None 1tez u in
[op], ()
In JsLIGO, (create_contract_of_file `file.tz`)
will be expanded to a function of type <s>(k: option<key_hash>, t: tez, s:storage) => [operation, address]
. It can be used as follows:
@entry
const main = (u : unit, _ : unit) : [list<operation>, unit] => {
let [op, _addr] = (create_contract_of_file `./interpreter_tests/contract_under_test/compiled.tz`)(None(), 1tez, u);
return [list([op]), []]
}
Notice that the parameter passed for storage must have a type that compiles to the type expected as storage of the contract in the .tz
file. In case of a mismatch, a type error will be present when typing the resulting Michelson contract. In the examples above, the contract's storage type is unit
, and the argument passed as storage to the function (u
) has that type.
Checklist:
-
If a new syntax has been introduced, put a message on slack ligo-lsp -
Changes follow the existing coding style (use dune @fmt
to check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Start titles under ## Changelog
section with #### (if appropriate). -
There is no image or uploaded file in changelog -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Merge request reports
Activity
assigned to @er433
mentioned in commit 8d750b25
added 4 commits
-
dc985600...2b3a3b07 - 2 commits from branch
dev
- 8d750b25 - Merge branch 'er433/codeinj/create_contract_of_file' into 'dev'
- bca3f55b - [Bot] add changelog entry
-
dc985600...2b3a3b07 - 2 commits from branch
A new deploy preview is available on Netlify at https://2860-eb1bb9a5--ligolang.netlify.app, you can view the logs at https://app.netlify.com/sites/ligolang/deploys/650447d501362f1491cdc265
Edited by Ligo Langadded 13 commits
-
bca3f55b...84c28ceb - 2 commits from branch
dev
- 69a4a295 - 1 earlier commit
- d6394d3b - feat: extend of_file with create_contract_of_file
- 36f31d72 - fix: give some rule about (/\v.u){t} |-> u[v/t] in monomorphisation
- c3111212 - test: add JsLIGO test file
- efaf0d03 - test: add test case to JsLIGO
- aa0ba4d2 - test: add CameLIGO test file
- ab614bf2 - test: add test case to CameLIGO
- a23128c9 - test: add negative test files
- abe92c81 - test: add negative test cases
- 4690f205 - style: apply dune fmt
- 8212ac16 - [Bot] add changelog entry
Toggle commit list-
bca3f55b...84c28ceb - 2 commits from branch
- Resolved by Rémi
- Resolved by E. Rivas
added 11 commits
-
280273dd...d74871a0 - 10 commits from branch
dev
- 9fd183cf - Merge branch 'dev' into er433/codeinj/create_contract_of_file
-
280273dd...d74871a0 - 10 commits from branch
added 11 commits
-
9fd183cf...521e875b - 10 commits from branch
dev
- e370ccc9 - Merge branch 'dev' into er433/codeinj/create_contract_of_file
-
9fd183cf...521e875b - 10 commits from branch
enabled automatic add to merge train when the pipeline for 96f827c0 succeeds
mentioned in commit db2d4351
unassigned @er433