Skip to content
Snippets Groups Projects

Code injection: new code injection for directly using `CREATE_CONTRACT` + `of_file`

Merged E. Rivas requested to merge er433/codeinj/create_contract_of_file into dev
All threads resolved!

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).
Edited by E. Rivas

Merge request reports

Merge train pipeline #1006225505 passed with warnings

Merge train pipeline passed with warnings for eb1bb9a5

Merged by E. RivasE. Rivas 1 year ago (Sep 15, 2023 1:50pm UTC)

Loading

Pipeline #1006371936 passed

Pipeline passed for db2d4351 on dev

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Rémi
  • E. Rivas added 1 commit

    added 1 commit

    • 280273dd - refactor: follow Rémi's suggestions

    Compare with previous version

  • E. Rivas added 11 commits

    added 11 commits

    Compare with previous version

  • Rémi approved this merge request

    approved this merge request

  • E. Rivas added 11 commits

    added 11 commits

    Compare with previous version

  • E. Rivas resolved all threads

    resolved all threads

  • E. Rivas enabled automatic add to merge train when the pipeline for 96f827c0 succeeds

    enabled automatic add to merge train when the pipeline for 96f827c0 succeeds

  • E. Rivas added this merge request to the merge train at position 2

    added this merge request to the merge train at position 2

  • merged

  • E. Rivas mentioned in commit db2d4351

    mentioned in commit db2d4351

  • unassigned @er433

  • Please register or sign in to reply
    Loading