I'm using estimatefee API to calculate transaction fee for Non-Segwit.
I'm using this formula now.
size = 180 * len(inputs) * 34 * len(outputs) + 10
necessary_fee = int(size / 1000 * fee_per_kb)
Example (1 inputs, 2 outputs. They are all p2pkh)
fee_per_kb = 25000 // result of bitcoin-cli estimatefee
size = 180 * 1 * 34 * 2 + 10
necessary_fee = int(size / 1000 * 25000)
// necessary_fee => 306250 satoshi
Now I need to calculate fee for Segwit. My question is that can I use bitcoin-cli estimatefee for weight? My expectation is this like below.
fee_per_kb = 25000 // result of bitcoin-cli estimatefee
virtual_size = (Something calculation logic including segwit discount)
necessary_fee = int(virtual_size / 1000 * 25000)
estimatesmartfee
instead.