Пример #1
0
def confirm_payment(request):
    try:
        res = {}
        session_id = request.session['session_id']
        if not session_id:
            res['message'] = 'Invalid session id'
        if request.method == 'POST':
            #notes_reader_command_message_queue.put(True)
            time.sleep(2)
            notes_reader_status = {}
            transaction = Transactions.objects.get(session_id=session_id)
            notes_reader_status['notes_inserted'] = transaction.cash_amount
            notes_reader_status['btc_amount'] = transaction.btc_amount
            tx_result = scripts.broadcast_transaction(session_id)
            res = notes_reader_status
        else:
            return HttpResponseServerError(json.dumps(
                {'error':
                 "can't broadcast transaction - invalid http method"}),
                                           content_type="application/json")

        return HttpResponse(json.dumps(res), content_type="application/json")

    except Transactions.DoesNotExist:
        log_error('confirm_payment',
                  'transaction does not exists',
                  session_id=session_id)
    except:
        exc_info = sys.exc_info()
        message = str(exc_info[0]) + ' - ' + str(exc_info[1])
        log_error('confirm_payment', message, session_id=session_id)
        return HttpResponseServerError(json.dumps(
            {'error': "can't broadcast transaction"}),
                                       content_type="application/json")
Пример #2
0
    def check_balance(self):
        try:
            self.wallet.start_threads(self.network)
            self.wallet.update()
            balance = self.wallet.get_account_balance(self.wallet.accounts.get('Main account'))
        except:
            exc_info = sys.exc_info()
            message = str(exc_info[0]) + ' - ' + str(exc_info[1])
            utils.log_error('btc processor check balance', message)
            raise

        return balance
Пример #3
0
    def check_balance(self):
        try:
            self.wallet.start_threads(self.network)
            self.wallet.update()
            balance = self.wallet.get_account_balance(
                self.wallet.accounts.get('Main account'))
        except:
            exc_info = sys.exc_info()
            message = str(exc_info[0]) + ' - ' + str(exc_info[1])
            utils.log_error('btc processor check balance', message)
            raise

        return balance
Пример #4
0
    def broadcast_transaction(self, dest_address, amount):
        try:
            satoshis_amount = utils.to_satoshis(float(amount))
            self.wallet.start_threads(self.network)
            tx = self.wallet.mktx([(dest_address, satoshis_amount)], self.__password__(), self.transaction_fee)
            res = self.wallet.sendtx(tx)
        except:
            exc_info = sys.exc_info()
            message = str(exc_info[0]) + ' - ' + str(exc_info[1])
            utils.log_error('btc processor broadcast transaction', message)
            raise

        return res # returns (Bool, transaction id)
Пример #5
0
    def broadcast_transaction(self, dest_address, amount):
        try:
            satoshis_amount = utils.to_satoshis(float(amount))
            self.wallet.start_threads(self.network)
            tx = self.wallet.mktx([(dest_address, satoshis_amount)],
                                  self.__password__(), self.transaction_fee)
            res = self.wallet.sendtx(tx)
        except:
            exc_info = sys.exc_info()
            message = str(exc_info[0]) + ' - ' + str(exc_info[1])
            utils.log_error('btc processor broadcast transaction', message)
            raise

        return res  # returns (Bool, transaction id)
Пример #6
0
def check_notes_reader_status(request):
    session_id = request.session['session_id']
    try:
        transaction_status = scripts.check_transaction_status(session_id)
        return HttpResponse(json.dumps(transaction_status),
                            content_type="application/json")
    except Transactions.DoesNotExist:
        log_error('check_notes_reader_status',
                  'transaction does not exists',
                  session_id=session_id)
        raise
    except:
        exc_info = sys.exc_info()
        message = str(exc_info[0]) + ' - ' + str(exc_info[1])
        log_error('check_notes_reader_status', message, session_id=session_id)
        raise
Пример #7
0
    def create_or_load_wallet(self):
        wallet = Wallet(self.storage)
        if not self.storage.file_exists:
            try:
                seed = wallet.make_seed()
                wallet.init_seed(seed)
                wallet.save_seed(self.__password__())
                wallet.synchronize()
                config_entry = Configuration.objects.get()
                config_entry.wallet_seed = str(seed)
                config_entry.save()
            except Exception:
                exc_info = sys.exc_info()
                message = str(exc_info[0]) + ' - ' + str(exc_info[1])
                utils.log_error('btc processor create or load wallet', message)

        return wallet
Пример #8
0
    def create_or_load_wallet(self):
        wallet = Wallet(self.storage)
        if not self.storage.file_exists:
            try:
                seed = wallet.make_seed()
                wallet.init_seed(seed)
                wallet.save_seed(self.__password__())
                wallet.synchronize()
                config_entry = Configuration.objects.get()
                config_entry.wallet_seed = str(seed)
                config_entry.save()
            except Exception:
                exc_info = sys.exc_info()
                message = str(exc_info[0]) + ' - ' + str(exc_info[1])
                utils.log_error('btc processor create or load wallet', message)

        return wallet
Пример #9
0
    def __init__(self, command_queue, session_id, available_coins):
        self.command_queue = command_queue
        self.session_id = session_id
        self.inserted_cash = 0
        self.surcharge = 0
        self.available_coins = available_coins
        self.btc_amount = 0

        try:
            self.transaction = Transactions.objects.get(session_id=self.session_id)
            self.transaction.status = Transactions.INSERTING_CASH
            self.transaction.updated_on = datetime.now()
            self.initial_max_acceptable_cash = self.transaction.max_cash_acceptable
            self.transaction.save()
        except Transactions.DoesNotExist:
            log_error('Notes reader', 'transaction ' + self.session_id + ' does not exists')
            raise

        try:
            configuration = Configuration.objects.get()
            self.config_surcharge = configuration.surcharge
        except Configuration.DoesNotExist:
            log_error('Notes reader', 'Configuration not found.')
            raise