0

I'm trying to initialise a contract that has an address option in its initial storage, but when I provide a valid address, it keeps being interpreted as a string; and compilation fails.

I have here a minimal contract showing the address option behaviour:

(** A host keeps the payment window open *)
type contract_storage = 
[@layout:comb]
{
    host: address option;
}

(* Fails if sender is not host *)
let fail_if_not_host (storage : contract_storage) : unit =
  match storage.host with
  | None -> unit
  | Some host ->
    if Tezos.sender <> host
    then failwith "You are not the host of the contract"
    else unit

let fail_if_unhosted (storage: contract_storage) : unit =
  match storage.host with
  | None -> (failwith "The contract is no longer hosted" : unit)
  | Some _host -> unit

type entrypoint =
[@layout:comb]
    | Remove_host of unit
    | Default of unit


let main (param, storage : entrypoint * contract_storage) : operation list * contract_storage =
    match param with
    | Remove_host _b ->
        let _ = fail_if_not_host storage in
        let new_storage = { storage with host = (None : address option); } in
        ([]: operation list), new_storage
    | Default _d ->
        let _ = fail_if_unhosted storage in
        ([]: operation list), storage

Initial storage:

{
    host = (Some "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb": address option);
}

This is a valid address: https://tzkt.io/tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb/operations/

When I try to compile it though:

echo -e "Initial ligo storage:\n${initial_ligo_storage}"
echo "Compiling…"
ligo compile storage $ligo_file "$initial_ligo_storage" --entry-point main --protocol $tezos_protocol --werror --output-file hostable_seed.tz
Initial ligo storage:
{
    host = (Some "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb": address option);
}
Compiling…

Invalid type(s).
Expected: "option (address)", but got: "option (string)". 

1 Answer 1

2

The address itself should be annotated as address, like this:

{
    host = Some ("tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" : address);
}

See successful deployment: https://ide.ligolang.org/p/lxt1CWE4AutZLUSL6z1Kow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.