From 59413be6266f7b9e47c6dd492bf75d0df6710d6a Mon Sep 17 00:00:00 2001 From: Doron Somech Date: Wed, 13 Jun 2018 15:26:36 +0300 Subject: [PATCH] up-do-date with zen-node --- package/package.json | 2 +- paket.dependencies | 13 ++----- paket.lock | 54 ++++++++++++++++++---------- src/ZFS-SDK/Program.fs | 72 +++++++++++++++++++++----------------- src/ZFS-SDK/ZFS-SDK.fsproj | 2 +- 5 files changed, 80 insertions(+), 63 deletions(-) diff --git a/package/package.json b/package/package.json index a98f245..e748cce 100644 --- a/package/package.json +++ b/package/package.json @@ -1,7 +1,7 @@ { "author":"Zebra", "name":"@zen/zebra", - "version":"0.0.5", + "version":"0.0.8", "main":"index.js", "bin": { "zebra":"zebra.js" diff --git a/paket.dependencies b/paket.dependencies index 2591bdf..5152337 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -8,23 +8,16 @@ nuget FSharp.Core nuget System.ValueTuple nuget ZFS-Tools 0.0.19 nuget FSharpx.Extras -nuget FsNetMQ -nuget FSharp.Control.Reactive -nuget FSharp.Data -nuget Zen.FSharp.Compiler.Service -nuget FsBech32 nuget ZFStar 0.0.19 nuget FSharp.Configuration nuget FSharp.Compatibility.OCaml -nuget System.Reflection.Metadata 1.4.2 -nuget NodaTime 1.3.2 source https://www.myget.org/f/zenprotocol framework: 47 -nuget Zulib >= 0.3.17 -nuget Infrastructure = 0.3.17 -nuget Consensus >= 0.3.17 +nuget Zulib >= 0.3.23 +nuget Infrastructure = 0.3.23 +nuget Consensus >= 0.3.23 nuget zen_secp256k1_osx nuget zen_secp256k1_linux nuget zen_z3_osx diff --git a/paket.lock b/paket.lock index dbc38db..72b36d9 100644 --- a/paket.lock +++ b/paket.lock @@ -10,7 +10,8 @@ NUGET FsBech32 (0.1.0.7) FSharp.Compiler.Tools FSharp.Core - FSharp.Compatibility.OCaml (0.1.13) + FSharp.Compatibility.OCaml (0.1.14) + FSharp.Core (>= 4.3.4) FSharp.Compiler.Tools (10.0.2) FSharp.Configuration (1.4) FSharp.Core (>= 4.0.0.1) @@ -49,18 +50,35 @@ NUGET NodaTime (1.3.2) System.Collections.Immutable (1.4) NETStandard.Library (>= 1.6.1) - System.Reactive (3.1.1) - System.Reactive.PlatformServices (>= 3.1.1) - System.Reactive.Windows.Threading (>= 3.1.1) - System.Reactive.Core (3.1.1) - System.Reactive.Interfaces (>= 3.1.1) - System.Reactive.Interfaces (3.1.1) - System.Reactive.Linq (3.1.1) - System.Reactive.Core (>= 3.1.1) - System.Reactive.PlatformServices (3.1.1) - System.Reactive.Linq (>= 3.1.1) - System.Reactive.Windows.Threading (3.1.1) - System.Reactive.Core (>= 3.1.1) + System.Reactive (4.0) + System.Reactive.Compatibility (4.0) + System.Reactive.Core (>= 4.0) + System.Reactive.Experimental (>= 4.0) + System.Reactive.Interfaces (>= 4.0) + System.Reactive.Linq (>= 4.0) + System.Reactive.PlatformServices (>= 4.0) + System.Reactive.Providers (>= 4.0) + System.Reactive.Runtime.Remoting (>= 4.0) + System.Reactive.Windows.Forms (>= 4.0) + System.Reactive.Windows.Threading (>= 4.0) + System.Reactive.Core (4.0) + System.Reactive (>= 4.0) + System.Reactive.Experimental (4.0) + System.Reactive (>= 4.0) + System.Reactive.Interfaces (4.0) + System.Reactive (>= 4.0) + System.Reactive.Linq (4.0) + System.Reactive (>= 4.0) + System.Reactive.PlatformServices (4.0) + System.Reactive (>= 4.0) + System.Reactive.Providers (4.0) + System.Reactive (>= 4.0) + System.Reactive.Runtime.Remoting (4.0) + System.Reactive (>= 4.0) + System.Reactive.Windows.Forms (4.0) + System.Reactive (>= 4.0) + System.Reactive.Windows.Threading (4.0) + System.Reactive (>= 4.0) System.Reflection.Metadata (1.4.2) System.Collections.Immutable (>= 1.3.1) System.ValueTuple (4.4) @@ -72,7 +90,7 @@ NUGET ZFS-Tools (0.0.19) ZFStar (0.0.19) remote: https://www.myget.org/f/zenprotocol - Consensus (0.3.17) + Consensus (0.3.23) BouncyCastle FsBech32 (>= 0.1.0.7) FSharp.Compatibility.OCaml @@ -80,10 +98,10 @@ NUGET FSharpx.Extras FsNetMQ (>= 0.2.7) FsPickler - Infrastructure (>= 0.3.17) + Infrastructure (>= 0.3.23) Logary Zulib (>= 0.0.1) - Infrastructure (0.3.17) + Infrastructure (0.3.23) BouncyCastle FSharp.Compiler.Tools (>= 10.0.2) FSharp.Control.Reactive @@ -93,7 +111,7 @@ NUGET FsNetMQ (>= 0.2.7) FsPickler Logary - System.Reactive.Linq + System.Reactive.Compatibility Zen.FSharp.Compiler.Service (17.0.2) ZFS-Tools (0.0.19) ZFStar (0.0.19) @@ -101,4 +119,4 @@ NUGET zen_z3_linux (4.5.1.8-v1f29cebd4df) zen_z3_osx (4.5.1.8-v1f29cebd4df6) zen_z3_windows (4.5.1.7-v1f29cebd4df) - Zulib (0.3.17) + Zulib (0.3.23) diff --git a/src/ZFS-SDK/Program.fs b/src/ZFS-SDK/Program.fs index e40a644..40988f1 100644 --- a/src/ZFS-SDK/Program.fs +++ b/src/ZFS-SDK/Program.fs @@ -46,55 +46,61 @@ open Zen.Base open Zen.Cost open Zen.Asset open Zen.Data -open Zen.Dictionary +module D = Zen.Dictionary +module W = Zen.Wallet module RT = Zen.ResultT -module OT = Zen.OptionT module Tx = Zen.TxSkeleton -module CR = Zen.ContractResult.NoMessage +module C = Zen.Cost let buy txSkeleton contractId returnAddress = - let! tokens = Tx.getAvailableTokens zenAsset txSkeleton in - - let! contractAsset = getDefault contractId in + let! contractToken = Zen.Asset.getDefault contractId in + let! amount = Tx.getAvailableTokens zenAsset txSkeleton in let! txSkeleton = - Tx.lockToContract zenAsset tokens contractId txSkeleton - >>= Tx.mint tokens contractAsset - >>= Tx.lockToAddress contractAsset tokens returnAddress in - - CR.ret txSkeleton + Tx.lockToContract zenAsset amount contractId txSkeleton + >>= Tx.mint amount contractToken + >>= Tx.lockToAddress contractToken amount returnAddress in + RT.ok @ { tx = txSkeleton; message = None; state = NoChange } let redeem txSkeleton contractId returnAddress wallet = - let! contractAsset = getDefault contractId in - let! tokens = Tx.getAvailableTokens contractAsset txSkeleton in + let! contractToken = Zen.Asset.getDefault contractId in + let! amount = Tx.getAvailableTokens contractToken txSkeleton in let! txSkeleton = - Tx.destroy tokens contractAsset txSkeleton - >>= Tx.lockToAddress zenAsset tokens returnAddress - >>= Tx.fromWallet zenAsset tokens contractId wallet in - - CR.ofOption "contract doesn't have enough zens to pay you" txSkeleton - -let main txSkeleton context contractId command sender data wallet = - let! returnAddress = data >!= tryDict >?= tryFind "returnAddress" >?= tryLock in - + Tx.destroy amount contractToken txSkeleton + >>= 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 + +let main txSkeleton _ contractId command sender messageBody wallet state = + let! returnAddress = + messageBody >!= tryDict + >?= D.tryFind "returnAddress" + >?= tryLock + in match returnAddress with | Some returnAddress -> - if command = "redeem" then - redeem txSkeleton contractId returnAddress wallet - else if command = "" || command = "buy" then - buy txSkeleton contractId returnAddress - |> autoInc - else - RT.autoFailw "unsupported command" + if command = "redeem" then + redeem txSkeleton contractId returnAddress wallet + else if command = "" || command = "buy" then + buy txSkeleton contractId returnAddress + |> autoInc + else + RT.autoFailw "unsupported command" | None -> - RT.autoFailw "returnAddress is required" + RT.autoFailw "returnAddress is required" -let cf _ _ _ _ _ wallet = - (4 + 64 + 2 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 25) + 31) +let cf _ _ _ _ _ wallet _ = + 4 + 64 + 2 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 33) + 31 |> cast nat - |> ret""" (filePath.Substring (0, filePath.Length - 4)) + |> C.ret""" (filePath.Substring (0, filePath.Length - 4)) System.IO.File.WriteAllText (filePath, code) diff --git a/src/ZFS-SDK/ZFS-SDK.fsproj b/src/ZFS-SDK/ZFS-SDK.fsproj index aa3bb46..697ece6 100644 --- a/src/ZFS-SDK/ZFS-SDK.fsproj +++ b/src/ZFS-SDK/ZFS-SDK.fsproj @@ -154,7 +154,7 @@ - ..\..\packages\FSharp.Compatibility.OCaml\lib\net40\FSharp.Compatibility.OCaml.dll + ..\..\packages\FSharp.Compatibility.OCaml\lib\net45\FSharp.Compatibility.OCaml.dll True True