veriblock-core/src/main/java/org/veriblock/core/utilities/BlockUtility.java
/**
     * Assembles the compact-format block header, which is used for PoW mining and is published during the PoP process
     * to Bitcoin.
     * <p>
     * The block header is 64 bytes which to fit comfortably into an 80-byte OP_RETURN on Bitcoin; remaining 16 bytes
     * will be PoP miner identification data
     *
     * @param blockHeight              4-byte block height
     * @param version                  2-byte block version
     * @param previousBlockHash        12-byte previous block hash encoded as hexadecimal, hash of the previous block which this block builds upon
     * @param secondPreviousBlockHash  9-byte second previous block hash encoded as hexadecimal
     * @param thirdPreviousBlockHash   9-byte third previous block hash encoded as hexadecimal
     * @param merkleRootHash           16-byte merkle root hash encoded as hexadecimal
     * @param timestamp                4-byte timestamp in Unix epoch format (with second granularity)
     * @param difficulty               4-byte difficulty
     * @param nonce                    4-byte nonce used to achieve a block hash under target
     * @return The block header created from all provided parameters
     */
Assembles the compact-format block header, which is used for PoW mining and is published during the PoP process
to Bitcoin.

The block header is 64 bytes which to fit comfortably into an 80-byte OP_RETURN on Bitcoin; remaining 16 bytes
will be PoP miner identification data


Assembles the compact - format block header which is used for PoW mining and is published during the PoP process to Bitcoin . The block header is 64 bytes which to fit comfortably into an 80 - byte OP_RETURN on Bitcoin ; remaining 16 bytes will be PoP miner identification data
public static byte[] assembleBlockHeader(int blockHeight,
                                             short version,
                                             String previousBlockHash,
                                             String secondPreviousBlockHash,
                                             String thirdPreviousBlockHash,
                                             String merkleRootHash,
                                             int timestamp,
                                             int difficulty,
                                             int nonce) {
        byte[] header = new byte[NONCE_END_POSITION + 1];
        int shift = 24;
        for (int i = BLOCK_HEIGHT_START_POSITION; i <= BLOCK_HEIGHT_END_POSITION; i++) {
            header[i] = (byte)((blockHeight & MASKS[i - BLOCK_HEIGHT_START_POSITION]) >> shift);
            shift -= 8;
        }
        shift = 8;
        for (int i = VERSION_START_POSITION; i <= VERSION_END_POSITION; i++) {
            header[i] = (byte)((version & MASKS[i - VERSION_START_POSITION + 2]) >> shift);
            shift -= 8;
        }
        previousBlockHash = previousBlockHash.substring(previousBlockHash.length() - (2 * (1 + PREVIOUS_BLOCK_HASH_END_POSITION - PREVIOUS_BLOCK_HASH_START_POSITION)));
        secondPreviousBlockHash = secondPreviousBlockHash.substring(secondPreviousBlockHash.length() - (2 * (1 + SECOND_PREVIOUS_BLOCK_HASH_END_POSITION - SECOND_PREVIOUS_BLOCK_HASH_START_POSITION)));
        thirdPreviousBlockHash = thirdPreviousBlockHash.substring(thirdPreviousBlockHash.length() - (2 * (1 + THIRD_PREVIOUS_BLOCK_HASH_END_POSITION - THIRD_PREVIOUS_BLOCK_HASH_START_POSITION)));
        for (int i = 0; i <= (PREVIOUS_BLOCK_HASH_END_POSITION - PREVIOUS_BLOCK_HASH_START_POSITION); i++)
            header[i + PREVIOUS_BLOCK_HASH_START_POSITION] = (byte) (Integer.parseInt(previousBlockHash.substring(i * 2, (i * 2) + 2), 16));
        for (int i = 0; i <= (SECOND_PREVIOUS_BLOCK_HASH_END_POSITION - SECOND_PREVIOUS_BLOCK_HASH_START_POSITION); i++)
            header[i + SECOND_PREVIOUS_BLOCK_HASH_START_POSITION] = (byte) (Integer.parseInt(secondPreviousBlockHash.substring(i * 2, (i * 2) + 2), 16));
        for (int i = 0; i <= (THIRD_PREVIOUS_BLOCK_HASH_END_POSITION - THIRD_PREVIOUS_BLOCK_HASH_START_POSITION); i++)
            header[i + THIRD_PREVIOUS_BLOCK_HASH_START_POSITION] = (byte) (Integer.parseInt(thirdPreviousBlockHash.substring(i * 2, (i * 2) + 2), 16));
        for (int i = 0; i <= (MERKLE_ROOT_HASH_END_POSITION - MERKLE_ROOT_HASH_START_POSITION); i++)
            header[i + MERKLE_ROOT_HASH_START_POSITION] = (byte) (Integer.parseInt(merkleRootHash.substring(i * 2, (i * 2) + 2), 16));
        shift = 24;
        for (int i = TIMESTAMP_START_POSITION; i <= TIMESTAMP_END_POSITION; i++) {
            header[i] = (byte)((timestamp & MASKS[i - TIMESTAMP_START_POSITION]) >> shift);
            shift -= 8;
        }
        shift = 24;
        for (int i = DIFFICULTY_START_POSITION; i <= DIFFICULTY_END_POSITION; i++) {
            header[i] = (byte)((difficulty & MASKS[i - DIFFICULTY_START_POSITION]) >> shift);
            shift -= 8;
        }
        shift = 24;
        for (int i = NONCE_START_POSITION; i <= NONCE_END_POSITION; i++) {
            header[i] = (byte)((nonce & MASKS[i - NONCE_START_POSITION]) >> shift);
            shift -= 8;
        }
        return header;
    }
public static byte [ ] assembleBlockHeader ( int blockHeight , short version , String previousBlockHash , String secondPreviousBlockHash , String thirdPreviousBlockHash , String merkleRootHash , int timestamp , int difficulty , int nonce ) { byte [ ] header = new byte [ NONCE_END_POSITION + 1 ] ; int shift = 24 ; for ( int i = BLOCK_HEIGHT_START_POSITION ; i <= BLOCK_HEIGHT_END_POSITION ; i ++ ) { header [ i ] = ( byte ) ( ( blockHeight & MASKS [ i - BLOCK_HEIGHT_START_POSITION ] ) >> shift ) ; shift -= 8 ; } shift = 8 ; for ( int i = VERSION_START_POSITION ; i <= VERSION_END_POSITION ; i ++ ) { header [ i ] = ( byte ) ( ( version & MASKS [ i - VERSION_START_POSITION + 2 ] ) >> shift ) ; shift -= 8 ; } previousBlockHash = previousBlockHash . substring ( previousBlockHash . length ( ) - ( 2 * ( 1 + PREVIOUS_BLOCK_HASH_END_POSITION - PREVIOUS_BLOCK_HASH_START_POSITION ) ) ) ; secondPreviousBlockHash = secondPreviousBlockHash . substring ( secondPreviousBlockHash . length ( ) - ( 2 * ( 1 + SECOND_PREVIOUS_BLOCK_HASH_END_POSITION - SECOND_PREVIOUS_BLOCK_HASH_START_POSITION ) ) ) ; thirdPreviousBlockHash = thirdPreviousBlockHash . substring ( thirdPreviousBlockHash . length ( ) - ( 2 * ( 1 + THIRD_PREVIOUS_BLOCK_HASH_END_POSITION - THIRD_PREVIOUS_BLOCK_HASH_START_POSITION ) ) ) ; for ( int i = 0 ; i <= ( PREVIOUS_BLOCK_HASH_END_POSITION - PREVIOUS_BLOCK_HASH_START_POSITION ) ; i ++ ) header [ i + PREVIOUS_BLOCK_HASH_START_POSITION ] = ( byte ) ( Integer . parseInt ( previousBlockHash . substring ( i * 2 , ( i * 2 ) + 2 ) , 16 ) ) ; for ( int i = 0 ; i <= ( SECOND_PREVIOUS_BLOCK_HASH_END_POSITION - SECOND_PREVIOUS_BLOCK_HASH_START_POSITION ) ; i ++ ) header [ i + SECOND_PREVIOUS_BLOCK_HASH_START_POSITION ] = ( byte ) ( Integer . parseInt ( secondPreviousBlockHash . substring ( i * 2 , ( i * 2 ) + 2 ) , 16 ) ) ; for ( int i = 0 ; i <= ( THIRD_PREVIOUS_BLOCK_HASH_END_POSITION - THIRD_PREVIOUS_BLOCK_HASH_START_POSITION ) ; i ++ ) header [ i + THIRD_PREVIOUS_BLOCK_HASH_START_POSITION ] = ( byte ) ( Integer . parseInt ( thirdPreviousBlockHash . substring ( i * 2 , ( i * 2 ) + 2 ) , 16 ) ) ; for ( int i = 0 ; i <= ( MERKLE_ROOT_HASH_END_POSITION - MERKLE_ROOT_HASH_START_POSITION ) ; i ++ ) header [ i + MERKLE_ROOT_HASH_START_POSITION ] = ( byte ) ( Integer . parseInt ( merkleRootHash . substring ( i * 2 , ( i * 2 ) + 2 ) , 16 ) ) ; shift = 24 ; for ( int i = TIMESTAMP_START_POSITION ; i <= TIMESTAMP_END_POSITION ; i ++ ) { header [ i ] = ( byte ) ( ( timestamp & MASKS [ i - TIMESTAMP_START_POSITION ] ) >> shift ) ; shift -= 8 ; } shift = 24 ; for ( int i = DIFFICULTY_START_POSITION ; i <= DIFFICULTY_END_POSITION ; i ++ ) { header [ i ] = ( byte ) ( ( difficulty & MASKS [ i - DIFFICULTY_START_POSITION ] ) >> shift ) ; shift -= 8 ; } shift = 24 ; for ( int i = NONCE_START_POSITION ; i <= NONCE_END_POSITION ; i ++ ) { header [ i ] = ( byte ) ( ( nonce & MASKS [ i - NONCE_START_POSITION ] ) >> shift ) ; shift -= 8 ; } return header ; }
Assembles the compact-format block header, which is used for PoW mining and is published during the PoP process
 to Bitcoin.
Assembles the compact - format block header which is used for PoW mining and is published during the PoP process to Bitcoin .