mirror of
https://github.com/fluencelabs/hackethberlin
synced 2025-04-24 17:02:18 +00:00
summirizing contract
This commit is contained in:
parent
577c7a5509
commit
4b44ac9c63
@ -15,7 +15,7 @@ sealed trait InlineExpr[T] extends Expr[T] with Expr.ToInlineVyper {
|
||||
def :=:(name: Symbol): Free[Expr, Expr.Ref[T]] =
|
||||
Free.liftF[Expr, Expr.Ref[T]](Expr.Assign[T](Expr.Ref[T](name.name, boxedValue), this))
|
||||
|
||||
def :=:(ref: Expr.Ref[T]): Free[Expr, Expr.Ref[T]] =
|
||||
def :==:(ref: Expr.Ref[T]): Free[Expr, Expr.Ref[T]] =
|
||||
Free.liftF[Expr, Expr.Ref[T]](Expr.Assign[T](ref, this))
|
||||
}
|
||||
|
||||
@ -39,6 +39,15 @@ object Expr {
|
||||
override def toInlineVyper: String = toVyper
|
||||
}
|
||||
|
||||
case class Right[R, T](
|
||||
op: String,
|
||||
right: InlineExpr[R],
|
||||
boxedValue: T
|
||||
) extends InlineExpr[T] {
|
||||
override def toVyper: String = s"$op " + right.toVyper
|
||||
override def toInlineVyper: String = toVyper
|
||||
}
|
||||
|
||||
case class Assign[T](ref: Ref[T], value: InlineExpr[T]) extends Expr[Ref[T]] {
|
||||
override def boxedValue: Ref[T] = ref
|
||||
|
||||
@ -58,6 +67,27 @@ object Expr {
|
||||
|
||||
def `++`(a: InlineExpr[uint256.type], b: InlineExpr[uint256.type]): InlineExpr[uint256.type] =
|
||||
Infix("+", a, b, uint256)
|
||||
|
||||
def `==`[A <: Type, B <: Type](a: InlineExpr[A], b: InlineExpr[B]): InlineExpr[bool.type] =
|
||||
Infix("==", a, b, bool)
|
||||
|
||||
def `+:+`(a: InlineExpr[timestamp.type], b: InlineExpr[timedelta.type]): InlineExpr[timestamp.type] =
|
||||
Infix("+", a, b, timestamp)
|
||||
|
||||
def `if`(expr: InlineExpr[bool.type]): InlineExpr[bool.type] =
|
||||
Right("if", expr, bool)
|
||||
|
||||
def `not`(expr: InlineExpr[bool.type]): InlineExpr[bool.type] =
|
||||
Right("not", expr, bool)
|
||||
|
||||
def `assertt`(expr: InlineExpr[bool.type]): InlineExpr[bool.type] =
|
||||
Right("assert", expr, bool)
|
||||
|
||||
def `<`[A <: Type, B <: Type](a: InlineExpr[A], b: InlineExpr[B]): InlineExpr[bool.type] =
|
||||
Infix("<", a, b, bool)
|
||||
|
||||
def `>`[A <: Type, B <: Type](a: InlineExpr[A], b: InlineExpr[B]): InlineExpr[bool.type] =
|
||||
Infix(">", a, b, bool)
|
||||
}
|
||||
|
||||
object Defs extends Defs
|
||||
|
@ -1,12 +1,16 @@
|
||||
package fluence.hackethberlin
|
||||
|
||||
import fluence.hackethberlin.types.{DataVyper, ProductType}
|
||||
import fluence.hackethberlin.types.{Call, DataVyper, ProductType}
|
||||
import shapeless._
|
||||
import BasisConstraint._
|
||||
import cats.free.Free
|
||||
import shapeless.ops.hlist.{Mapped, ToList}
|
||||
import shapeless.ops.record.{Keys, Selector, Values}
|
||||
import shapeless.tag.@@
|
||||
|
||||
class FuncDef[Args <: HList, Ret <: types.Type, Params <: HList](
|
||||
name: String,
|
||||
argsDef: ProductType[Args],
|
||||
val argsDef: ProductType[Args],
|
||||
ret: Ret,
|
||||
body: ProductType[Args] ⇒ Free[Expr, Ret],
|
||||
decorators: Set[Decorator] = Set.empty
|
||||
|
@ -17,5 +17,8 @@ object PrimitiveType {
|
||||
case object uint256 extends PrimitiveType("uint256")
|
||||
case object decimal extends PrimitiveType("decimal")
|
||||
case object string extends PrimitiveType("string")
|
||||
case object timestamp extends PrimitiveType("timestamp")
|
||||
case object wei_value extends PrimitiveType("wei_value")
|
||||
case object timedelta extends PrimitiveType("timedelta")
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,9 @@ import shapeless.ops.record.Selector
|
||||
|
||||
class ProductType[D <: HList](dataDef: D, dv: DataVyper[D]) extends Type {
|
||||
|
||||
def ref[T <: Symbol, V <: Type](k: Witness.Aux[T])(implicit selector: Selector.Aux[D, T, V]): InlineExpr[V] =
|
||||
import fluence.hackethberlin.untag._
|
||||
|
||||
def ref[T <: Symbol, V <: Type](k: Witness.Aux[T])(implicit selector: Selector.Aux[D, T, V]): Expr.Ref[V] =
|
||||
Expr.Ref[V](k.value.name, selector(dataDef))
|
||||
|
||||
// type in type definition somewhere
|
||||
|
@ -4,6 +4,7 @@ import hackethberlin._
|
||||
import hackethberlin.types._
|
||||
import shapeless._
|
||||
import Decorator._
|
||||
import cats.free.Free
|
||||
import syntax.singleton._
|
||||
|
||||
object MakeVyperApp extends App {
|
||||
@ -51,7 +52,7 @@ object MakeVyperApp extends App {
|
||||
for {
|
||||
c ← 'c :=: `++`(args.ref('a), args.ref('b))
|
||||
d ← 'd :=: `++`(args.ref('b), c)
|
||||
_ ← d :=: c
|
||||
_ ← d :==: c
|
||||
sum ← `++`(args.ref('a), d).toReturn
|
||||
} yield sum
|
||||
}
|
||||
@ -68,3 +69,52 @@ object MakeVyperApp extends App {
|
||||
|
||||
// println(s"MMMMMACRO\n\n ${new MyContract("abc", 123).toAST.toVyper}")
|
||||
}
|
||||
|
||||
object Auction {
|
||||
val data = ProductType(
|
||||
('beneficiary ->> public(address)) ::
|
||||
('auction_start ->> public(timestamp)) ::
|
||||
('auction_end ->> public(timestamp)) ::
|
||||
('highest_bidder ->> `public`(address)) ::
|
||||
('highest_bid ->> `public`(wei_value)) ::
|
||||
('ended ->> public(bool)) :: HNil
|
||||
)
|
||||
|
||||
val beneficiary = data.ref('beneficiary)
|
||||
val auction_start = data.ref('auction_start)
|
||||
val auction_end = data.ref('auction_end)
|
||||
val highest_bid = data.ref('highest_bid)
|
||||
|
||||
val initArgs = ProductType(('_beneficiary ->> address) :: ('_bidding_time ->> timedelta) :: HNil)
|
||||
|
||||
import untag._
|
||||
|
||||
val _beneficiary = initArgs.ref('_beneficiary)
|
||||
val _bidding_time = initArgs.ref('_bidding_time)
|
||||
|
||||
println(_beneficiary.getClass)
|
||||
|
||||
val init = `@public` @: initArgs.funcDef(
|
||||
"__init__",
|
||||
Void
|
||||
) { args ⇒
|
||||
for {
|
||||
_ <- Free.pure(Void)
|
||||
// _ <- beneficiary :==: _beneficiary
|
||||
// _ <- auction_start :==: block.timestamp
|
||||
// _ <- auction_end :==: auction_start `+:+` _bidding_time
|
||||
} yield Void
|
||||
}
|
||||
|
||||
|
||||
val bid = `@public` @: `@payable` @: ProductType(HNil).funcDef(
|
||||
"bid",
|
||||
Void
|
||||
) { args ⇒
|
||||
for {
|
||||
_ <- Free.pure(Void)
|
||||
_ <- `assertt` (block.timestamp `<` auction_end)
|
||||
_ <- `assertt` (msg.value `>` highest_bid)
|
||||
} yield Void
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package fluence
|
||||
import fluence.hackethberlin.ToVyper
|
||||
|
||||
@ToVyper
|
||||
class MyContract(owner: String, friend: Int) {}
|
||||
//@ToVyper
|
||||
//class MyContract(owner: String, friend: Int) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user