Contract - ST
Address:
ID:

SUMMARY
FULL NAMESubtype Test
STATUSInactive
TRANSACTIONS0
LAST ACTIVATION BLOCK4,735
BALANCES
ASSETAMOUNT
(* NAME_START:Subtype 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 CR = Zen.ContractResult
module RT = Zen.ResultT
module String = FStar.String
module C = Zen.Cost

let getToken contractId command = 
 if command = "index" then 
 begin
    let! token = Zen.Asset.fromSubtypeInt contractId 100ul in
 
    ret token
 end
 else
    let (version,cHash) = contractId in 
    let token = (version,cHash,cHash) in

    autoRet token

let main txSkeleton _ contractId command sender messageBody wallet state =
  let dict = messageBody >!= tryDict in

  let! returnAddress =
    dict
    >?= D.tryFind "returnAddress"
    >?= tryLock 
    in

  let! amount = 
    dict
    >?= D.tryFind "amount"
    >?= tryU64 
    in 
      
  match returnAddress,amount with
  | Some returnAddress, Some amount ->          
      let! token = getToken contractId command in 
                 
      let! txSkeleton =
        Tx.lockToAddress token amount returnAddress txSkeleton
        >>= Tx.mint amount token in

      CR.ofTxSkel txSkeleton
  | _ ->
    RT.autoFailw "parameters are missing"
    
let cf _ _ _ _ _ wallet _ =
    (4 + 64 + 2 + (4 + 64 + 2 + (64 + 0 + 10 + (64 + 64 + 3))) + 38)
    |> cast nat
    |> C.ret