Skip to content

Commit

Permalink
Merge pull request #11 from SharonU/master
Browse files Browse the repository at this point in the history
updated example contract
  • Loading branch information
somdoron authored Jul 26, 2018
2 parents 140ceaa + 7dd2861 commit c849286
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/ZFS-SDK/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module W = Zen.Wallet
module RT = Zen.ResultT
module Tx = Zen.TxSkeleton
module C = Zen.Cost
module CR = Zen.ContractResult
let buy txSkeleton contractId returnAddress =
let! contractToken = Zen.Asset.getDefault contractId in
Expand All @@ -61,7 +62,8 @@ let buy txSkeleton contractId returnAddress =
Tx.lockToContract zenAsset amount contractId txSkeleton
>>= Tx.mint amount contractToken
>>= Tx.lockToAddress contractToken amount returnAddress in
RT.ok @ { tx = txSkeleton; message = None; state = NoChange }
CR.ofTxSkel txSkeleton
let redeem txSkeleton contractId returnAddress wallet =
let! contractToken = Zen.Asset.getDefault contractId in
Expand All @@ -72,12 +74,7 @@ let redeem txSkeleton contractId returnAddress wallet =
>>= Tx.lockToAddress zenAsset amount returnAddress
>>= Tx.fromWallet zenAsset amount contractId wallet in
let result =
match txSkeleton with
| Some tx -> Some @ { tx = tx; message = None; state = NoChange }
| None -> None in
RT.of_option "contract doesn't have enough zens tokens" result
CR.ofOptionTxSkel "contract doesn't have enough zens tokens" txSkeleton
let main txSkeleton _ contractId command sender messageBody wallet state =
let! returnAddress =
Expand All @@ -98,9 +95,8 @@ let main txSkeleton _ contractId command sender messageBody wallet state =
RT.autoFailw "returnAddress is required"
let cf _ _ _ _ _ wallet _ =
4 + 64 + 2 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 33) + 31
|> cast nat
|> C.ret""" (filePath.Substring (0, filePath.Length - 4))
4 + 64 + 2 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 3)) + 25) + 31
|> C.ret #nat""" (filePath.Substring (0, filePath.Length - 4))

System.IO.File.WriteAllText (filePath, code)

Expand Down

0 comments on commit c849286

Please sign in to comment.