bitcoin-atm
bitcoin atm for pyc inc.
git clone https://9o.is/git/bitcoin-atm.git
Factory.scala
(4868B)
1 package inc.pyc.chimera
2 package minions
3
4 import akka.actor._
5 import util.Random
6 import inc.pyc.bill._
7 import acceptor._
8 import Events._
9
10 /**
11 * Creates minions.
12 */
13 trait MinionFactory {
14 this: Actor =>
15
16 /**
17 * Name for actor minions.
18 */
19 def minionName: String = "Minion_"+Random.nextInt
20
21 /**
22 * Summons a minion
23 */
24 def summon(minion: Props) = context.actorOf(minion, minionName)
25
26 /**
27 * Summons a SMS Minion.
28 */
29 def summonSMS: ActorRef = summon(Props[SMSMinion])
30
31 /**
32 * Summons a User Minion.
33 */
34 def summonUser: ActorRef = summon(Props[UserMinion])
35
36 /**
37 * Summons a General Minion.
38 */
39 def summonGeneral: ActorRef = summon(Props[GeneralMinion])
40
41 /**
42 * Summons a User Minion.
43 */
44 def summonLocalDb: ActorRef = summon(Props[LocalDBMinion])
45
46 /**
47 * Summons a Transaction Minion.
48 */
49 def summonTransaction: ActorRef = summon(Props[TransactionMinion])
50
51 /**
52 * Summons an Expenditure Minion.
53 */
54 def summonExpenditure: ActorRef = summon(Props[ExpenditureMinion])
55
56 /**
57 * Summons a Phone Number Minion.
58 */
59 def summonPhoneNumber: ActorRef = summon(Props[PhoneNumberMinion])
60
61 /**
62 * Summons a Receipt Email Minion.
63 */
64 def summonReceiptEmail: ActorRef = summon(Props[ReceiptEmailMinion])
65
66 /**
67 * Summons a receipt minion.
68 */
69 def summonReceipt: ActorRef = summon(Props[ReceiptMinion])
70
71 /**
72 * Summons a receipt minion.
73 */
74 def summonCustomerSupport: ActorRef = summon(Props[CustomerSupportMinion])
75
76 /**
77 * Logs in registered user with bitcoin address.
78 */
79 def loginUser(address: BitcoinAddress) {
80 summonUser ! address
81 }
82
83 /**
84 * Logs in registered user.
85 */
86 def loginUser(info: UserVerify) {
87 summonUser ! info
88 }
89
90 /**
91 * Searches for information to allow or
92 * disallow user to buy bitcoin.
93 */
94 def audit(data: AuditData) {
95 summonExpenditure ! data
96 }
97
98 /**
99 * Creates a transaction at current price. Recover
100 * any incomplete transactions if they exist.
101 */
102 def createTx(creator: CreatorTx) {
103 summonLocalDb ! creator
104 }
105
106 /**
107 * Verifies a phone number via sms.
108 * @param phone phone number to verify
109 * @return SMS Minion actor reference
110 */
111 def verifyNumber(phone: Phone) {
112 summonSMS ! phone
113 }
114
115 /**
116 * Saves a phone number to storage.
117 * @param address bitcoin address linked to the phone number
118 * @param phone phone number
119 */
120 def saveNumber(address: String, phone: Phone) {
121 summonPhoneNumber ! (address, phone)
122 }
123
124 /**
125 * Logs in with previously verified phone number.
126 * @param address bitcoin address linked to the phone number
127 */
128 def loginNumber(address: BitcoinAddress) {
129 summonPhoneNumber ! address
130 }
131
132 /**
133 * Sends transaction receipt via email.
134 * @param email email to send to
135 * @param tx completed transaction
136 */
137 def sendReceipt(email: Email, tx: CompleteTx) {
138 summonReceipt ! (email, tx)
139 }
140
141 /**
142 * Sends a message that customer support is on its way
143 * via email.
144 * @param email email address
145 * @param tx incomplete transaction
146 */
147 def sendSupport(email: Email, tx: IncompleteTx) {
148 summonCustomerSupport ! (email, tx)
149 }
150
151 /**
152 * Sends a message that customer support is on its way
153 * via SMS.
154 * @param phone phone number
155 * @param tx incomplete transaction
156 */
157 def sendSupport(phone: Phone, tx: IncompleteTx) {
158 summonCustomerSupport ! (phone, tx)
159 }
160
161 /**
162 * Saves aan email address to storage.
163 * @param address bitcoin address linked to the phone number
164 * @param email email address
165 */
166 def saveReceiptEmail(address: String, email: Email) {
167 summonReceiptEmail ! (address, email)
168 }
169
170 /**
171 * Checks whether inserted bill should be accepted.
172 */
173 def validateBill(inspect: InspectBill) {
174 summonGeneral ! inspect
175 }
176
177 /**
178 * Saves an incomplete tx to local database
179 */
180 def saveTx(tx: IncompleteTx) {
181 summonLocalDb ! tx
182 }
183
184 /**
185 * Gives credit for the confirmed bill.
186 */
187 def confirmBill(confirmed: Confirmed, tx: IncompleteTx) {
188 summonLocalDb ! (confirmed, tx)
189 }
190
191 /**
192 * Once transaction is complete, it does the following:
193 * - saves tx to local database and remove incomplete transaction
194 * - saves tx to Dynamo's Expenditure table
195 * - saves tx to Dynamo's Transaction table
196 */
197 def completeTx(tx: CompleteTx) {
198 summonLocalDb ! tx
199 summonTransaction ! tx
200 summonExpenditure ! tx
201 }
202 }