summirizing contract

This commit is contained in:
dmitry.shakhtarin 2018-09-09 11:01:35 +03:00
parent c3f30a2b71
commit 31d4d171ca
3 changed files with 15 additions and 20 deletions

View File

@ -115,6 +115,19 @@ object Expr {
object Defs extends Defs { object Defs extends Defs {
import types._
import syntax.singleton._
val send =
ProductType(('_addr ->> `public`(address)) :: ('_money ->> `public`(wei_value)) :: HNil).funcDef(
"send",
Void
) { args
for {
_ <- Free.pure(Void)
} yield Void
}
val predef = ProductType( val predef = ProductType(
(Symbol("block.timestamp") ->> timestamp) :: (Symbol("block.timestamp") ->> timestamp) ::
(Symbol("msg.value") ->> wei_value) :: (Symbol("msg.value") ->> wei_value) ::

View File

@ -47,18 +47,4 @@ object FuncDef {
mapped: ops.hlist.Mapped[_Values, InlineExpr] mapped: ops.hlist.Mapped[_Values, InlineExpr]
)(implicit values: ops.record.Values.Aux[Args, _Values]): FuncDef[Args, types.Void, mapped.Out] = )(implicit values: ops.record.Values.Aux[Args, _Values]): FuncDef[Args, types.Void, mapped.Out] =
new FuncDef(name, ProductType(argsDef), types.Void, args body(args).map(_ types.Void)) new FuncDef(name, ProductType(argsDef), types.Void, args body(args).map(_ types.Void))
import types._
import syntax.singleton._
val send = {
ProductType(('_addr ->> `public`(address)) :: ('_money ->> `public`(wei_value)) :: HNil).funcDef(
"send",
Void
) { args
for {
_ <- Free.pure(Void)
} yield Void
}
}
} }

View File

@ -5,7 +5,6 @@ import hackethberlin.types._
import shapeless._ import shapeless._
import Decorator._ import Decorator._
import syntax.singleton._ import syntax.singleton._
import cats.free.Free
import fluence.hackethberlin.{Contract, Expr, FuncDef} import fluence.hackethberlin.{Contract, Expr, FuncDef}
import fluence.hackethberlin.types.{`public`, ProductType, Void} import fluence.hackethberlin.types.{`public`, ProductType, Void}
import shapeless.HNil import shapeless.HNil
@ -39,7 +38,6 @@ object Auction extends App {
Void Void
) { args ) { args
for { for {
_ <- Free.pure(Void)
_ <- beneficiary :=: _beneficiary _ <- beneficiary :=: _beneficiary
_ <- auction_start :=: `block.timestamp` _ <- auction_start :=: `block.timestamp`
_ <- auction_end :=: `+:+`(auction_start, _bidding_time) _ <- auction_end :=: `+:+`(auction_start, _bidding_time)
@ -55,9 +53,7 @@ object Auction extends App {
_ <- `assert`(`>>`(`msg.value`, highest_bid)) _ <- `assert`(`>>`(`msg.value`, highest_bid))
_ <- `if`(`not`(`:===:`(highest_bid, `msg.value`)), { _ <- `if`(`not`(`:===:`(highest_bid, `msg.value`)), {
() => () =>
for { send(highest_bidder :: highest_bid :: HNil).liftF.map(_ => Void)
_ <- FuncDef.send(highest_bidder :: highest_bid :: HNil).liftF
} yield Void
}) })
_ <- highest_bidder :=: `msg.sender` _ <- highest_bidder :=: `msg.sender`
_ <- highest_bid :=: `msg.value` _ <- highest_bid :=: `msg.value`
@ -72,7 +68,7 @@ object Auction extends App {
_ <- `assert`(`>=`(`block.timestamp`, auction_end)) _ <- `assert`(`>=`(`block.timestamp`, auction_end))
_ <- `assert`(`not`(ended)) _ <- `assert`(`not`(ended))
_ <- ended :=: `True` _ <- ended :=: `True`
_ <- FuncDef.send(beneficiary :: highest_bid :: HNil).liftF _ <- send(beneficiary :: highest_bid :: HNil).liftF.map(_ => Void)
} yield Void } yield Void
} }