bitcoin-atm
bitcoin atm for pyc inc.
git clone https://9o.is/git/bitcoin-atm.git
General.scala
(965B)
1 package inc.pyc.chimera
2 package minions
3
4 import akka.actor._
5
6 /**
7 * Just a general minion. Has nothing special about it.
8 * Might remove this in the future.
9 */
10 class GeneralMinion
11 extends Actor
12 with ActorLogging
13 with Minion {
14
15 val tasks: Receive = {
16 case insp: InspectBill => isBillAcceptable(insp)
17 }
18
19 /**
20 * Checks if the inserted bill should be accepted
21 * @param inserted bill inserted
22 * @param tx incomplete transaction
23 */
24 def isBillAcceptable(inspect: InspectBill) = runTask {
25 val tx = inspect.tx
26 val newTx = tx.insertBill(inspect.inserted.bill)
27 val balance = inspect.balance.remaining
28
29 // new total must not exceed purchase limit
30 if(newTx.total > tx.limit)
31 sender ! InvalidBill
32
33 // new amount of bitcoins must not exceed the amount in our wallet
34 else if(newTx.bitcoins > balance)
35 sender ! InsufficientFunds
36
37 // else, okay!
38 else
39 sender ! ValidBill
40 }
41 }