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).