bitcoin-atm

bitcoin atm for pyc inc.

git clone https://9o.is/git/bitcoin-atm.git

Expenditure.scala

(1172B)


      1 package inc.pyc.chimera
      2 package ddb
      3 
      4 import akka.actor._
      5 import awscala.dynamodbv2._
      6 import org.joda.time._
      7 import format._
      8 
      9 /**
     10  * Save and view the amount of money spent on bitcoin.
     11  * Primary Key is the bitcoin address.
     12  */
     13 class Expenditure extends Actor with ActorLogging with DDB {  
     14   
     15   def receive = {
     16     case tx: CompleteTx =>
     17       table.put(
     18           tx.address, 
     19           tx.dateISO8601, 
     20           "txid" -> tx.txid, 
     21           "paid" -> tx.bills.sum , 
     22           "currency" -> tx.currency.toString)
     23           
     24     case qry @ Past24Hours(addresses) =>
     25       val all = addresses.map ("address" -> Condition.eq(_))
     26       val items = table.query(
     27           keyConditions = (all ::: List("date" -> qry.condition)) toSeq)
     28       sender ! DDBItems(items)
     29   }
     30 }
     31 
     32 /**
     33  * Query to find out how much was spent in buying bitcoin in the past 24 hours.
     34  * @param addresses list of bitcoin addresses to query
     35  */
     36 case class Past24Hours(addresses: List[String]) {
     37   
     38   def condition = Condition.gt(hoursAgo24)
     39   
     40   private def hoursAgo24 = {
     41     val dt = new DateTime(DateTimeZone.UTC).minusDays(1)
     42     val fmt = ISODateTimeFormat.basicDateTime();
     43     fmt.print(dt)
     44   }
     45 }