package fluence import hackethberlin._ import hackethberlin.types._ import shapeless._ import Decorator._ import cats.free.Free import fluence.hackethberlin.Expr.Defs import syntax.singleton._ object MakeVyperApp extends App { val struct = ProductType( ('address ->> address) :: ('owner ->> address) :: ('size ->> uint256) :: ('time ->> int128) :: HNil ) val data = ProductType( ('address ->> address) :: ('owner ->> `public`(address)) :: ('holders ->> (address ~>> bool)) :: ('structMap ->> `public`(uint256 ~>> struct)) :: ('struct ->> `public`(struct)) :: ('struct2 ->> struct) :: HNil ) val func = FuncDef( "myFunc", ('addr ->> address) :: HNil, address )(args ⇒ args.ref('addr).toReturn) val recordStruct = ProductType( ('record_address ->> address) :: ('other_some ->> uint256) :: HNil ) println(Console.RED + recordStruct.ref('other_some) + Console.RESET) println(recordStruct.toVyper) println(data.toDataVyper) println(func.toVyper) val sumArgs = ProductType(('a ->> uint256) :: ('b ->> uint256) :: HNil) import Expr.Defs._ val f = `@public` @: sumArgs.funcDef("sum", uint256) { args ⇒ for { c ← 'c :=: `++`(args.ref('a), args.ref('b)) d ← 'd :=: `++`(args.ref('b), c) _ ← d :=: c sum ← `++`(args.ref('a), d).toReturn } yield sum } val all = recordStruct :: data :: func :: f :: HNil val c = new Contract(recordStruct :: struct :: data :: func :: f :: HNil) println(c.toVyper) println( func(recordStruct.ref('record_address) :: HNil).toVyper ) // println(s"MMMMMACRO\n\n ${new MyContract("abc", 123).toAST.toVyper}") } object Auction { import Expr.Defs._ val predef = ProductType( (Symbol("block.timestamp") ->> timestamp) :: (Symbol("msg.value") ->> uint256) :: (Symbol("msg.sender") ->> address) :: HNil ) val `block.timestamp` = predef.ref(Symbol("block.timestamp")) val `msg.value` = predef.ref(Symbol("msg.value")) val `msg.sender` = predef.ref(Symbol("msg.sender")) 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 highest_bidder = data.ref('highest_bidder) val initArgs = ProductType(('_beneficiary ->> address) :: ('_bidding_time ->> timedelta) :: HNil) 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 bidIf: () ⇒ Free[Expr, Void] = { () => for { _ <- Free.pure(Void) // _ <- FuncDef.send(highest_bidder :: highest_bid :: HNil) } yield Void } /*val bid = `@public` @: `@payable` @: ProductType(HNil: HList).funcDef( "bid", Void ) { args ⇒ for { _ <- `assertt`(`block.timestamp` `<<` auction_end) _ <- `assertt`(`msg.value` `>>` highest_bid) _ <- `if`(`not`(highest_bid `:===:` `msg.value`), bidIf) _ <- highest_bidder :=: `msg.sender` _ <- highest_bid :=: `msg.value` } yield Void }*/ }