add gas price variables and function

This commit is contained in:
Daniel Liu 2023-10-16 11:22:19 +08:00
parent 548aa05990
commit 3764cb3d84
2 changed files with 35 additions and 0 deletions

View file

@ -77,6 +77,7 @@ var BaseTopUp = big.NewInt(100)
var BaseRecall = big.NewInt(100)
var TIPTRC21Fee = big.NewInt(38383838)
var TIPTRC21FeeTestnet = big.NewInt(38383838)
var BlockNumberGas50x = big.NewInt(TIPTRC21Fee.Int64() + 30000000)
var LimitTimeFinality = uint64(30) // limit in 30 block
var IgnoreSignerCheckBlockArray = map[uint64]bool{

34
common/gas.go Normal file
View file

@ -0,0 +1,34 @@
package common
import "math/big"
var MinGasPrice50x = big.NewInt(12500000000)
var GasPrice50x = big.NewInt(12500000000)
func GetGasFee(blockNumber, gas uint64) *big.Int {
fee := new(big.Int).SetUint64(gas)
if blockNumber >= BlockNumberGas50x.Uint64() {
fee = fee.Mul(fee, GasPrice50x)
} else if blockNumber > TIPTRC21Fee.Uint64() {
fee = fee.Mul(fee, TRC21GasPrice)
}
return fee
}
func GetGasPrice(number *big.Int) *big.Int {
if number == nil || number.Cmp(BlockNumberGas50x) < 0 {
return new(big.Int).Set(TRC21GasPrice)
} else {
return new(big.Int).Set(GasPrice50x)
}
}
func GetMinGasPrice(number *big.Int) *big.Int {
if number == nil || number.Cmp(BlockNumberGas50x) < 0 {
return new(big.Int).Set(MinGasPrice)
} else {
return new(big.Int).Set(MinGasPrice50x)
}
}