예제 #1
0
    def addAuxpow(self, block, blkHash, ok):
        """
    Fills in the auxpow for the given block message.  It is either
    chosen to be valid (ok = True) or invalid (ok = False).
    """

        target = b"%064x" % uint256_from_compact(block.nBits)
        auxpowHex = computeAuxpow(blkHash, target, ok)
        block.auxpow = CAuxPow()
        block.auxpow.deserialize(BytesIO(hex_str_to_bytes(auxpowHex)))

        return block
예제 #2
0
    def addAuxpow(self, block, blkHash, ok):
        """
    Fills in the auxpow for the given block message.  It is either
    chosen to be valid (ok = True) or invalid (ok = False).
    """

        tmpl = self.nodes[0].getauxblock()
        target = reverseHex(tmpl["_target"])

        auxpowHex = computeAuxpow(blkHash, target, ok)
        block.auxpow = CAuxPow()
        block.auxpow.deserialize(BytesIO(hex_str_to_bytes(auxpowHex)))

        return block
예제 #3
0
    def createBlock(self):
        """
    Creates and mines a new block with auxpow.
    """

        bestHash = self.nodes[0].getbestblockhash()
        bestBlock = self.nodes[0].getblock(bestHash)
        tip = int(bestHash, 16)
        height = bestBlock["height"] + 1
        time = bestBlock["time"] + 1

        block = create_block(tip, create_coinbase(height), time)
        block.mark_auxpow()
        block.rehash()
        newHash = "%032x" % block.sha256

        target = b"%032x" % uint256_from_compact(block.nBits)
        auxpowHex = computeAuxpow(newHash, target, True)
        block.auxpow = CAuxPow()
        block.auxpow.deserialize(BytesIO(hex_str_to_bytes(auxpowHex)))

        return block, newHash