bitcoin-atm
bitcoin atm for pyc inc.
git clone https://9o.is/git/bitcoin-atm.git
IncompleteTransaction.scala
(1859B)
1 package inc.pyc.chimera
2 package model
3
4 import inc.pyc.currency._
5 import net.liftweb._
6 import mapper._
7 import inc.pyc.bitcoin.Price
8
9 /**
10 * The information of a completed customer transaction.
11 */
12 class IncompleteTransaction extends KeyedMapper[String, IncompleteTransaction] {
13 def getSingleton = IncompleteTransaction
14 def primaryKeyField = address
15
16 /**
17 * Bitcoin address to send bitcoin
18 */
19 object address extends MappedStringIndex(this, 256) {
20 override def writePermission_? = true
21 override def dbAutogenerated_? = false
22 override def dbNotNull_? = true
23 }
24
25 /**
26 * Market buy price
27 */
28 object price extends MappedDouble(this)
29
30 /**
31 * Percentage over market buy price
32 */
33 object percentage extends MappedDouble(this)
34
35 /**
36 * Currency used to make the transaction
37 */
38 object currency extends MappedString(this, 5) {
39 def apply(c: Currency) = super.apply(c.toString)
40 def asCurrency: Currency = findCurrency(get)
41 }
42
43 /**
44 * The bills the user has inserted into the bill acceptor
45 */
46 object bills extends MappedString(this, 2048) {
47
48 def apply(b: List[Int]) =
49 super.apply(b mkString ",")
50
51 def asList: List[Int] =
52 if (get.isEmpty) Nil
53 else get.split(",").toList.map(_.toInt)
54
55 }
56
57 def asIncompleteTx: IncompleteTx =
58 IncompleteTx(address.get, Price(price.get, percentage.get),
59 currency.asCurrency, bills.asList, 0, UserInfo())
60
61 def save(tx: IncompleteTx): Boolean = {
62 address(tx.address)
63 price(tx.price.price)
64 percentage(tx.price.percentage)
65 currency(tx.currency)
66 bills(tx.bills)
67 save()
68 }
69
70 }
71
72 object IncompleteTransaction extends IncompleteTransaction
73 with KeyedMetaMapper[String, IncompleteTransaction] {
74
75 override def save(tx: IncompleteTx) = {
76 val incomplete = find(tx.address) openOr create
77 incomplete.save(tx)
78 }
79
80 }