getblock info for calculating balances

+1 vote
Looking at the data for getblock, we can store that data in our database and update balances. eg:

For asset transfers

vout n=0 :  amount 30 of an asset with type transfer, we can add that to an address
vout n=1 (or next number with different address) : amount of 30 (from above n=0) deduct from the address listed there

For native currency transfers, not quite sure how best to calculate it, as the tx fee varies.

Does anyone have advice on how to calculate from getblock and transaction data?
asked Oct 23, 2017 by mark

1 Answer

0 votes

First you can't rely on the vout indexes, since transactions can have their output ordering reversed and still move money in the same way. If you want to safely calculate the change in address balances due to a transaction, you need to reference its spent inputs and compare them to its outputs. You should have the information about its spent inputs from previous transactions also in your database.

answered Oct 23, 2017 by MultiChain
...