4 "github.com/bytom/vapor/consensus"
5 "github.com/bytom/vapor/math/checked"
6 "github.com/bytom/vapor/protocol/bc/types"
9 // CalculateTxFee calculate transaction fee
10 func CalculateTxFee(tx *types.Tx) (fee uint64, err error) {
12 for _, input := range tx.Inputs {
13 if input.InputType() == types.CoinbaseInputType {
16 if input.AssetID() == *consensus.BTMAssetID {
17 if fee, ok = checked.AddUint64(fee, input.Amount()); !ok {
18 return 0, checked.ErrOverflow
23 for _, output := range tx.Outputs {
24 if *output.AssetAmount().AssetId == *consensus.BTMAssetID {
25 if fee, ok = checked.SubUint64(fee, output.AssetAmount().Amount); !ok {
26 return 0, checked.ErrOverflow