Hangzhou
API
New types
type chest
A type for cheststype chest_key
A type for chest keystype chest_opening_result = ["Ok_opening", bytes] | ["Fail_decrypt"] | ["Fail_timelock"];
A type for the result of chest opening, see Mavryk.open_chest
New primitives
Mavryk
let open_chest : chest_key => chest => nat => chest_opening_result
let call_view : string => 'arg => address => option <'ret>
let constant : string => 'a
Test
New signature for originate_from_file:
let originate_from_file = (filepath: string, entrypoint: string , views : list <'string> , init: michelson_program, balance: mav) => [address, michelson_program, int]
Originate a contract with a path to the contract file, an entrypoint, a list of views, an initial storage and an initial balance.
let create_chest : bytes => nat => [chest , chest_key]
Generate a locked value, the RSA parameters and encrypt the payload. Also returns the chest key Exposes mavryk timelock library function create_chest_and_chest_key
let create_chest_key : chest => nat => chest_key
Unlock the value and create the time-lock proof. Exposes mavryk timelock library function create_chest_key.
Examples
Timelock
Extensive documentation about timelock can be found here. Here is an example of a contract trying to open a chest and the corresponding tests to trigger all error kinds:
On-chain views
Mavryk documentation on views can be found here
On-chain views are named routines attached to your contract allowing
another contract to call them to get a "view" of your contract current
storage. It cannot modify your storage nor emit operations. These
routines can either simply return your contract storage or apply some
kind of processing to it: they take your current storage, a parameter
and returns the data of your choice. Note that parameter and return
types can be anything except big_map
; sapling_state
; operation
and ticket
. Views are named after their declaration name and can be
compiled in two ways:
by passing their names to the command line option
--views
(e.g.ligo compile contract --views v1,v2,v3
)by annotating their declarations in your code with
view
Important: the first way (
--views
) will override any annotated declarations
Given a very simple contract having a storage of type string
, here
are a few legit views:
Note:
[@view]
attribute is only supported for top-level functions.The use of
[@view]
attribute anywhere other than top-level will be ignored.
A few primitives have a slightly different meaning when executed as part of a view:
Mavryk.get_balance
represents the current amount of mumav held by the contract attached to the viewMavryk.get_sender
represents the caller of the viewMavryk.get_amount
is always 0 mumavMavryk.get_self_address
represents the contract attached to the view
On the caller side, the primitive Mavryk.call_view
will allow you to call another contract view and get its result by providing the view name; the contract address and the parameter of the view. If the address is nonexistent; the name does not match of of the contract
view or the parameter type do not match, Mavryk.call_view
will return None
.
Global constant
The new primitive Mavryk.constant
allows you to use a predefined
constant already registered on chain. It accepts a hash in the form
of a string and will require a type annotation.