Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gas.go #2101

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions packages/smart/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewFuelCategory(fuelType FuelType, decimal decimal.Decimal, flag GasPayAble
}

func (f *FuelCategory) writeFuelType(fuelType FuelType) { f.FuelType = fuelType }
func (f *FuelCategory) writeDecimal(decimal decimal.Decimal) { f.Decimal = decimal.Floor() }
func (f *FuelCategory) writeDecimal(decimal decimal.Decimal) { f.Decimal = decimal }
func (f *FuelCategory) writeArithmetic(a Arithmetic) { f.Arithmetic = a }
func (f *FuelCategory) resetArithmetic() { f.Arithmetic = Arithmetic_NATIVE }
func (f *FuelCategory) writeFlag(tf GasPayAbleType) {
Expand Down Expand Up @@ -601,13 +601,11 @@ func (sc *SmartContract) getChangeAddress(eco int64) ([]*PaymentInfo, error) {
continue
}
category := NewFuelCategory(FuelType(FuelType_value[k]), categoryFee, GasPayAbleType(flag.FlagToInt()), flag.ConversionRateToFloat())
var div = category.Decimal.Div(decimal.NewFromFloat(feeMode.FollowFuel))

switch category.Flag {
case GasPayAbleType_Unable:
category.writeDecimal(category.Decimal.Shift(int32(cpyPlatCaller.Ecosystem.Digits - curPay.Ecosystem.Digits)))
cpyPlatCaller.PushFuelCategories(category)
if category.FuelType == FuelType_expedite_fee {
cpyPlatCaller.SetDecimalByType(category.FuelType, div)
}
case GasPayAbleType_Capable:
// exclude FuelType_expedite_fee
if category.FuelType != FuelType_expedite_fee {
Expand All @@ -616,14 +614,11 @@ func (sc *SmartContract) getChangeAddress(eco int64) ([]*PaymentInfo, error) {
}
indirectPay.PushFuelCategories(category)
category.resetArithmetic()
category.writeDecimal(category.Decimal.Shift(int32(cpyPlatIndirect.Ecosystem.Digits - curPay.Ecosystem.Digits)))
if category.FuelType == FuelType_expedite_fee {
category.writeArithmetic(Arithmetic_DIV)
category.writeDecimal(category.Decimal.Div(decimal.NewFromFloat(feeMode.FollowFuel)))
}
cpyPlatIndirect.PushFuelCategories(category)
if category.FuelType == FuelType_expedite_fee {
cpyPlatIndirect.SetDecimalByType(category.FuelType, div)
indirectPay.SetDecimalByType(category.FuelType, div)
}
}
}
pays = append(pays, cpyPlatCaller, cpyPlatIndirect, indirectPay, curPay)
Expand Down