Example #1
0
 def unpack_and_mint(self, msg):
   """unpacks the request retreiving the number of coins packed and the total value desired.
   Verification: values must be positive!
   """
   self.number, msg = Basic.read_short(msg)
   value, msg = Basic.read_int(msg)
   log_msg('REQUEST:: %s %s'%(self.number, self.hexId), 0)
   if not BankUtil.is_positive_integer(self.number):
     raise ValueError('number of coins must be greater than 0!')
   if value != ACOIN_VALUE or not BankUtil.is_positive_integer(value):
     raise ValueError('coins must have a positive, integer value')
     
   self.bill = 0
   self.signatures = ""
   for i in range(0, self.number):
     #TODO: move to a worker pool or something
     sig = Globals.ACOIN_KEY.decrypt(msg[:Globals.ACOIN_KEY_BYTES], False)
     self.signatures += struct.pack('!%ss'%(Globals.ACOIN_KEY_BYTES), sig)
     msg = msg[Globals.ACOIN_KEY_BYTES:]
     self.bill += value
     
   #TODO: move this constraint to postgres to get rid of any potential race conditions
   sql = "SELECT balance FROM Accounts WHERE Username = %s"
   inj = (self.user,)
   d = db.read(sql, inj)
   return d
Example #2
0
    def unpack_and_mint(self, msg):
        """unpacks the request retreiving the number of coins packed and the total value desired.
    Verification: values must be positive!
    """
        self.number, msg = Basic.read_short(msg)
        value, msg = Basic.read_int(msg)
        log_msg('REQUEST:: %s %s' % (self.number, self.hexId), 0)
        if not BankUtil.is_positive_integer(self.number):
            raise ValueError('number of coins must be greater than 0!')
        if value != ACOIN_VALUE or not BankUtil.is_positive_integer(value):
            raise ValueError('coins must have a positive, integer value')

        self.bill = 0
        self.signatures = ""
        for i in range(0, self.number):
            #TODO: move to a worker pool or something
            sig = Globals.ACOIN_KEY.decrypt(msg[:Globals.ACOIN_KEY_BYTES],
                                            False)
            self.signatures += struct.pack('!%ss' % (Globals.ACOIN_KEY_BYTES),
                                           sig)
            msg = msg[Globals.ACOIN_KEY_BYTES:]
            self.bill += value

        #TODO: move this constraint to postgres to get rid of any potential race conditions
        sql = "SELECT balance FROM Accounts WHERE Username = %s"
        inj = (self.user, )
        d = db.read(sql, inj)
        return d
Example #3
0
 def unpack_and_verify(self, blob):
   """verifies that...
   1. the coin is valid
   2. isn't expired
   3. hasn't been deposited before
   returns one of 4 statements"""
   self.number, blob = Basic.read_short(blob)
   log_msg('DEPOSIT:: %s %s'%(self.number, self.hexId), 0)
   total = 0
   self.returnSlip = ""
   if BankUtil.is_positive_integer(self.number):
     #we don't want the interval to roll over half way through a request
     current = Globals.CURRENT_ACOIN_INTERVAL[0]
     for i in range(self.number):
       result, coin, blob = deposit_acoin(blob, current)
       self.returnSlip += result
       if result == '0':
         total += ACoin.VALUE
   self.amountEarned = total
   return total
Example #4
0
 def unpack_and_verify(self, blob):
     """verifies that...
 1. the coin is valid
 2. isn't expired
 3. hasn't been deposited before
 returns one of 4 statements"""
     self.number, blob = Basic.read_short(blob)
     log_msg('DEPOSIT:: %s %s' % (self.number, self.hexId), 0)
     total = 0
     self.returnSlip = ""
     if BankUtil.is_positive_integer(self.number):
         #we don't want the interval to roll over half way through a request
         current = Globals.CURRENT_ACOIN_INTERVAL[0]
         for i in range(self.number):
             result, coin, blob = deposit_acoin(blob, current)
             self.returnSlip += result
             if result == '0':
                 total += ACoin.VALUE
     self.amountEarned = total
     return total