2
I want to know how one can query bitcoin core via json rpc or other methods to find all the transaction fees in a block? API queries are not useful as they have a rate limit.
Here is an example block, for which i want to calculate transaction fees
2
I want to know how one can query bitcoin core via json rpc or other methods to find all the transaction fees in a block? API queries are not useful as they have a rate limit.
Here is an example block, for which i want to calculate transaction fees
1
As the block id is known, the fee can be found from the coinbase itself without an overhead. Maintain a simple map for reward points saying blocks between 0-149 gives 50 BTC, next 149 25 etc.
Now, the first transaction in any block is always a coinbase tran. Coinbasetran->vout[0] - reward = Fee (actual fee + unclaimed change)
0
Here is a simple workaround.
txDetails of blockToJSON() in rpcblockchain.cppChanges Needed:
--- a/src/rpcblockchain.cpp
+++ b/src/rpcblockchain.cpp
@@ -423,7 +423,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
return strHex;
}
- return blockToJSON(block, pblockindex);
+ return blockToJSON(block, pblockindex, true);
}
getblock <HASH> JSON RPC command. Now, it will throw all the transaction details. Coinbase transaction can help you infer your fees (NOTE that the logic can also be incorporated in above code but I am keeping it simple) Example output:
.....
"vout": [
{
"value": 25.04810000,
"n": 0,
"scriptPubKey": {
"asm": "02b551067a9159d3964cb5c5b15d57169c0b2e24fefcfe768c6624ff1a6cedf7b5 OP_CHECKSIG",
"hex": "2102b551067a9159d3964cb5c5b15d57169c0b2e24fefcfe768c6624ff1a6cedf7b5ac",
"reqSigs": 1,
"type": "pubkey",
"addresses": [
"mqu1hVy32hcojhq12kt21kVaCd7g4nwPU5"
]
}
}
]
}
],
.....