Example #1
0
 def pay_account(self, account_id, amount):
     "from user account to wild"
     balance = self.get_balance(account_id)
     if amount > balance.balance:
         msg = "Amount %d, current balance %d" % (amount, balance.balance)
         raise InsufficientFundsError, msg
     with transaction.manager:
         acct = self.get_balance(account_id)
         wild = self.get_balance(self.inthewild.id)
         now = datetime.now()
         ttype = self._get_txn_type('withdraw_acct')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         # transfer to wild
         # transfer from account
         to_wild, from_acct = mkdbl_entries(txn,
                                            self.inthewild.id,
                                            account_id,
                                            amount,
                                            now)
         
         #adjust balances
         wild.balance += amount
         acct.balance -= amount
         # update database
         self.session.add(to_wild)
         self.session.add(from_acct)
         acct = self.session.merge(acct)
         wild = self.session.merge(wild)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #2
0
 def take_from_cash(self, amount):
     cash_balance = self.get_balance(self.cash.id).balance
     if cash_balance < amount:
         msg = "Cash balance %d, amount %d" % (cash_balance, amount)
         raise InsufficientFundsError, msg
     with transaction.manager:
         now = datetime.now()
         ttype = self._get_txn_type('withdraw_cash')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         cash = self.get_balance(self.cash.id)
         wild = self.get_balance(self.inthewild.id)
         # transfer to wild and from cash
         to_wild, from_cash = mkdbl_entries(txn,
                                            self.inthewild.id,
                                            self.cash.id,
                                            amount,
                                            now)
         #adjust balances
         wild.balance += amount
         cash.balance -= amount
         # update database
         self.session.add(to_wild)
         self.session.add(from_cash)
         cash = self.session.merge(cash)
         wild = self.session.merge(wild)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #3
0
 def deposit_to_account(self, account_id, amount):
     if amount <= 0:
         raise InsufficientFundsError, 'bad amount %d' % amount
     with transaction.manager:
         acct = self.get_balance(account_id)
         wild = self.get_balance(self.inthewild.id)
         now = datetime.now()
         ttype = self._get_txn_type('deposit_acct')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         # make double entries
         to_acct, from_wild = mkdbl_entries(txn,
                                            account_id,
                                            self.inthewild.id,
                                            amount,
                                            now)
         #adjust balances
         acct.balance += amount
         wild.balance -= amount
         # update database
         self.session.add(to_acct)
         self.session.add(from_wild)
         acct = self.session.merge(acct)
         wild = self.session.merge(wild)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #4
0
    def pay_account(self, account_id, amount):
        "from user account to wild"
        balance = self.get_balance(account_id)
        if amount > balance.balance:
            msg = "Amount %d, current balance %d" % (amount, balance.balance)
            raise InsufficientFundsError, msg
        with transaction.manager:
            acct = self.get_balance(account_id)
            wild = self.get_balance(self.inthewild.id)
            now = datetime.now()
            ttype = self._get_txn_type('withdraw_acct')
            txn = Transaction()
            txn.type_id = ttype.id
            txn.created = now
            self.session.add(txn)
            txn = self.session.merge(txn)
            # transfer to wild
            # transfer from account
            to_wild, from_acct = mkdbl_entries(txn, self.inthewild.id,
                                               account_id, amount, now)

            #adjust balances
            wild.balance += amount
            acct.balance -= amount
            # update database
            self.session.add(to_wild)
            self.session.add(from_acct)
            acct = self.session.merge(acct)
            wild = self.session.merge(wild)
        self._refresh_standard_accounts()
        return self.session.merge(txn)
Example #5
0
 def add_to_cash(self, amount):
     if amount <= 0:
         raise InsufficientFundsError, 'bad amount %d' % amount
     with transaction.manager:
         cash = self.get_balance(self.cash.id)
         wild = self.get_balance(self.inthewild.id)
         now = datetime.now()
         ttype = self._get_txn_type('deposit_cash')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         # transfer to cash and from wild
         to_cash, from_wild = mkdbl_entries(txn,
                                            self.cash.id,
                                            self.inthewild.id,
                                            amount,
                                            now)
         #adjust balances
         cash.balance += amount
         wild.balance -= amount
         # update database
         self.session.add(to_cash)
         self.session.add(from_wild)
         cash = self.session.merge(cash)
         wild = self.session.merge(wild)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #6
0
 def lose_bet(self, amount):
     cash = self.get_balance(self.cash.id)
     wagers = self.get_balance(self.wagers.id)
     juice = self.get_balance(self.juice.id)
     juice_insurance = amount / 10
     total = amount + juice_insurance
     with transaction.manager:
         now = datetime.now()
         ttype = self._get_txn_type('lose_bet')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         payback = amount + amount
         to_cash, from_wagers = mkdbl_entries(txn, self.cash.id,
                                              self.wagers.id, payback, now)
         get_juice, juiced_from = mkdbl_entries(txn, self.cash.id,
                                                self.juice.id,
                                                juice_insurance, now)
         dbobjects = [to_cash, from_wagers, get_juice, juiced_from, txn]
         # adjust balances
         cash.balance += payback
         wagers.balance -= payback
         cash.balance += juice_insurance
         juice.balance -= juice_insurance
         for dbobj in dbobjects:
             self.session.add(dbobj)
         for dbobj in [cash, wagers, juice]:
             self.session.merge(dbobj)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #7
0
 def deposit_to_account(self, account_id, amount):
     if amount <= 0:
         raise InsufficientFundsError, 'bad amount %d' % amount
     with transaction.manager:
         acct = self.get_balance(account_id)
         wild = self.get_balance(self.inthewild.id)
         now = datetime.now()
         ttype = self._get_txn_type('deposit_acct')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         # make double entries
         to_acct, from_wild = mkdbl_entries(txn, account_id,
                                            self.inthewild.id, amount, now)
         #adjust balances
         acct.balance += amount
         wild.balance -= amount
         # update database
         self.session.add(to_acct)
         self.session.add(from_wild)
         acct = self.session.merge(acct)
         wild = self.session.merge(wild)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #8
0
 def take_from_cash(self, amount):
     cash_balance = self.get_balance(self.cash.id).balance
     if cash_balance < amount:
         msg = "Cash balance %d, amount %d" % (cash_balance, amount)
         raise InsufficientFundsError, msg
     with transaction.manager:
         now = datetime.now()
         ttype = self._get_txn_type('withdraw_cash')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         cash = self.get_balance(self.cash.id)
         wild = self.get_balance(self.inthewild.id)
         # transfer to wild and from cash
         to_wild, from_cash = mkdbl_entries(txn, self.inthewild.id,
                                            self.cash.id, amount, now)
         #adjust balances
         wild.balance += amount
         cash.balance -= amount
         # update database
         self.session.add(to_wild)
         self.session.add(from_cash)
         cash = self.session.merge(cash)
         wild = self.session.merge(wild)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #9
0
 def add_to_cash(self, amount):
     if amount <= 0:
         raise InsufficientFundsError, 'bad amount %d' % amount
     with transaction.manager:
         cash = self.get_balance(self.cash.id)
         wild = self.get_balance(self.inthewild.id)
         now = datetime.now()
         ttype = self._get_txn_type('deposit_cash')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         # transfer to cash and from wild
         to_cash, from_wild = mkdbl_entries(txn, self.cash.id,
                                            self.inthewild.id, amount, now)
         #adjust balances
         cash.balance += amount
         wild.balance -= amount
         # update database
         self.session.add(to_cash)
         self.session.add(from_wild)
         cash = self.session.merge(cash)
         wild = self.session.merge(wild)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #10
0
    def place_bet(self, account_id, amount):
        juice_insurance = amount / 10
        total = amount + juice_insurance
        acct = self.get_balance(account_id)
        cash = self.get_balance(self.cash.id)
        if total > acct.balance:
            j = juice_insurance
            a = amount
            b = acct.balance
            msg = "Amount %d, insurance, %d, balance %d" % (a, j, b)
            raise InsufficientFundsError, msg
        if amount > cash.balance:
            msg = "Amount %d, cash balance %d" % (amount, cash.balance)
            raise InsufficientFundsError, msg
        with transaction.manager:
            acct = self.get_balance(account_id)
            wagers = self.get_balance(self.wagers.id)
            juice = self.get_balance(self.juice.id)
            cash = self.get_balance(self.cash.id)
            now = datetime.now()
            ttype = self._get_txn_type('place_bet')
            txn = Transaction()
            txn.type_id = ttype.id
            txn.created = now
            self.session.add(txn)
            txn = self.session.merge(txn)
            # transfer to wager
            # transfer from account
            to_wagers, from_acct = mkdbl_entries(txn, self.wagers.id,
                                                 account_id, amount, now)

            # transfer to juice
            # account covers juice
            to_juice, juiced_from = mkdbl_entries(txn, self.juice.id,
                                                  account_id, juice_insurance,
                                                  now)
            # transfer to wager
            # transfer from cash
            cash_to_wagers, from_cash = mkdbl_entries(txn, self.wagers.id,
                                                      self.cash.id, amount,
                                                      now)
            dbobjects = [
                to_wagers, from_acct, to_juice, juiced_from, cash_to_wagers,
                from_cash, txn
            ]
            #adjust balances
            wagers.balance += amount + amount
            acct.balance -= amount
            cash.balance -= amount
            juice.balance += juice_insurance
            acct.balance -= juice_insurance
            # update database
            for dbobj in dbobjects:
                self.session.add(dbobj)
            for dbobj in [wagers, acct, cash, juice]:
                self.session.merge(dbobj)
        self._refresh_standard_accounts()
        return self.session.merge(txn)
Example #11
0
    def win_bet(self, account_id, amount):
        acct = self.get_balance(account_id)
        wagers = self.get_balance(self.wagers.id)
        juice = self.get_balance(self.juice.id)
        juice_insurance = amount / 10
        total = amount + juice_insurance
        if amount > wagers.balance:
            msg = "Amount %d, balance %d" % (amount, wagers.balance)
            raise InsufficientFundsError, msg
        if juice_insurance > juice.balance:
            msg = "Juice %d, balance %d" % (juice_insurance, juice.balance)
            raise InsufficientFundsError, msg
        with transaction.manager:
            now = datetime.now()
            ttype = self._get_txn_type('win_bet')
            txn = Transaction()
            txn.type_id = ttype.id
            txn.created = now
            self.session.add(txn)
            txn = self.session.merge(txn)
            # transfer to user
            # transfer from wagers
            payout = amount + amount
            to_acct, from_wagers = mkdbl_entries(txn,
                                                 account_id,
                                                 self.wagers.id,
                                                 payout, now)
            

            # juice to user
            # juice from juice
            juiced_to, from_juice = mkdbl_entries(txn,
                                                  account_id,
                                                  self.juice.id,
                                                  juice_insurance,
                                                  now)
            # make object list
            dbobjects = [to_acct, from_wagers, from_juice, juiced_to, txn]
            # adjust balances
            acct.balance += payout
            wagers.balance -= payout
            acct.balance += juice_insurance
            juice.balance -= juice_insurance
            # update database
            for dbobj in dbobjects:
                self.session.add(dbobj)
            for dbobj in [acct, wagers, juice]:
                self.session.merge(dbobj)
        self._refresh_standard_accounts()
        return self.session.merge(txn)
Example #12
0
 def push_bet(self, account_id, amount):
     acct = self.get_balance(account_id)
     cash = self.get_balance(self.cash.id)
     wagers = self.get_balance(self.wagers.id)
     juice = self.get_balance(self.juice.id)
     juice_insurance = amount / 10
     total = amount + juice_insurance
     with transaction.manager:
         now = datetime.now()
         ttype = self._get_txn_type('push_bet')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         wagers_loss = amount + amount
         # transfer from wagers to account
         to_acct, from_wagers = mkdbl_entries(txn,
                                              account_id,
                                              self.wagers.id,
                                              amount,
                                              now)
         # transfer from wagers to cash
         to_cash, cfrom_wagers = mkdbl_entries(txn,
                                               self.cash.id,
                                               self.wagers.id,
                                               amount,
                                               now)
         # transfer from juice to account
         jto_acct, from_juice = mkdbl_entries(txn,
                                              account_id,
                                              self.juice.id,
                                              juice_insurance,
                                              now)
         dbobjects = [to_acct, from_wagers, to_cash, cfrom_wagers,
                      jto_acct, from_juice, txn]
         # adjust balances
         acct.balance += amount
         cash.balance += amount
         wagers.balance -= wagers_loss
         acct.balance += juice_insurance
         juice.balance -= juice_insurance
         for dbobj in dbobjects:
             self.session.add(dbobj)
         for dbobj in [acct, cash, wagers, juice]:
             self.session.merge(dbobj)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #13
0
    def win_bet(self, account_id, amount):
        acct = self.get_balance(account_id)
        wagers = self.get_balance(self.wagers.id)
        juice = self.get_balance(self.juice.id)
        juice_insurance = amount / 10
        total = amount + juice_insurance
        if amount > wagers.balance:
            msg = "Amount %d, balance %d" % (amount, wagers.balance)
            raise InsufficientFundsError, msg
        if juice_insurance > juice.balance:
            msg = "Juice %d, balance %d" % (juice_insurance, juice.balance)
            raise InsufficientFundsError, msg
        with transaction.manager:
            now = datetime.now()
            ttype = self._get_txn_type('win_bet')
            txn = Transaction()
            txn.type_id = ttype.id
            txn.created = now
            self.session.add(txn)
            txn = self.session.merge(txn)
            # transfer to user
            # transfer from wagers
            payout = amount + amount
            to_acct, from_wagers = mkdbl_entries(txn, account_id,
                                                 self.wagers.id, payout, now)

            # juice to user
            # juice from juice
            juiced_to, from_juice = mkdbl_entries(txn, account_id,
                                                  self.juice.id,
                                                  juice_insurance, now)
            # make object list
            dbobjects = [to_acct, from_wagers, from_juice, juiced_to, txn]
            # adjust balances
            acct.balance += payout
            wagers.balance -= payout
            acct.balance += juice_insurance
            juice.balance -= juice_insurance
            # update database
            for dbobj in dbobjects:
                self.session.add(dbobj)
            for dbobj in [acct, wagers, juice]:
                self.session.merge(dbobj)
        self._refresh_standard_accounts()
        return self.session.merge(txn)
Example #14
0
 def push_bet(self, account_id, amount):
     acct = self.get_balance(account_id)
     cash = self.get_balance(self.cash.id)
     wagers = self.get_balance(self.wagers.id)
     juice = self.get_balance(self.juice.id)
     juice_insurance = amount / 10
     total = amount + juice_insurance
     with transaction.manager:
         now = datetime.now()
         ttype = self._get_txn_type('push_bet')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         wagers_loss = amount + amount
         # transfer from wagers to account
         to_acct, from_wagers = mkdbl_entries(txn, account_id,
                                              self.wagers.id, amount, now)
         # transfer from wagers to cash
         to_cash, cfrom_wagers = mkdbl_entries(txn, self.cash.id,
                                               self.wagers.id, amount, now)
         # transfer from juice to account
         jto_acct, from_juice = mkdbl_entries(txn, account_id,
                                              self.juice.id,
                                              juice_insurance, now)
         dbobjects = [
             to_acct, from_wagers, to_cash, cfrom_wagers, jto_acct,
             from_juice, txn
         ]
         # adjust balances
         acct.balance += amount
         cash.balance += amount
         wagers.balance -= wagers_loss
         acct.balance += juice_insurance
         juice.balance -= juice_insurance
         for dbobj in dbobjects:
             self.session.add(dbobj)
         for dbobj in [acct, cash, wagers, juice]:
             self.session.merge(dbobj)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #15
0
 def lose_bet(self, amount):
     cash = self.get_balance(self.cash.id)
     wagers = self.get_balance(self.wagers.id)
     juice = self.get_balance(self.juice.id)
     juice_insurance = amount / 10
     total = amount + juice_insurance
     with transaction.manager:
         now = datetime.now()
         ttype = self._get_txn_type('lose_bet')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         payback = amount + amount
         to_cash, from_wagers = mkdbl_entries(txn,
                                              self.cash.id,
                                              self.wagers.id,
                                              payback,
                                              now)
         get_juice, juiced_from = mkdbl_entries(txn,
                                                self.cash.id,
                                                self.juice.id,
                                                juice_insurance,
                                                now)
         dbobjects = [to_cash, from_wagers, get_juice, juiced_from, txn]
         # adjust balances
         cash.balance += payback
         wagers.balance -= payback
         cash.balance += juice_insurance
         juice.balance -= juice_insurance
         for dbobj in dbobjects:
             self.session.add(dbobj)
         for dbobj in [cash, wagers, juice]:
             self.session.merge(dbobj)
     self._refresh_standard_accounts()
     return self.session.merge(txn)
Example #16
0
 def place_bet(self, account_id, amount):
     juice_insurance = amount / 10
     total = amount + juice_insurance
     acct = self.get_balance(account_id)
     cash = self.get_balance(self.cash.id)
     if total > acct.balance:
         j = juice_insurance
         a = amount
         b = acct.balance
         msg = "Amount %d, insurance, %d, balance %d" % (a, j, b)
         raise InsufficientFundsError, msg
     if amount > cash.balance:
         msg = "Amount %d, cash balance %d" % (amount, cash.balance)
         raise InsufficientFundsError, msg
     with transaction.manager:
         acct = self.get_balance(account_id)
         wagers = self.get_balance(self.wagers.id)
         juice = self.get_balance(self.juice.id)
         cash = self.get_balance(self.cash.id)
         now = datetime.now()
         ttype = self._get_txn_type('place_bet')
         txn = Transaction()
         txn.type_id = ttype.id
         txn.created = now
         self.session.add(txn)
         txn = self.session.merge(txn)
         # transfer to wager
         # transfer from account
         to_wagers, from_acct = mkdbl_entries(txn,
                                              self.wagers.id,
                                              account_id,
                                              amount,
                                              now)
         
         # transfer to juice
         # account covers juice
         to_juice, juiced_from = mkdbl_entries(txn,
                                               self.juice.id,
                                               account_id,
                                               juice_insurance,
                                               now)
         # transfer to wager
         # transfer from cash
         cash_to_wagers, from_cash = mkdbl_entries(txn,
                                                   self.wagers.id,
                                                   self.cash.id,
                                                   amount,
                                                   now)
         dbobjects = [to_wagers, from_acct, to_juice, juiced_from,
                      cash_to_wagers, from_cash, txn]
         #adjust balances
         wagers.balance += amount + amount
         acct.balance -= amount
         cash.balance -= amount
         juice.balance += juice_insurance
         acct.balance -= juice_insurance
         # update database
         for dbobj in dbobjects:
             self.session.add(dbobj)
         for dbobj in [wagers, acct, cash, juice]:
             self.session.merge(dbobj)
     self._refresh_standard_accounts()
     return self.session.merge(txn)