Bitcoin Forum
May 11, 2024, 04:07:28 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to efficiently extract values of vin in blockchain transactions  (Read 451 times)
PVminer (OP)
Jr. Member
*
Offline Offline

Activity: 43
Merit: 1


View Profile
November 09, 2017, 08:07:11 PM
 #1

I'm trying to analyze fees in the blockchain and I wrote a script in Python using bitcoinrpc library and getrawtransaction RPC call. However, getrawtransaction does not print vin values, only corresponding txids so I had to read all those transactions and extract the values from vout of the parent transactions. The script works but is very slow, each block takes a few minutes to process.

Is there a faster way to do it? I want a local solution (I can patch Bitcoin Core if necessary) but downloading e.g. from blockchain.info will not work because they have limits on the number of queries.
1715443648
Hero Member
*
Offline Offline

Posts: 1715443648

View Profile Personal Message (Offline)

Ignore
1715443648
Reply with quote  #2

1715443648
Report to moderator
1715443648
Hero Member
*
Offline Offline

Posts: 1715443648

View Profile Personal Message (Offline)

Ignore
1715443648
Reply with quote  #2

1715443648
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
November 09, 2017, 08:51:53 PM
 #2

Is there a faster way to do it? I want a local solution (I can patch Bitcoin Core if necessary) but downloading e.g. from blockchain.info will not work because they have limits on the number of queries.

You could write a program to maintain your own indexed UTXO list, and then just grab the values from your list.
PVminer (OP)
Jr. Member
*
Offline Offline

Activity: 43
Merit: 1


View Profile
November 09, 2017, 10:50:28 PM
 #3


You could write a program to maintain your own indexed UTXO list, and then just grab the values from your list.

The problem is that the input transaction does not have to be unspent and the list of all outputs is going to be a large database. And initializing it via RPC will be slow.
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
November 10, 2017, 12:34:56 AM
 #4

the list of all outputs is going to be a large database.

And this is why it is so slow for you to look it up right now.  The blockchain is effectively a database of all outputs.  The value of the input is NOT stored in the transaction.  It is ONLY stored in the output that is being spent, so you have to go find it (either in the blockchain or your own database).
byteball
Member
**
Offline Offline

Activity: 266
Merit: 42

The rising tide lifts all boats


View Profile
November 14, 2017, 04:48:28 PM
 #5

Have a look at https://github.com/metrodexcoin/litecoin/blob/getblocksummary/src/rpc/misc.cpp#L651

getblocksummary RPC method.

The code that might help you to calculate each tx fee is commented out, in lines 691-700.

The reason I commented it out (after writing it myself) was that I only needed the fee for entire block,
which I can find in the coinbase transaction. Line 706 has the calculation.

In your case, you would need a similar method that returns fee for every transaction in the block.
Having -txindex is vital for this (see line 660), as transactions with all outputs already spent are not linked from UTXO
and therefore not easily findable, unless you know their block hash or height.

I can do this for a small donation or bounty, when I have free time, if C++ is alien to you Smiley

Ceterum censeo Civitatem Profunda esse delendam
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!