Example #1
0
def computeAuxpowWithChainId(block, target, chainid, ok):
    """
  Build an auxpow object (serialised as hex string) that solves the
  block, for a given chain id.
  """

    # Start by building the merge-mining coinbase.  The merkle tree
    # consists only of the block hash as root.
    coinbase = "fabe" + binascii.hexlify("m" * 2)
    coinbase += block
    coinbase += "01000000" + ("00" * 4)

    # Construct "vector" of transaction inputs.
    vin = "01"
    vin += ("00" * 32) + ("ff" * 4)
    vin += ("%02x" % (len(coinbase) / 2)) + coinbase
    vin += ("ff" * 4)

    # Build up the full coinbase transaction.  It consists only
    # of the input and has no outputs.
    tx = "01000000" + vin + "00" + ("00" * 4)
    txHash = auxpow.doubleHashHex(tx)

    # Construct the parent block header.  It need not be valid, just good
    # enough for auxpow purposes.
    header = "0100" + chainid + "00"
    header += "00" * 32
    header += auxpow.reverseHex(txHash)
    header += "00" * 4
    header += "00" * 4
    header += "00" * 4

    # Mine the block.
    (header, blockhash) = mineScryptBlock(header, target, ok)

    # Build the MerkleTx part of the auxpow.
    output = tx
    output += blockhash
    output += "00"
    output += "00" * 4

    # Extend to full auxpow.
    output += "00"
    output += "00" * 4
    output += header

    return output
Example #2
0
def computeAuxpowWithChainId (block, target, chainid, ok):
  """
  Build an auxpow object (serialised as hex string) that solves the
  block, for a given chain id.
  """

  # Start by building the merge-mining coinbase.  The merkle tree
  # consists only of the block hash as root.
  coinbase = "fabe" + binascii.hexlify ("m" * 2)
  coinbase += block
  coinbase += "01000000" + ("00" * 4)

  # Construct "vector" of transaction inputs.
  vin = "01"
  vin += ("00" * 32) + ("ff" * 4)
  vin += ("%02x" % (len (coinbase) / 2)) + coinbase
  vin += ("ff" * 4)

  # Build up the full coinbase transaction.  It consists only
  # of the input and has no outputs.
  tx = "01000000" + vin + "00" + ("00" * 4)
  txHash = auxpow.doubleHashHex (tx)

  # Construct the parent block header.  It need not be valid, just good
  # enough for auxpow purposes.
  header = "0100" + chainid + "00"
  header += "00" * 32
  header += auxpow.reverseHex (txHash)
  header += "00" * 4
  header += "00" * 4
  header += "00" * 4

  # Mine the block.
  (header, blockhash) = mineScryptBlock (header, target, ok)

  # Build the MerkleTx part of the auxpow.
  output = tx
  output += blockhash
  output += "00"
  output += "00" * 4

  # Extend to full auxpow.
  output += "00"
  output += "00" * 4
  output += header

  return output
Example #3
0
def mineScryptBlock(header, target, ok):
    """
  Given a block header, update the nonce until it is ok (or not)
  for the given target.
  """

    data = bytearray(binascii.unhexlify(header))
    while True:
        assert data[79] < 255
        data[79] += 1
        hexData = binascii.hexlify(data)

        scrypt = getScryptPoW(hexData)
        if (ok and scrypt < target) or ((not ok) and scrypt > target):
            break

    blockhash = auxpow.doubleHashHex(hexData)
    return (hexData, blockhash)
Example #4
0
def mineScryptBlock (header, target, ok):
  """
  Given a block header, update the nonce until it is ok (or not)
  for the given target.
  """

  data = bytearray (binascii.unhexlify (header))
  while True:
    assert data[79] < 255
    data[79] += 1
    hexData = binascii.hexlify (data)

    scrypt = getScryptPoW(hexData)
    if (ok and scrypt < target) or ((not ok) and scrypt > target):
      break

  blockhash = auxpow.doubleHashHex (hexData)
  return (hexData, blockhash)