예제 #1
0
파일: api.py 프로젝트: fiatjaf/bitclouds.sh
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('image')
        args = parser.parse_args()
        dtime = datetime.datetime.strftime(datetime.datetime.now(),
                                           '%Y-%m-%d %H:%M:%S')
        try:
            host_type = args['image']
        except KeyError as e:
            print(dtime + ' no data ' + str(e))
            return False

        if host_type:
            addr_info = requests.post(wallet_host + '/newaddr',
                                      data={"image": host_type})

            if addr_info.status_code == 200:
                info = addr_info.json()

            invoice_data = invoice(amount=0.03,
                                   cur='EUR',
                                   desc=info['address'])
            id = invoice_data['id']
            bolt = invoice_data['payreq']
            register_webhook(id, wallet_host + '/chargify')

            result = {"host": info['address'], "paytostart": bolt}

            return result
        else:
            return False
예제 #2
0
파일: api.py 프로젝트: fiatjaf/bitclouds.sh
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('host')
        parser.add_argument('sats')
        args = parser.parse_args()

        isamount = False

        host = args['host']
        if not host:
            return {"error": "provide host id (bitcoin address)"}

        sats = args['sats']

        try:
            if int(sats) > 0:
                isamount = True
            else:
                isamount = False
        except Exception as e:
            pass

        if host:
            if not isamount:
                invoice_data = invoice(amount=0.03, cur='EUR', desc=str(host))
                print("generating invoice for 0.03 EUR desc=" + host)
            elif isamount:
                print(sats)
                invoice_data = invoice(msat=int(sats) * 1000, desc=str(host))
                print("generating invoice for " + str(sats) + " sats desc=" +
                      str(host))

            print(invoice_data)
            id = invoice_data['id']
            bolt = invoice_data['payreq']
            register_webhook(id, wallet_host + '/chargify')

            result = {"invoice": bolt}

            return result
        else:
            return False
예제 #3
0
def support(address, contact, msg, premium):
    if len(msg) > 300:
        formatted_msg = msg[:300]
    else:
        formatted_msg = msg
    if premium == 'urgent':
        desc = '$[support BitClouds.sh] | ' + address + ' | ' + contact + ':~ ' + formatted_msg
        invoice_data = invoice(amount=0.00009999, cur='BTC', desc=desc)
    elif premium == 'regular':
        desc = '*[support BitClouds.sh] | ' + address + ' | ' + contact + ':~ ' + formatted_msg
        invoice_data = invoice(amount=0.00000099, cur='BTC', desc=desc)

    id = invoice_data['id']
    bolt = invoice_data['payreq']
    register_webhook(id, wallet_host + '/support')

    result = {
        "paytosend": bolt
    }
    return jsonify(result)
예제 #4
0
def topup(host, sats):
    desc = 'BitClouds.sh: ' + str(host)
    if sats == 0:
        invoice_data = invoice(amount=0.03, cur='EUR', desc=desc)
        print("generating invoice for 0.03 EUR desc=" + host)
    else:
        print(sats)
        invoice_data = invoice(msat=int(sats)*1000, desc=desc)
        print("generating invoice for " + str(sats) + " sats desc=" + desc)

    print(invoice_data)
    id = invoice_data['id']
    bolt = invoice_data['payreq']
    register_webhook(id, wallet_host + '/chargify')

    result = {
        "invoice": bolt
    }

    return jsonify(result)
예제 #5
0
def create_vps(image):
    if image in ['debian', 'centos', 'ubuntu', 'bitcoind', 'lightningd', 'rootshell', 'vpn', 'pay2exec']:
        addr_info = requests.post(wallet_host + '/newaddr', data={"image": image})
        if addr_info.status_code != 200:
            return addr_info.status_code
        info = addr_info.json()
        desc = 'BitClouds.sh: ' + info['address']
        invoice_data = invoice(amount=0.00000420, cur='BTC', desc=desc)
        id = invoice_data['id']
        bolt = invoice_data['payreq']
        register_webhook(id, wallet_host + '/chargify')

        result = {
            "host": info['address'],
            "paytostart": bolt
        }

        return jsonify(result)
    else:
        return {'error': 'no such image'}
예제 #6
0
def create_invoice(addr, amount, fast=False):
    dtime = datetime.datetime.strftime(datetime.datetime.now(),
                                       '%Y-%m-%d %H:%M:%S')
    hash = blake2b(digest_size=8)
    hash.update(str.encode(dtime + addr + str(amount)))
    order_id = hash.hexdigest()[:5]

    fee_sat = int(fees['service'])
    ltc_network_fee = int(fees['ltc'])

    ### pay for all needed computations

    def getfastfee():
        inv_count = 0
        receiver_dict_optimized = dict()

        for inv in processing:
            inv_count += 1

            order_data = processing[inv]
            try:
                receiver_dict_optimized[
                    order_data['address']] += order_data['amount_btc']
            except KeyError as e:
                receiver_dict_optimized[
                    order_data['address']] = order_data['amount_btc']

        final_output_count = 0

        for receiver in receiver_dict_optimized:
            final_output_count += 1

        if final_output_count == 0:
            final_output_count = 1

        total_kb = (100 + (final_output_count * 50)) / 1000
        fee_urgent = fees['btc_full']['perkb']['normal']

        per_client_fee = fees['btc']
        expected_tx_fee = fee_urgent * total_kb
        collected_fees = final_output_count * fees['btc']

        fast_fee = expected_tx_fee - (expected_tx_fee - collected_fees)

        return fast_fee

    ####

    #fee per one user
    if not fast:
        btc_network_fee = int(fees['btc'])
    else:
        btc_network_fee = getfastfee()

    if addr.startswith("L") or addr.startswith("M") or addr.startswith("ltc1"):
        fast = True
        #THIS IS FOR LITECOIN

        return {'error': 'litecoin support currently paused due to no demand'}

        valid = lvalidate(addr, ltc_wallet)
        if valid != 'true':
            return {'error': 'wrong address'}

        ltc_price = rates['ltcbtc'] * 1.005

        satoshis = round((float(ltc_price) * float(amount)) * 100000000)

        if satoshis > max_amount_sat:
            return {
                'error':
                'maximum amount is 1 000 000 satoshi (' +
                "{:.4f}".format(round(0.01 / ltc_price, 4)) + ' LTC)'
            }

        lites = round(float(amount) * 100000000)
        network_fee_sat = round(float(ltc_network_fee) * ltc_price)
        msat = round(satoshis * 1000 + fee_sat * 1000 + network_fee_sat * 1000)
        currency = 'LTC'
    else:
        #THIS IS FOR BITCOIN
        valid = bvalidate(addr, btc_wallet)
        if valid != 'true':
            return {'error': 'wrong address'}

        satoshis = round(float(amount) * 100000000)

        lites = False

        def split_invoices():
            dm = divmod(satoshis, max_amount_sat)
            modulus = dm[0]
            amount_left = dm[1]
            if amount_left > 0:
                total_invoices = modulus + 1
            else:
                total_invoices = modulus

            result = {
                "total_invoices": total_invoices,
                "amount_left": amount_left
            }

            return result

        network_fee_sat = btc_network_fee

        msat = round(satoshis * 1000 + fee_sat * 1000 + network_fee_sat * 1000)
        currency = 'BTC'

        if satoshis > max_amount_sat:
            # divide large amount into multiple smaller ones

            #return {'error': 'maximum amount is 1 000 000 satoshi (0.01 BTC)'}
            splitted = split_invoices()

            invoice_count = splitted['total_invoices']
            amount_left = splitted['amount_left']

            counter = 1
            invoices_list = list()

            while counter <= invoice_count:
                #while all whole amounts are divided, create invoices
                #as a separate invoice create what left
                dtime = datetime.datetime.strftime(datetime.datetime.now(),
                                                   '%Y-%m-%d %H:%M:%S')

                counter += 1
                if counter != invoice_count:
                    msat = round(max_amount_sat * 1000 + fee_sat * 1000 +
                                 (network_fee_sat / invoice_count) * 1000) + 3
                    splitted_order_fast = False
                else:
                    msat = round(amount_left * 1000 + fee_sat * 1000 +
                                 getfastfee() * 1000) + 3
                    splitted_order_fast = fast

                inv = invoice(msat=msat,
                              desc='Boost tx of ' + str(amount) + ' to ' +
                              addr + '(id:' + order_id + ')')
                if inv:
                    payreq = inv['payreq']
                    id = inv['id']
                    register_webhook(id, charge_callbacks)
                    if counter != invoice_count:
                        new_invoice(dtime, order_id, addr, max_amount_sat, id,
                                    payreq)
                    else:
                        new_invoice(dtime, order_id, addr, amount_left, id,
                                    payreq)

                    order = {
                        'order_id':
                        order_id,
                        'charge_id':
                        id,
                        'bolt11':
                        payreq,
                        'fee_satoshi':
                        fee_sat,
                        'network_fee_sat':
                        round(network_fee_sat / invoice_count) + 3,
                        'tobe_paid_satoshi':
                        str(round(msat / 1000)),
                        'receiver':
                        addr,
                        'fast':
                        fast,
                        'receiver_amount':
                        str(amount),
                        'receiver_currency':
                        currency
                    }
                    invoices_list.append(order)
                    current_orders.append(order)
                else:
                    return {
                        'error':
                        'something went completely wrong. please contact developer!'
                    }
            #FINALLY, return bunch of invoices
            return {"invoices": invoices_list}

    print('generating invoice for msat:' + str(msat))
    inv = invoice(msat=msat,
                  desc='Boost tx of ' + str(amount) + ' to ' + addr + '(id:' +
                  order_id + ')')
    if inv:
        payreq = inv['payreq']
        id = inv['id']
        register_webhook(id, charge_callbacks)
        if lites:
            satoshis = lites
        new_invoice(dtime, order_id, addr, satoshis, id, payreq)
        order = {
            'order_id': order_id,
            'charge_id': id,
            'bolt11': payreq,
            'fee_satoshi': fee_sat,
            'network_fee_sat': network_fee_sat,
            'tobe_paid_satoshi': str(round(msat / 1000)),
            'receiver': addr,
            'fast': fast,
            'receiver_amount': str(amount),
            'receiver_currency': currency
        }
        if lites:
            order['exchange_ltcbtc'] = "{:.8f}".format(ltc_price)

        invoices = list()
        invoices.append(order)
        current_orders.append(order)
        return {"invoices": invoices}
    else:
        return False
예제 #7
0
from charge import getinfo, invoice, register_webhook

nodeinfo = getinfo()
print('using node: ' + nodeinfo['alias'] + '(' + str(nodeinfo['blockheight']) +
      ', peers: ' + str(nodeinfo['num_peers']) + ')')
inv = invoice(amount=1, desc='testing charge')
print("\n\n==== INVOICE =====\n\n" + inv['payreq'] +
      "\n\n===================\n")
print("==== URL ====")
print(
    'https://api.qrserver.com/v1/create-qr-code/?size=300x300&data=lightning:'
    + inv['payreq'])
print("=============")

if register_webhook(inv['id'], 'https://cb.yaya.cf/charge'):
    print('registered webhook for ' + inv['id'])
else:
    print('failed to register webhook for ' + inv['id'])
예제 #8
0
from charge import invoice

dbclient = pymongo.MongoClient('localhost')
mongo_db = "hosting"
mongo = dbclient[mongo_db]

hosts = mongo.hosts.find()

txs = mongo.txs.find()

hetzners = mongo.hetzner.find()

arg = sys.argv[1]

if arg == 'list':
    for host in hosts:
        print(host)

    for tx in txs:
        print(tx)

    for server in hetzners:
        print(server)

elif arg == 'del':
    dbclient.drop_database(mongo_db)

elif arg == 'inv':
    invoice_data = invoice(msat=1000, desc="test")
    print(invoice_data)