Exemplo n.º 1
0
def start_cpu_mining(username, client, wallet, prefix='mining'):
    """ Mine bitcoin on the command line by using the CPU of the system.

    Note that this is primarily used to rate limit mining
    advances. CPU mining, or foreground mining, is when the pool sets
    the difficulty very low and the CPU finds a valid solution.

    Args:
        username (str): username from .two1/two1.json
    """
    enonce1, enonce2_size, reward = set_payout_address(client, wallet)

    start_time = time.time()
    ux(prefix + '_start', username, reward)

    # gets work from the server
    work = get_work(client)

    # kicks off cpu miner to find a solution
    found_share = mine_work(work, enonce1=enonce1, enonce2_size=enonce2_size)

    paid_satoshis = save_work(client, found_share)

    end_time = time.time()
    duration = end_time - start_time

    ux(prefix + '_success', username, paid_satoshis, duration, fg='magenta')

    ux(prefix + '_status')
    status.status_wallet(client, wallet)

    status21 = click.style("21 status", bold=True)
    buy21 = click.style("21 buy", bold=True)
    ux(prefix + '_finish', status21, buy21)
Exemplo n.º 2
0
def start_cpu_mining(config):
    """Mine at the CPU.
    >>> from two1.commands.config import Config
    >>> config = Config()
    >>> start_cpu_mining(config)
    """

    client = rest_client.TwentyOneRestClient(cmd_config.TWO1_HOST,
                                             config.machine_auth,
                                             config.username)

    enonce1, enonce2_size, reward = set_payout_address(config, client)

    start_time = time.time()
    config.log(UxString.mining_start.format(config.username, reward))

    work = get_work(config, client)

    found_share = mine_work(work, enonce1=enonce1, enonce2_size=enonce2_size)

    paid_satoshis = save_work(client, found_share, config.username)

    end_time = time.time()
    duration = end_time - start_time

    config.log(UxString.mining_success.format(config.username, paid_satoshis,
                                              duration),
               fg="magenta")

    click.echo(UxString.mining_status)
    status.status_wallet(config, client)

    click.echo(
        UxString.mining_finish.format(click.style("21 status", bold=True),
                                      click.style("21 buy", bold=True)))
Exemplo n.º 3
0
def start_cpu_mining(username, client, wallet, prefix="mining"):
    """ Mine bitcoin on the command line by using the CPU of the system.

    Note that this is primarily used to rate limit mining
    advances. CPU mining, or foreground mining, is when the pool sets
    the difficulty very low and the CPU finds a valid solution.

    Args:
        username (str): username from .two1/two1.json
    """
    enonce1, enonce2_size, reward = set_payout_address(client, wallet)

    start_time = time.time()
    ux(prefix + "_start", username, reward)

    # gets work from the server
    work = get_work(client)

    # kicks off cpu miner to find a solution
    found_share = mine_work(work, enonce1=enonce1, enonce2_size=enonce2_size)

    paid_satoshis = save_work(client, found_share)

    end_time = time.time()
    duration = end_time - start_time

    ux(prefix + "_success", username, paid_satoshis, duration, fg="magenta")

    ux(prefix + "_status")
    status.status_wallet(client, wallet)

    status21 = click.style("21 status", bold=True)
    buy21 = click.style("21 buy", bold=True)
    ux(prefix + "_finish", status21, buy21)
 def doFlush(self):
     pre_flush_wallet = status.status_wallet(client, wallet)
     flush_response = flush._flush(conf, client)
     print(flush_response)
     status_wallet = status.status_wallet(client, wallet)
     if pre_flush_wallet['wallet']['twentyone_balance'] != status_wallet['wallet']['twentyone_balance']:
         return "Flush successful!"
     else:
         return "Flush error or less than 20000 OffChain Satoshis"
Exemplo n.º 5
0
 def doFlush(self):
     pre_flush_wallet = status.status_wallet(client, wallet)
     flush_response = flush._flush(conf, client)
     print(flush_response)
     status_wallet = status.status_wallet(client, wallet)
     if pre_flush_wallet['wallet']['twentyone_balance'] != status_wallet[
             'wallet']['twentyone_balance']:
         return "Flush successful!"
     else:
         return "Flush error or less than 20000 OffChain Satoshis"
    def dashboard(self):
        flush_message = ""
        status_mining = status.status_mining(client)

        if request.method == 'POST':
            print(request.form)
            if request.form['submit'] == 'Flush Earnings':
                flush_message = self.doFlush()
            else:
                if status_mining['is_mining'] == 'A 21 mining chip is running (/run/minerd.pid)':
                    os.system('sudo minerd --stop')
                else:
                    os.system('21 mine')

        status_mining = status.status_mining(client)

        if status_mining['is_mining'] == 'A 21 mining chip is running (/run/minerd.pid)':
            mine_button_message = 'Click to Stop Miner'
            mining_message = 'Miner Is Running'
        else:
            mine_button_message = 'Click to Start Miner'
            mining_message = 'Miner Is Not Running'

        status_wallet = status.status_wallet(client, wallet)
        status_account = status.status_account(client, wallet)
        status_earnings = client.get_earnings()

        return self.render('admin/dashboard.html', status_mining=status_mining, mining_message=mining_message, status_wallet=status_wallet['wallet'], status_account=status_account, status_earnings=status_earnings, flush_message=flush_message, mine_button_message=mine_button_message)
Exemplo n.º 7
0
def status_wallet(client, wallet):
    result = status.status_wallet(client, wallet)
    address_balances = wallet.balances_by_address(0)
    status_addresses = []
    for addr, balances in address_balances.items():
        if balances['confirmed'] > 0 or balances['total'] > 0:
            status_addresses.append(dict(address=addr, confirmed=balances['confirmed'], total=balances['total']))
    result['addresses'] = status_addresses
    return result
Exemplo n.º 8
0
def dashboard():  
        if request.args.get("code") != code:
            return custom_401()
        client = rest_client.TwentyOneRestClient(host, conf.machine_auth, conf.username)
        status_mining = status.status_mining(conf, client)
        status_wallet = status.status_wallet(conf, client)  
        status_account = status.status_account(conf)  
        status_earnings = client.get_earnings()
        dashInfo = {"status_mining":status_mining, "status_wallet": status_wallet['wallet'], "status_account": status_account, "status_earnings": status_earnings}      
        return json.dumps(dashInfo, default=lambda o: o.__dict__, sort_keys=True, indent=4)
Exemplo n.º 9
0
    def dashboard(self):
        flush_message = ""
        if request.method == 'POST':
            flush_message = self.doFlush()
        status_mining = status.status_mining(conf, client)
        status_wallet = status.status_wallet(conf, client)
        status_account = status.status_account(conf)
        status_earnings = client.get_earnings()

        return self.render('admin/dashboard.html', status_mining=status_mining, status_wallet=status_wallet['wallet'], status_account=status_account, status_earnings=status_earnings, flush_message=flush_message)
Exemplo n.º 10
0
def start_cpu_mining(config):
    """ Mines bitcoin on the command line by using the CPU of the system

    CPU mining, or foreground mining, is when the pool sets the difficulty
    very low and the CPU finds a valid solution.

    Args:
        config (Config): config object used for getting .two1 information
    """

    client = rest_client.TwentyOneRestClient(cmd_config.TWO1_HOST,
                                             config.machine_auth,
                                             config.username)

    enonce1, enonce2_size, reward = set_payout_address(config, client)

    start_time = time.time()
    config.log(UxString.mining_start.format(config.username, reward))



    work = get_work(config, client)

    found_share = mine_work(work, enonce1=enonce1, enonce2_size=enonce2_size)

    paid_satoshis = save_work(client, found_share, config.username)

    end_time = time.time()
    duration = end_time - start_time

    config.log(
        UxString.mining_success.format(config.username, paid_satoshis, duration),
        fg="magenta")

    click.echo(UxString.mining_status)
    status.status_wallet(config, client)

    click.echo(UxString.mining_finish.format(
        click.style("21 status", bold=True), click.style("21 buy", bold=True)))
Exemplo n.º 11
0
Arquivo: mine.py Projeto: iweave/two1
def start_cpu_mining(config):
    """Mine at the CPU.
    >>> from two1.commands.config import Config
    >>> config = Config()
    >>> start_cpu_mining(config)
    """

    client = rest_client.TwentyOneRestClient(cmd_config.TWO1_HOST,
                                             config.machine_auth,
                                             config.username)

    enonce1, enonce2_size, reward = set_payout_address(config, client)

    start_time = time.time()
    config.log(UxString.mining_start.format(config.username, reward))

    device_uuid = config.device_uuid or "local"

    work = get_work(config, client, device_uuid)

    found_share = mine_work(work, enonce1=enonce1, enonce2_size=enonce2_size)

    paid_satoshis = save_work(client, found_share, config.username, device_uuid)

    end_time = time.time()
    duration = end_time - start_time

    config.log(
        UxString.mining_success.format(config.username, paid_satoshis, duration),
        fg="magenta")

    click.echo(UxString.mining_status)
    status.status_wallet(config, client)

    click.echo(UxString.mining_finish.format(
        click.style("21 status", bold=True), click.style("21 buy", bold=True)))
Exemplo n.º 12
0
    def dashboard(self):
        flush_message = ""
        status_mining = status.status_mining(client)

        if request.method == 'POST':
            print(request.form)
            if request.form['submit'] == 'Flush Earnings':
                flush_message = self.doFlush()
            else:
                if status_mining[
                        'is_mining'] == 'A 21 mining chip is running (/run/minerd.pid)':
                    os.system('sudo minerd --stop')
                else:
                    os.system('21 mine')

        status_mining = status.status_mining(client)

        if status_mining[
                'is_mining'] == 'A 21 mining chip is running (/run/minerd.pid)':
            mine_button_message = 'Click to Stop Miner'
            mining_message = 'Miner Is Running'
        else:
            mine_button_message = 'Click to Start Miner'
            mining_message = 'Miner Is Not Running'

        status_wallet = status.status_wallet(client, wallet)
        status_account = status.status_account(client, wallet)
        status_earnings = client.get_earnings()

        return self.render('admin/dashboard.html',
                           status_mining=status_mining,
                           mining_message=mining_message,
                           status_wallet=status_wallet['wallet'],
                           status_account=status_account,
                           status_earnings=status_earnings,
                           flush_message=flush_message,
                           mine_button_message=mine_button_message)