self. for data

This commit is contained in:
alari 2018-09-09 09:26:17 +02:00
parent 5fbdecf11b
commit d59412e14d
3 changed files with 8 additions and 5 deletions

View File

@ -2,7 +2,7 @@
Metaprogramming for Ethereum Smart Contracts expressed in Scala's Type System.
- Unlock Smart Contracts **adoption with JVM**-based language: code them _from_ Scala or _in_ Scala
- Unlock Smart Contracts **adoption with a JVM**-based language: code them _from_ Scala or _in_ Scala
- Smart Contracts code generator is itself **a strictly typed program**
- Write a Contract using structs and definitions of **Crotalinae DSL**, and if it compiles, you're **safe**
- **Export** Smart Contract in [Vyper](https://github.com/ethereum/vyper) as a single plaintext and check it visually if needed

View File

@ -5,10 +5,10 @@ import fluence.hackethberlin.{Expr, FuncDef, InlineExpr}
import shapeless._
import shapeless.ops.record.Selector
class ProductType[D <: HList](dataDef: D, dv: DataVyper[D]) extends Type {
class ProductType[D <: HList](dataDef: D, refPrefix: String, dv: DataVyper[D]) extends Type {
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))
Expr.Ref[V](refPrefix + k.value.name, selector(dataDef))
// type in type definition somewhere
override def toVyper: String =
@ -35,7 +35,10 @@ class ProductType[D <: HList](dataDef: D, dv: DataVyper[D]) extends Type {
object ProductType {
def apply[D <: HList](dataDef: D)(implicit dv: DataVyper[D]): ProductType[D] =
new ProductType[D](dataDef, dv)
new ProductType[D](dataDef, "", dv)
def self[D <: HList](dataDef: D)(implicit dv: DataVyper[D]): ProductType[D] =
new ProductType[D](dataDef, "self.", dv)
def hNil: ProductType[HNil] = ProductType(HNil)
}

View File

@ -87,7 +87,7 @@ object Auction extends App {
val `msg.sender` = predef.ref(Symbol("msg.sender"))
val `True` = predef.ref('True)
val data = ProductType(
val data = ProductType.self(
('beneficiary ->> public(address)) ::
('auction_start ->> public(timestamp)) ::
('auction_end ->> public(timestamp)) ::