def pay_daily_reward_tx(reward_account, character_coins_account): dest_transfer = Account_transfer.get_by_key_name(str(character_coins_account.key()), parent=reward_account) #str(reward_account.key()) if not dest_transfer: amount = random.randint(25, 75) transfer = accountController.transfer_currency(todays_reward.coins_account, character_coins_account, amount) return transfer return None
def _tx(): dest_transfer = Account_transfer.get_by_key_name(str(source_transfer.key()), parent=source_transfer.counter_account.key()) if not dest_transfer: dest_transfer = Account_transfer( parent = source_transfer.counter_account.key(), key_name = str(source_transfer.key()), self_account = source_transfer.counter_account, counter_account = source_transfer.key().parent(), #same as source_transfer.counter_account counter_transfer = source_transfer, currency_type = source_transfer.currency_type, amount = -source_transfer.amount, is_committed = True) account = Account.get(dest_transfer.self_account.key()) account.balance += source_transfer.amount # add negative amount db.put([account, dest_transfer]) return dest_transfer
def execute_uncommitted_account_transfers(self, count): rolled_count = 0 cutoff = datetime.utcnow() - timedelta(seconds=30) q = Account_transfer.all().filter("is_committed =", False).filter("timestamp <", cutoff) for transfer in q.fetch(count): self.roll_forward_account_transfer(transfer) rolled_count += 1 return rolled_count
def transfer_currency(self, source, target, amount): if source.balance < amount and not source.negative_balance_allowed: return None if source.currency_type != target.currency_type: return None source.balance -= amount transfer = Account_transfer(parent=source, key_name=str(target.key()), self_account=source, counter_account=target, counter_transfer=None, currency_type=source.currency_type, amount=amount, is_committed = False) db.put([source, transfer]) return transfer