Skip to content

Commit

Permalink
up-do-date with zen-node
Browse files Browse the repository at this point in the history
  • Loading branch information
somdoron committed Jun 13, 2018
1 parent 112ba94 commit 59413be
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 63 deletions.
2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author":"Zebra",
"name":"@zen/zebra",
"version":"0.0.5",
"version":"0.0.8",
"main":"index.js",
"bin": {
"zebra":"zebra.js"
Expand Down
13 changes: 3 additions & 10 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 36 additions & 18 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -72,18 +90,18 @@ 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
FSharp.Core (4.3.4)
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
Expand All @@ -93,12 +111,12 @@ 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)
zen_secp256k1_osx (0.1.0.26-v6ad5cdb42a1a)
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)
72 changes: 39 additions & 33 deletions src/ZFS-SDK/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/ZFS-SDK/ZFS-SDK.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.7'">
<ItemGroup>
<Reference Include="FSharp.Compatibility.OCaml">
<HintPath>..\..\packages\FSharp.Compatibility.OCaml\lib\net40\FSharp.Compatibility.OCaml.dll</HintPath>
<HintPath>..\..\packages\FSharp.Compatibility.OCaml\lib\net45\FSharp.Compatibility.OCaml.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
Expand Down

0 comments on commit 59413be

Please sign in to comment.