1 Star 0 Fork 0

艾鸥科技 / go-aiou

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils.go 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
张卓 提交于 2020-05-10 14:55 . init
package vm
import (
"fmt"
"gitee.com/aiou-official/go-aiou/common"
"gitee.com/aiou-official/go-aiou/core/global"
"gitee.com/aiou-official/go-aiou/core/tx"
"gitee.com/aiou-official/go-aiou/vm/database"
"gitee.com/aiou-official/go-aiou/vm/native"
)
// CheckTxGasLimitValid ...
func CheckTxGasLimitValid(t *tx.Tx, currentGas *common.Fixed, dbVisitor *database.Visitor) (err error) {
gasLimit := &common.Fixed{Value: t.GasLimit, Decimal: 2}
if !currentGas.LessThan(gasLimit) {
return nil
}
defaultErr := fmt.Errorf("gas not enough: user %v has %v < %v", t.Publisher, currentGas.ToString(), gasLimit.ToString())
if !(len(t.Actions) == 1 && t.Actions[0].Contract == native.GasContractName && t.Actions[0].ActionName == "pledge") {
return defaultErr
}
// user is trying to pledge for gas without initial gas
args, err := UnmarshalArgs(dbVisitor.Contract(native.GasContractName).ABI("pledge"), t.Actions[0].Data)
if err != nil {
return fmt.Errorf("invalid gas pledge args %v %v", err, t.Actions[0].Data)
}
if !(args[0] == t.Publisher && args[1] == t.Publisher) {
return defaultErr
}
balance := dbVisitor.TokenBalanceFixed(global.Token, t.Publisher)
pledgeAmount, err := common.NewFixed(args[2].(string), 8)
if err != nil {
return fmt.Errorf("invalid gas pledge amount %v %v", err, args[2].(string))
}
if pledgeAmount.LessThan(database.GasMinPledgePerAction) {
return fmt.Errorf("invalid gas pledge amount %v %v", err, args[2].(string))
}
if balance.LessThan(pledgeAmount) {
return fmt.Errorf("aiou token amount not enough for pledgement %v < %v", balance.ToString(), pledgeAmount.ToString())
}
if currentGas.Add(pledgeAmount.Multiply(database.GasImmediateReward)).LessThan(gasLimit) {
return fmt.Errorf("gas not enough even if considering the new gas pledgement %v + %v < %v",
currentGas.ToString(), pledgeAmount.Multiply(database.GasImmediateReward).ToString(), gasLimit.ToString())
}
return nil
}
1
https://gitee.com/aiou-official/go-aiou.git
git@gitee.com:aiou-official/go-aiou.git
aiou-official
go-aiou
go-aiou
376a44096468

搜索帮助