Exemple #1
0
def wallet(request):
    btcp = BTCProcessor(True)
    b = btcp.check_balance()
    balance = str(to_btc(b[0])) + ' ' + str(to_btc(b[1]))
    wallet_status = {}
    wallet_status['balance'] = balance
    wallet_status['addresses'] = btcp.wallet.addresses()

    return HttpResponse(json.dumps(wallet_status),
                        content_type="application/json")
Exemple #2
0
def index(request):
    params = {}
    configuration = scripts.check_configuration()
    if not configuration:
        params['missing_config'] = True
    else:
        params['configuration'] = configuration
        btc_processor = BTCProcessor(False)
        params['wallet_exists'] = btc_processor.does_wallet_exists()

    return render(request, 'index.html', params)
Exemple #3
0
def check_transaction_status(session_id):
    transaction_status = {}
    try:
        btc_proc = BTCProcessor(True)
        available_coins =  to_btc(float(btc_proc.check_balance()[0]))
        transaction = Transactions.objects.get(session_id=session_id)
        transaction_status['notes_inserted'] = transaction.cash_amount
        transaction_status['btc_amount'] = transaction.btc_amount

    except Transactions.DoesNotExist:
        log_error('check_transaction_status', '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('check_transaction_status', message, session_id=session_id)
    return transaction_status
Exemple #4
0
def check_transaction_status(session_id):
    transaction_status = {}
    try:
        btc_proc = BTCProcessor(True)
        available_coins = to_btc(float(btc_proc.check_balance()[0]))
        transaction = Transactions.objects.get(session_id=session_id)
        transaction_status['notes_inserted'] = transaction.cash_amount
        transaction_status['btc_amount'] = transaction.btc_amount

    except Transactions.DoesNotExist:
        log_error('check_transaction_status',
                  '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('check_transaction_status', message, session_id=session_id)
    return transaction_status
Exemple #5
0
def init_transaction(exchange_rate):
    """
    - Check if a previous session was pending, if found invalidate it
    - Initialize a new transaction with a new session_id
    - Set fixed exchange rate, init_timestamp, availability, session_id
    - Set status: initialized if coins are available, failed if not
    """
    try:
        btcProc = BTCProcessor(True)
        session_id = urandom(16).encode('hex')
        available_coins = to_btc(float(btcProc.check_balance()[0]))
        timestamp = datetime.now()
        config = Configuration.objects.get()
        set_transaction = Transactions(session_id=session_id,
                                       created_on=timestamp,
                                       updated_on=timestamp,
                                       exchange_rate=exchange_rate,
                                       coins_available=available_coins,
                                       currency=config.currency)

        if available_coins > 0:
            set_transaction.status = Transactions.INITIALIZED
            initialized = True
            # surcharge = user_data.surcharge
            # surcharged_exchange_rate = round(float((exchange_rate*surcharge) + exchange_rate), 2)
            set_transaction.max_cash_acceptable = max_acceptable_cash(
                exchange_rate, available_coins)
            # enable qr reader
        else:
            set_transaction.status = Transactions.ABORTED
            initialized = False

        set_transaction.save()
    except:
        exc_info = sys.exc_info()
        message = str(exc_info[0]) + ' - ' + str(exc_info[1])
        log_error('init transaction', message)
    return {
        'initialized': initialized,
        'session_id': session_id,
        'available_coins': available_coins
    }
Exemple #6
0
def init_transaction(exchange_rate):
    """
    - Check if a previous session was pending, if found invalidate it
    - Initialize a new transaction with a new session_id
    - Set fixed exchange rate, init_timestamp, availability, session_id
    - Set status: initialized if coins are available, failed if not
    """
    try:
        btcProc = BTCProcessor(True)
        session_id = urandom(16).encode('hex')
        available_coins =  to_btc(float(btcProc.check_balance()[0]))
        timestamp = datetime.now()
        config = Configuration.objects.get()
        set_transaction = Transactions(session_id=session_id,
                                           created_on=timestamp,
                                           updated_on=timestamp,
                                           exchange_rate=exchange_rate,
                                           coins_available=available_coins,
                                           currency=config.currency
                                           )

        if  available_coins > 0:
            set_transaction.status = Transactions.INITIALIZED
            initialized = True
            # surcharge = user_data.surcharge
            # surcharged_exchange_rate = round(float((exchange_rate*surcharge) + exchange_rate), 2)
            set_transaction.max_cash_acceptable = max_acceptable_cash(exchange_rate, available_coins)
            # enable qr reader
        else:
            set_transaction.status = Transactions.ABORTED
            initialized = False

        set_transaction.save()
    except:
        exc_info = sys.exc_info()
        message = str(exc_info[0]) + ' - ' + str(exc_info[1])
        log_error('init transaction',message)
    return {'initialized': initialized, 'session_id': session_id, 'available_coins': available_coins}
Exemple #7
0
def restore_from_seed(request):
    btcprocessor = BTCProcessor(False)
    seed = request.POST.get('seedToRestore')
    btcprocessor.restore_wallet_from_seed(seed)
    return redirect('/')
Exemple #8
0
def create_wallet(request):
    BTCProcessor(True)
    return redirect('/')
Exemple #9
0
def test(request):
    #FIXME what's this ?
    btcp = BTCProcessor(True)
    t = btcp.broadcast_transaction('1GEQsEtzeUJHVNWR9xt24RMXu676rxGhf5',
                                   0.0003)
    return HttpResponse(json.dumps(t), content_type="application/json")