示例#1
0
def pay(keyid, sats):

    keydata = get_keydata(keyid)

    if keydata:
        invoice = generate_invoice(sats, keyid)['bolt11']
        register_payment(keyid, invoice, "inc", get_req_ip())

        key_status = keydata['status']
        if key_status in ['subscribed']:
            result = {"cid": keyid, "invoice": invoice}
        else:
            result = {"error": "error message - key status is not subscribed"}
    else:
        result = {"error": "no such key", "action": "key record created"}
        add_key(keyid)

    return jsonify(result)
示例#2
0
def topup(host, sats):

    hostdata = get_hostdata(host)

    if hostdata:
        invoice = generate_invoice(sats, host)['bolt11']
        register_payment(hostdata['name'], invoice, "topup", get_req_ip())

        host_status = hostdata['status']
        if host_status == 'subscribed':
            result = {"host": host, "invoice": invoice}
        else:
            result = {"error": "host is expired or not yet initialized"}

    else:
        result = {
            "error": "no such host",
        }

    return jsonify(result)
示例#3
0
def create_vps(image):

    setup_fee = 0

    if image in MARKET:
        setup_fee = 9900

        if not check_k8s():
            return jsonify({"error": 'out of stock'})

        name = 'm-' + getStar()
        inc = 0

        while get_hostdata(name):
            inc += 1
            name = 'm-' + getStar() + '-' + str(inc)

        add_host(name, get_random_string(12), 'init', image,
                 get_username(image))

        invoice = generate_invoice(setup_fee + 99, name)['bolt11']

        result = {
            "host":
            name,
            "price":
            "<1 sat/min",
            "setup_fee":
            setup_fee,
            "paytostart":
            invoice,
            "disclaimer":
            "If you pay the LN invoice, you agree with terms of service: any abuse usage is prohibited."
            " Your instance may be stopped and/or destroyed at any time without any reason. Do backups."
            " Your data is securely encrypted and instances hosted in enterprise datacenters."
            " Your digital identifiers are saved for authorization purposes."
            " Bitclouds never use your data for any purpose except mentioned above.",
            "support":
            "https://support.bitclouds.sh"
        }

        register_payment(name, invoice, "new", get_req_ip())
        return jsonify(result)
    elif image in ALL_IMAGES:
        name = getStar()
        inc = 0

        while get_hostdata(name):
            inc += 1
            name = getStar() + '-' + str(inc)

        add_host(name, get_random_string(12), 'init', image,
                 get_username(image))

        if image == 'lnd':
            setup_fee = 900
        elif image == 'bitcoind':
            setup_fee = 900
        elif image in ['debian', 'ubuntu', 'centos']:
            setup_fee = 0

        invoice = generate_invoice(setup_fee + 99, name)['bolt11']

        result = {
            "host":
            name,
            "price":
            "<1 sat/min",
            "setup_fee":
            setup_fee,
            "performance":
            "1xXeon-2GB-40GB",
            "paytostart":
            invoice,
            "disclaimer":
            "If you pay the LN invoice, you agree with terms of service: any abuse usage is prohibited."
            " Your instance may be stopped and/or destroyed at any time without any reason. Do backups."
            " Your data is securely encrypted and instances hosted in enterprise datacenters."
            " Your digital identifiers are saved for authorization purposes."
            " Bitclouds never use your data for any purpose except mentioned above.",
            "support":
            "https://support.bitclouds.sh"
        }

        register_payment(name, invoice, "new", get_req_ip())

        return jsonify(result)
    else:
        return {"error": 'no such image'}