"encoding/hex"
"sort"
+ "github.com/vapor/common/compute"
"github.com/vapor/config"
"github.com/vapor/consensus"
"github.com/vapor/crypto/ed25519/chainkd"
coinbaseAmount := consensus.BlockSubsidy(block.BlockHeader.Height)
for _, tx := range block.Transactions {
- txFee := CalculateTxFee(tx)
+ txFee := compute.CalculateTxFee(tx)
if txFee < 0 {
return nil, errors.Wrap(errMathOperationOverFlow, "calculate transaction fee")
}
}, nil
}
-// CalculateTxFee calculate transaction fee
-func CalculateTxFee(tx *types.Tx) uint64 {
- var totalInputBTM, totalOutputBTM uint64
- for _, input := range tx.Inputs {
- if input.InputType() == types.CoinbaseInputType {
- return 0
- }
- if input.AssetID() == *consensus.BTMAssetID {
- totalInputBTM += input.Amount()
- }
- }
-
- for _, output := range tx.Outputs {
- if *output.AssetAmount().AssetId == *consensus.BTMAssetID {
- totalOutputBTM += output.AssetAmount().Amount
- }
- }
- return totalInputBTM - totalOutputBTM
-}
-
// GetCoinbaseRewards convert into CoinbaseReward array and sort it by amount
func (c *ConsensusResult) GetCoinbaseRewards(blockHeight uint64) ([]CoinbaseReward, error) {
rewards := []CoinbaseReward{}