def learned_current_acoin_interval(tup, onAcoinInterval=None, onNewIntervalCallback=None): #there must be at least one interval if len(tup) != 2: log_ex("Bank ran out of ACoin intervals!", "THIS MUST BE FIXED IMMEDIATELY") return current, next = tup interval = current[0] expires = DBUtil.ctime_to_int(current[1].ctime()) expiresNext = DBUtil.ctime_to_int(next[1].ctime()) #expires is natively a datetime #expires = DBUtil.ctime_to_int(expires.ctime()) Globals.CURRENT_ACOIN_INTERVAL = [interval, expires, expiresNext] if onNewIntervalCallback: onNewIntervalCallback() now = int(time.time()) if Globals.isListening == False: onAcoinInterval() Globals.isListening = True #schedule the next lookup after we know when the interval rolls over lookupTime = expires - now + (MAX_BANK_CLOCK_SKEW) if lookupTime <= 0: lookupTime = EXPIRED_CHECK_INTERVAL Globals.reactor.callLater(lookupTime, update_local_acoin_interval, onAcoinInterval, onNewIntervalCallback)
def _on_learned_hexkey(self, result): """Called when the sql query to retrieve the invite hexkey from the IP cache finishes""" #if there was no entry in the cache if not result: self._reply(RESPONSE_CODES["BAD_EMAIL"]) return #unpack the db result hexKey, eventTime = result[0] eventTime = eventTime.ctime() #if the cache entry is too old if DBUtil.ctime_to_int(eventTime) - DBUtil.ctime_to_int(self.curTime) > CACHE_ENTRY_LIFETIME: self._reply(RESPONSE_CODES["BAD_EMAIL"]) return #otherwise, check if this invite has been redeemed yet sql = "SELECT value, email FROM email_signup_keys WHERE redeemed = FALSE AND value = %s" inj = (hexKey,) redeemedDeferred = self.db.read(sql, inj) redeemedDeferred.addCallback(self._on_learned_invite) redeemedDeferred.addErrback(self._handle_error)
def learned_current_acoin_interval(tup, onAcoinInterval=None, onNewIntervalCallback=None): #there must be at least one interval if len(tup) != 2: log_ex("Bank ran out of ACoin intervals!", "THIS MUST BE FIXED IMMEDIATELY") return current, next = tup interval = current[0] expires = DBUtil.ctime_to_int(current[1].ctime()) expiresNext = DBUtil.ctime_to_int(next[1].ctime()) #expires is natively a datetime #expires = DBUtil.ctime_to_int(expires.ctime()) Globals.CURRENT_ACOIN_INTERVAL = [interval, expires, expiresNext] if onNewIntervalCallback: onNewIntervalCallback() now = int(time.time()) if Globals.isListening == False: onAcoinInterval() Globals.isListening = True #schedule the next lookup after we know when the interval rolls over lookupTime = expires-now + (MAX_BANK_CLOCK_SKEW) if lookupTime <= 0: lookupTime = EXPIRED_CHECK_INTERVAL Globals.reactor.callLater(lookupTime, update_local_acoin_interval, onAcoinInterval, onNewIntervalCallback)
def _on_learned_hexkey(self, result): """Called when the sql query to retrieve the invite hexkey from the IP cache finishes""" #if there was no entry in the cache if not result: self._reply(RESPONSE_CODES["BAD_EMAIL"]) return #unpack the db result hexKey, eventTime = result[0] eventTime = eventTime.ctime() #if the cache entry is too old if DBUtil.ctime_to_int(eventTime) - DBUtil.ctime_to_int( self.curTime) > CACHE_ENTRY_LIFETIME: self._reply(RESPONSE_CODES["BAD_EMAIL"]) return #otherwise, check if this invite has been redeemed yet sql = "SELECT value, email FROM email_signup_keys WHERE redeemed = FALSE AND value = %s" inj = (hexKey, ) redeemedDeferred = self.db.read(sql, inj) redeemedDeferred.addCallback(self._on_learned_invite) redeemedDeferred.addErrback(self._handle_error)
x = raw_input() if x != "y": raise Exception("User aborted.") cur.execute("DELETE FROM acoin_interval WHERE interval_id > %s", (nextInterval,)) tup = get_last_interval() curInterval, curTime = tup[0] print("You deleted ALL intervals after %s (expires at %s). Are you SURE you wanted to do that? (type anything except continue to abort): " % (nextInterval, nextTime.ctime())) x = raw_input() if x != "continue": raise Exception("User aborted.") assert tup assert len(tup) == 1 highestACoinInterval, highestACoinFreshUntil = tup[0] #the freshness is a ctime type... we need to convert it into a float base = DBUtil.ctime_to_int(highestACoinFreshUntil.ctime()) highestACoinInterval = int(highestACoinInterval) sql = [] inj = [] startTime = highestACoinFreshUntil.ctime() startInterval = highestACoinInterval print("Creating intervals...") for x in range(numberOfIntervalsToMake): highestACoinInterval += 1 validAfter, spoilsOn = insert_interval_row(base, highestACoinInterval) #need to update base for next iteration base = spoilsOn print("Created %s interval[s] from time %s to time %s ending with interval: %s"%(highestACoinInterval - 1 - startInterval, startTime, DBUtil.int_to_ctime(spoilsOn), highestACoinInterval - 1)) conn.commit()
cur.execute("DELETE FROM acoin_interval WHERE interval_id > %s", (nextInterval, )) tup = get_last_interval() curInterval, curTime = tup[0] print( "You deleted ALL intervals after %s (expires at %s). Are you SURE you wanted to do that? (type anything except continue to abort): " % (nextInterval, nextTime.ctime())) x = raw_input() if x != "continue": raise Exception("User aborted.") assert tup assert len(tup) == 1 highestACoinInterval, highestACoinFreshUntil = tup[0] #the freshness is a ctime type... we need to convert it into a float base = DBUtil.ctime_to_int(highestACoinFreshUntil.ctime()) highestACoinInterval = int(highestACoinInterval) sql = [] inj = [] startTime = highestACoinFreshUntil.ctime() startInterval = highestACoinInterval print("Creating intervals...") for x in range(numberOfIntervalsToMake): highestACoinInterval += 1 validAfter, spoilsOn = insert_interval_row(base, highestACoinInterval) #need to update base for next iteration base = spoilsOn print( "Created %s interval[s] from time %s to time %s ending with interval: %s"