Decode blocks received and Store in another file for analyzing I am working on a bitcoin research project. I want to decode receiving blocks from the block chain and store decoded data in a separate file for analyzing purposes.

For this purpose I digs the bitcoin c++ code and find the exact place, which use to write the blocks into blkXXX.dat file.

Could you please suggest a solution for this matter.

Thank you
#include &lt;QTimer&gt;
#include &lt;QFile&gt;

#include "BlockChain.h"

BlockChain::BlockChain ( const int start, QObject* parent ) : QFile ( parent ), blkFile ( start + 1 )
{
  QTimer::singleShot ( 0, this, SLOT ( start ( ) ) );
}
//--------------------------------------------------------------
void BlockChain::start ( )
{
  setFileName ( blkFileName ( blkFile++ ) );
  if ( !open ( QIODevice::ReadOnly ) )
  {
    _trace ( QString ( "cant open [%1]" ).arg ( fileName ( ) ) );
    getParent ( ).block ( QByteArray ( ) ); // finish signal
    deleteLater ( );
  }
  else
  {
    _trace ( QString ( "processing [%1]" ).arg ( fileName ( ) ) );
    QTimer::singleShot ( 0, this, SLOT ( next ( ) ) );
  }
}
//--------------------------------------------------------------
void BlockChain::next ( )
{
  bool lock ( true );
  if ( pos ( ) &lt; size ( ) )
  {
    quint32 magic;
    quint32 size ( read ( (char*)&amp;magic, 4 ) );
    xassert ( ( ( magic == MAGIC_ID ) || !magic ) &amp;&amp; ( size == 4 ) );
    if ( magic )
    {
      read ( (char*)&amp;size, 4 );
      xassert ( size &gt; HEADER_SIZE &amp;&amp; size &lt;= MAX_BLOCK_SIZE );
      getParent ( ).block ( read ( size ) ); // process data
      QTimer::singleShot ( 0, this, SLOT ( next ( ) ) );
      return;
    }
    else
      lock = false;
  }
  close ( );
  getParent ( ).doneFile ( lock, blkFile - 1 );
  QTimer::singleShot ( 0, this, SLOT ( start ( ) ) );
}
//--------------------------------------------------------------
const QString BlockChain::blkFileName ( const int i )
{
  return
    ( i &lt; 10 ) ? QString ( DATA_ROOT "\\blk0000%1.dat" ).arg ( i ) :
    ( i &lt; 100 ) ? QString ( DATA_ROOT "\\blk000%1.dat" ).arg ( i ) :
    QString ( DATA_ROOT "\\blk00%1.dat" ).arg ( i );
}