Example #1
0
def _options_vpn(provider):
    name, _ = provider.get_metadata()
    print(("Options for %s:\n" % name))
    options = provider.get_options()

    # Print heading
    row = "{:18}" * 6
    print(
        row.format("Name", "Protocol", "Bandwidth", "Speed",
                   "Est. Price (mBTC)", "Price (USD)"))

    for option in options:
        bandwidth = "Unlimited" if option.bandwidth == sys.maxsize else str(
            option.bandwidth)
        speed = "Unlimited" if option.speed == sys.maxsize else option.speed

        # Calculate the estimated price
        rate = wallet_util.get_rate("USD")
        fee = wallet_util.get_network_fee()
        gateway = provider.get_gateway()
        estimate = gateway.estimate_price(option.price * rate) + fee  # BTC
        estimate = round(1000 * estimate, 2)  # mBTC

        print(
            row.format(option.name, option.protocol, bandwidth, speed,
                       str(estimate), str(option.price)))
Example #2
0
def _options_vps(p):
    name, _ = p.get_metadata()
    print(("Options for %s:\n" % name))
    options = p.get_options()

    # Print heading
    row = "{:<5}" + "{:20}" * 8
    print(
        row.format("#", "Name", "Cores", "Memory (GB)", "Storage (GB)",
                   "Bandwidth", "Connection (Gbit/s)", "Est. Price (mBTC)",
                   "Price (USD)"))

    for i, option in enumerate(options):
        bandwidth = "Unlimited" if option.bandwidth == sys.maxsize else str(
            option.bandwidth)

        # Calculate the estimated price
        rate = wallet_util.get_rate("USD")
        fee = wallet_util.get_network_fee()
        gateway = p.get_gateway()
        estimate = gateway.estimate_price(option.price * rate) + fee  # BTC
        estimate = round(1000 * estimate, 2)  # mBTC

        print(
            row.format(i, option.name, str(option.cores), str(option.memory),
                       str(option.storage), bandwidth, str(option.connection),
                       str(estimate), str(option.price)))
Example #3
0
    def pay(self, wallet, url):

        self._browser.open(url)
        soup = self._browser.get_current_page()
        address = soup.select_one("div.transaction > input").get("value")
        amount = float(soup.select_one("div.transaction > input:nth-of-type(2)").get("value"))
        fee = wallet_util.get_network_fee()
        print(('Calculated fee: %s' % fee))
        transaction_hash = wallet.pay(address, amount, fee)
        print('Done purchasing')
        return transaction_hash
Example #4
0
    def pay(cls, wallet, gateway, url):
        """Do a payment (should be moved to the payment gateways?)

        :param wallet: the wallet to pay with
        :param gateway: gateway through which to make the payment
        :param url: url from which the amount and address can be extracted
        """
        name, _ = cls.get_metadata()

        # Make the payment
        print("Purchasing {} instance".format(name))
        info = gateway.extract_info(url)
        print(('Paying %s BTC to %s' % (info.amount, info.address)))
        fee = wallet_util.get_network_fee()
        print(('Calculated fee: %s' % fee))
        transaction_hash = wallet.pay(info.address, info.amount, fee)
        print('Done purchasing')
        return transaction_hash
Example #5
0
def get_network_fee():
    return wallet_util.get_network_fee()