(* NAME_START:test :NAME_END *)
open Zen.Types
open Zen.Base
open Zen.Cost
open Zen.Asset
open Zen.Data
module D = Zen.Dictionary
module Tx = Zen.TxSkeleton
module C = Zen.Cost
module RT = Zen.ResultT
module CR = Zen.ContractResult
let cf _ _ _ _ _ wallet _ =
4 + 64 + 2 + (64 + (0 + 64 + 3)) + 25
|> C.ret #nat
let main txSkeleton _ contractId _ _ messageBody wallet _ =
let! returnAddress =
messageBody >!= tryDict
>?= D.tryFind "returnAddress"
>?= tryLock
in
match returnAddress with
| Some returnAddress ->
let! amount = Tx.getAvailableTokens zenAsset txSkeleton in
let! txSkeleton =
ret txSkeleton
>>= Tx.lockToAddress zenAsset amount returnAddress in
CR.ofTxSkel txSkeleton
| None ->
RT.autoFailw "returnAddress is required"