コード例 #1
0
    def run(self):
        self.logger.info("starting to mine")

        pool_target = utils.bits_to_target(self.notify_msg.bits_pool)
        for enonce2_num in range(0, 2**(self.enonce2_size * 8)):
            enonce2 = enonce2_num.to_bytes(self.enonce2_size, byteorder="big")

            cb_txn, _ = Transaction.from_bytes(self.notify_msg.coinb1 +
                                               self.enonce1 + enonce2 +
                                               self.notify_msg.coinb2)
            cb = CompactBlock(
                self.notify_msg.height,
                self.notify_msg.version,
                Hash(self.notify_msg.prev_block_hash),
                self.notify_msg.ntime,
                self.notify_msg.nbits,  # lower difficulty work for testing
                self.notify_msg.merkle_edge,
                cb_txn)
            for nonce in range(0xffffffff):
                cb.block_header.nonce = nonce
                h = cb.block_header.hash.to_int('little')
                if h < pool_target:
                    self.logger.info("Found Share")
                    share = Share(enonce2=enonce2,
                                  nonce=nonce,
                                  work_id=self.notify_msg.work_id,
                                  otime=self.notify_msg.ntime)
                    self.event_loop.call_soon_threadsafe(
                        asyncio. async, self.handle_found_cb(share))
                    time.sleep(0.3)
コード例 #2
0
ファイル: cpu_miner.py プロジェクト: SamvitJ/21BC-lib
    def run(self):
        self.logger.info("starting to mine")

        pool_target = utils.bits_to_target(self.notify_msg.bits_pool)
        for enonce2_num in range(0, 2 ** (self.enonce2_size * 8)):
            enonce2 = enonce2_num.to_bytes(self.enonce2_size, byteorder="big")

            cb_txn, _ = Transaction.from_bytes(
                self.notify_msg.coinb1 + self.enonce1 + enonce2 + self.notify_msg.coinb2)
            cb = CompactBlock(self.notify_msg.height,
                              self.notify_msg.version,
                              Hash(self.notify_msg.prev_block_hash),
                              self.notify_msg.ntime,
                              self.notify_msg.nbits,  # lower difficulty work for testing
                              self.notify_msg.merkle_edge,
                              cb_txn)
            for nonce in range(0xffffffff):
                cb.block_header.nonce = nonce
                h = cb.block_header.hash.to_int('little')
                if h < pool_target:
                    self.logger.info("Found Share")
                    share = Share(
                        enonce2=enonce2,
                        nonce=nonce,
                        work_id=self.notify_msg.work_id,
                        otime=self.notify_msg.ntime)
                    self.event_loop.call_soon_threadsafe(
                        asyncio.async,
                        self.handle_found_cb(share)
                    )
                    time.sleep(0.3)
コード例 #3
0
ファイル: mine.py プロジェクト: erikvold/two1
def mine_work(work_msg, enonce1, enonce2_size):
    """ Mines the work using a CPU to find a valid solution

        Loops until the CPU finds a valid solution of the given work.

    Todo:
        slow down the click echo when on a 21BC

    Args:
        work_msg (WorkNotification): the work given by the pool API
        enonce1 (bytes): extra nonce required to make the coinbase transaction
        enonce2_size (int): size of the extra nonce 2 in bytes

    """
    pool_target = utils.bits_to_target(work_msg.bits_pool)
    for enonce2_num in range(0, 2 ** (enonce2_size * 8)):
        enonce2 = enonce2_num.to_bytes(enonce2_size, byteorder="big")

        cb_txn, _ = Transaction.from_bytes(
            work_msg.coinb1 + enonce1 + enonce2 + work_msg.coinb2)
        cb = CompactBlock(work_msg.height,
                          work_msg.version,
                          Hash(work_msg.prev_block_hash),
                          work_msg.ntime,
                          work_msg.nbits,  # lower difficulty work for testing
                          work_msg.merkle_edge,
                          cb_txn)

        row_counter = 0
        for nonce in range(0xffffffff):

            if nonce % 6e3 == 0:
                click.echo(click.style(u'█', fg='green'), nl=False)
                row_counter += 1
            if row_counter > 40:
                row_counter = 0
                click.echo("")

            cb.block_header.nonce = nonce
            h = cb.block_header.hash.to_int('little')
            if h < pool_target:
                share = Share(
                    enonce2=enonce2,
                    nonce=nonce,
                    work_id=work_msg.work_id,
                    otime=int(time.time()))
                # adds a new line at the end of progress bar
                click.echo("")
                return share

        click.echo("Exhausted enonce1 space. Changing enonce2")
コード例 #4
0
ファイル: block.py プロジェクト: SamvitJ/21BC-lib
    def __init__(self, version, prev_block_hash, merkle_root_hash,
                 time, bits, nonce):
        if not isinstance(prev_block_hash, Hash):
            raise TypeError('prev_block_hash must be a Hash object')
        if not isinstance(merkle_root_hash, Hash):
            raise TypeError('merkle_root hash must be a Hash object')
        self.version = version
        self.prev_block_hash = prev_block_hash
        self.merkle_root_hash = merkle_root_hash
        self.time = time
        self.bits = bits
        self.nonce = nonce

        self.target = bits_to_target(bits)
コード例 #5
0
ファイル: block.py プロジェクト: jameshilliard/two1
    def __init__(self, version, prev_block_hash, merkle_root_hash, time, bits,
                 nonce):
        if not isinstance(prev_block_hash, Hash):
            raise TypeError('prev_block_hash must be a Hash object')
        if not isinstance(merkle_root_hash, Hash):
            raise TypeError('merkle_root hash must be a Hash object')
        self.version = version
        self.prev_block_hash = prev_block_hash
        self.merkle_root_hash = merkle_root_hash
        self.time = time
        self.bits = bits
        self.nonce = nonce

        self.target = bits_to_target(bits)
コード例 #6
0
ファイル: mine.py プロジェクト: iweave/two1
def mine_work(work_msg, enonce1, enonce2_size):
    pool_target = utils.bits_to_target(work_msg.bits_pool)
    for enonce2_num in range(0, 2 ** (enonce2_size * 8)):
        enonce2 = enonce2_num.to_bytes(enonce2_size, byteorder="big")

        cb_txn, _ = Transaction.from_bytes(
            work_msg.coinb1 + enonce1 + enonce2 + work_msg.coinb2)
        cb = CompactBlock(work_msg.height,
                          work_msg.version,
                          Hash(work_msg.prev_block_hash),
                          work_msg.ntime,
                          work_msg.nbits,  # lower difficulty work for testing
                          work_msg.merkle_edge,
                          cb_txn)

        row_counter = 0
        for nonce in range(0xffffffff):

            if nonce % 6e3 == 0:
                click.echo(click.style(u'█', fg='green'), nl=False)
                row_counter += 1
            if row_counter > 40:
                row_counter = 0
                click.echo("")

            cb.block_header.nonce = nonce
            h = cb.block_header.hash.to_int('little')
            if h < pool_target:
                share = Share(
                    enonce2=enonce2,
                    nonce=nonce,
                    work_id=work_msg.work_id,
                    otime=int(time.time()))
                # adds a new line at the end of progress bar
                click.echo("")
                return share

        click.echo("Exhausted enonce1 space. Changing enonce2")
コード例 #7
0
ファイル: mine.py プロジェクト: jameshilliard/two1
def mine_work(work_msg, enonce1, enonce2_size):
    pool_target = utils.bits_to_target(work_msg.bits_pool)
    for enonce2_num in range(0, 2**(enonce2_size * 8)):
        enonce2 = enonce2_num.to_bytes(enonce2_size, byteorder="big")

        cb_txn, _ = Transaction.from_bytes(work_msg.coinb1 + enonce1 +
                                           enonce2 + work_msg.coinb2)
        cb = CompactBlock(
            work_msg.height,
            work_msg.version,
            Hash(work_msg.prev_block_hash),
            work_msg.ntime,
            work_msg.nbits,  # lower difficulty work for testing
            work_msg.merkle_edge,
            cb_txn)

        row_counter = 0
        for nonce in range(0xffffffff):

            if nonce % 6e3 == 0:
                click.echo(click.style(u'█', fg='green'), nl=False)
                row_counter += 1
            if row_counter > 40:
                row_counter = 0
                click.echo("")

            cb.block_header.nonce = nonce
            h = cb.block_header.hash.to_int('little')
            if h < pool_target:
                share = Share(enonce2=enonce2,
                              nonce=nonce,
                              work_id=work_msg.work_id,
                              otime=int(time.time()))
                # adds a new line at the end of progress bar
                click.echo("")
                return share

        click.echo("Exhausted enonce1 space. Changing enonce2")