Most efficient way to calculate fee from getrawtransaction? I would to get the fee when I search for a transaction using getrawtransaction, but the JSON-RPC does not return this.

https://chainquery.com/bitcoin-api/getrawtransaction

So to achieve this, my idea is to:


Call getrawtransaction for each vin, and save the output value for each one.
Sum all the output value for the vins, and subtract the sum of the vout values to give you the remainder.


I know this will work, but I dislike having to call getrawtransaction for each vin (as this JSON-RPC call will be made 200+ times for some transactions).

Is there a more efficient way? Or is this currently the only way to calculate the fee for a transaction using bitcoin-cli?


  Aside: Why doesn't getrawtransaction return a fee field, like the transactions in getrawmempool and getblocktemplate do?
To calculate fees.
Take sum of all vouts.For every vin there will be prev txid and outputindex,
Get this txid with getrawtransaction or some other way,go to vouts of this new tx at index, here you will get amount,
Repeat this for every vin.
Take sum of this vins. 
Take difference between vin and vout you will get fees.

To avoid calling ever time you need to store txids somewhere or user something like insight.