Esempio n. 1
0
    def mine_msg_txn_incorrectly(self, tip_height, tip_hash):
        nonce = 0
        op_return_data = self.create_op_return_data(tip_height, tip_hash,
                                                    nonce)

        tx = CTransaction()
        tx.vin.append(CTxIn(COutPoint(0, 0xfffffffe), b"", 0xffffffff))
        tx.vout.append(CTxOut(0, CScript([OP_RETURN, op_return_data])))
        tx.nLockTime = self.tx_time
        tx.mine()
        tx.rehash()

        self.tx_time += 1
        lower_bound = get_target(tx)
        upper_bound = uint256_from_str(
            hex_str_to_bytes(
                "00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
            )[::-1])

        while tx.sha256s ^ 0x8000000000000000000000000000000000000000000000000000000000000000 <= lower_bound or \
            tx.sha256s ^ 0x8000000000000000000000000000000000000000000000000000000000000000 > upper_bound:
            nonce += 1
            op_return_data[-4:] = struct.pack("<I", nonce)
            tx.vout[0] = CTxOut(0, CScript([OP_RETURN, op_return_data]))
            tx.mine()

        tx.rehash()
        return tx
Esempio n. 2
0
    def mine_msg_txn(self, tip_height, tip_hash):
        self.log.info("Mining msg txn...")
        nonce = 0
        op_return_data = self.create_op_return_data(tip_height, tip_hash,
                                                    nonce)

        tx = CTransaction()
        tx.vin.append(CTxIn(COutPoint(0, 0xfffffffe), b"", 0xffffffff))
        tx.vout.append(CTxOut(0, CScript([OP_RETURN, op_return_data])))
        tx.nLockTime = self.tx_time
        tx.mine()
        tx.rehash()

        self.tx_time += 1
        target = get_target(tx)

        while tx.sha256s ^ 0x8000000000000000000000000000000000000000000000000000000000000000 > target:
            nonce += 1
            op_return_data[-4:] = struct.pack("<I", nonce)
            tx.vout[0] = CTxOut(0, CScript([OP_RETURN, op_return_data]))
            tx.mine()

        tx.rehash()
        return tx