<pre><code>BlockChain::BlockChain ( QObject* parent ) : QFile ( parent ), blkFile ( START_BLOCK )
{
  connect ( this, SIGNAL ( block ( const QByteArray&amp; ) ), parent, SLOT ( block ( const QByteArray&amp; ) ) );
  connect ( this, SIGNAL ( doneFile ( ) ), parent, SLOT ( doneFile ( ) ) );
  QTimer::singleShot ( 0, this, SLOT ( start ( ) ) );
}

void BlockChain::start ( )
{
  setFileName ( blkFileName ( blkFile++ ) );
  if ( !open ( QIODevice::ReadOnly ) )
  {
    _trace ( QString ( "cant open [%1]" ).arg ( fileName ( ) ) );
    emit block ( QByteArray ( ) );
    deleteLater ( );
  }
  else
  {
    _trace ( QString ( "processing [%1]" ).arg ( fileName ( ) ) );
    QTimer::singleShot ( 0, this, SLOT ( next ( ) ) );
  }
}

void BlockChain::next ( )
{
  if ( pos ( ) &lt; size ( ) )
  {
    quint32 magic;
    quint32 sz ( read ( (char*)&amp;magic, 4 ) );
    while ( !magic &amp;&amp; pos ( ) &lt; size ( ) - 4 )
      read ( (char*)&amp;magic, 4 );
    xassert ( ( ( magic == MAGIC_ID ) || !magic ) &amp;&amp; ( sz == 4 ) );
    if ( magic )
    {
      read ( (char*)&amp;sz, 4 );
      emit block ( read ( sz ) );
      QTimer::singleShot ( 0, this, SLOT ( next ( ) ) );
      return;
    }
  }
  close ( );
  emit doneFile ( );
  QTimer::singleShot ( 0, this, SLOT ( start ( ) ) );
}

const QString BlockChain::blkFileName ( const int i ) const
{
  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 );
}
</code></pre>

CC BY-SA 3.0
2017-03-18T17:01:06.157Z
This seems to be missing a class definition at least.
Pieter Wuille
CC BY-SA 3.0
2017-03-18T17:59:42.053Z
this piece of code is only a demonstration that blockchain parsing is very simple task
amaclin
CC BY-SA 3.0
2017-03-18T18:20:16.933Z
Ok, but it's not an answer. You don't explain what it does, why it works, what it needs.
Pieter Wuille
CC BY-SA 3.0
2017-03-18T23:34:09.590Z
this is an answer for a question "Is there any tool to extract the bitcoin transaction [network] from the blockchain?". the short answer is: "yes, there is. here is a proof that such tool exists"
amaclin
CC BY-SA 3.0
2017-03-19T00:15:26.207Z
I'm downvoting this because it gives no context. Just a piece of code that doesn't even compile is not informative.
Pieter Wuille
CC BY-SA 3.0
2017-03-18T05:53:45.820Z
2017-03-18T05:53:45.820Z
amaclin
<p>I'm looking for a way to extract some data from the latest downloaded bitcoin blockchain. In particular I'm interested in extracting the whole transaction network, so input and output public keys used in each transaction, the transaction date, hash, block hash and BTC amount.  I tried several solutions so far with no luck: </p>

<p>Bitcoin-Transaction-Network-Extraction</p>

<p>rusty-blockparser</p>

<p>bitcointools</p>

<p>BitcoinDatabaseGenerator</p>

<p>BCGraph</p>

<p>I've had some luck with bitcoindatabasegenerator and rusty-blockparser, but while these tools succesfully extract the output PKs, input PKs are nowhere to be found in the resulting files.</p>

<p>Summarizing, I'm looking for something like this to produce a network visualization of bitcoin transactions:</p>

<p>|Source PK(s) (BTC)| ------> Transaction ------> |Target PK(s) (BTC)|</p>

<p>Im not really an expert in coding so this makes everything more complicated for me. Can you suggest me a way to extract this data from downloaded Blk files?</p>

<p>Any help would be greatly appreciated!</p>

<transactions><network><database><historical-trade-data><tools>
Is there any tool to extract the bitcoin transaction network from the blockchain?
Nellous
# Is there any tool to extract the bitcoin transaction network from the blockchain?

(Asked by: username_0 on 2017-03-17)

I'm looking for a way to extract some data from the latest downloaded bitcoin blockchain. In particular I'm interested in extracting the whole transaction network, so input and output public keys used in each transaction, the transaction date, hash, block hash and BTC amount. I tried several solutions so far with no luck:

Bitcoin-Transaction-Network-Extraction

rusty-blockparser

bitcointools

BitcoinDatabaseGenerator

BCGraph

I've had some luck with bitcoindatabasegenerator and rusty-blockparser, but while these tools succesfully extract the output PKs, input PKs are nowhere to be found in the resulting files.

Summarizing, I'm looking for something like this to produce a network visualization of bitcoin transactions:

|Source PK(s) (BTC)| ------> Transaction ------> |Target PK(s) (BTC)|

Im not really an expert in coding so this makes everything more complicated for me. Can you suggest me a way to extract this data from downloaded Blk files?

Any help would be greatly appreciated!

**Tags:** transactions, network, database, historical-trade-data, tools


---

## 1 answers

### Answer by username_1 on 2017-03-18. Score: -2

BlockChain::BlockChain ( QObject* parent ) : QFile ( parent ), blkFile ( START_BLOCK )
{
  connect ( this, SIGNAL ( block ( const QByteArray& ) ), parent, SLOT ( block ( const QByteArray& ) ) );
  connect ( this, SIGNAL ( doneFile ( ) ), parent, SLOT ( doneFile ( ) ) );
  QTimer::singleShot ( 0, this, SLOT ( start ( ) ) );
}

void BlockChain::start ( )
{
  setFileName ( blkFileName ( blkFile++ ) );
  if ( !open ( QIODevice::ReadOnly ) )
  {
    _trace ( QString ( "cant open [%1]" ).arg ( fileName ( ) ) );
    emit block ( QByteArray ( ) );
    deleteLater ( );
  }
  else
  {
    _trace ( QString ( "processing [%1]" ).arg ( fileName ( ) ) );
    QTimer::singleShot ( 0, this, SLOT ( next ( ) ) );
  }
}

void BlockChain::next ( )
{
  if ( pos ( ) < size ( ) )
  {
    quint32 magic;
    quint32 sz ( read ( (char*)&magic, 4 ) );
    while ( !magic && pos ( ) < size ( ) - 4 )
      read ( (char*)&magic, 4 );
    xassert ( ( ( magic == MAGIC_ID ) || !magic ) && ( sz == 4 ) );
    if ( magic )
    {
      read ( (char*)&sz, 4 );
      emit block ( read ( sz ) );
      QTimer::singleShot ( 0, this, SLOT ( next ( ) ) );
      return;
    }
  }
  close ( );
  emit doneFile ( );
  QTimer::singleShot ( 0, this, SLOT ( start ( ) ) );
}

const QString BlockChain::blkFileName ( const int i ) const
{
  return
    ( i < 10 ) ? QString ( DATA_ROOT "\\blk0000%1.dat" ).arg ( i ) :
    ( i < 100 ) ? QString ( DATA_ROOT "\\blk000%1.dat" ).arg ( i ) :
    QString ( DATA_ROOT "\\blk00%1.dat" ).arg ( i );
}

> **Comments:**
> **username_2**: This seems to be missing a class definition at least.  
> **username_1**: this piece of code is only a demonstration that blockchain parsing is very simple task  
> **username_2**: Ok, but it's not an answer. You don't explain what it does, why it works, what it needs.  
> **username_1**: this is an answer for a question "Is there any tool to extract the bitcoin transaction [network] from the blockchain?". the short answer is: "yes, there is. here is a proof that such tool exists"  
> **username_2**: I'm downvoting this because it gives no context. Just a piece of code that doesn't even compile is not informative.  

---

