Observing the fee trends using Rust
Fees in bitcoin is a hot topic now and will continue to grow in future given the fact that fees will be the largest revenue factor for a miner than a block reward.
Problem statement
Given a block find the transaction with the largest fee.
The Block
struct has txdata field which is just a Vec<Transaction>
, so if it's length is 0 then we know that we have to return None as it carries no fee.
Computing the Fee of a Transaction
In order to compute the fee of a transaction we need to do the following.
Find the total value of the inputs
Find the total value of the outputs
The difference between them is the fee.
Computing the Total value of outputs
This step is much easier because the TxOut
type has the value field which gives the Amount
of that output. So the following would suffice,
Computing the Total value of inputs
This is a bit involved as the TxIn
type has reference to the previous OutPoint
which has the txid and vout of the previous transaction, vout refers to the index of the output.
So to indentify it's value we have to make request with bitcoinrpc to fetch TxOut
data of that previous transaction.
Last updated