Skip to content

Commit ed76e54

Browse files
author
Ji Qiren
committed
fix decimal precision
1 parent ee63584 commit ed76e54

File tree

9 files changed

+60
-57
lines changed

9 files changed

+60
-57
lines changed

common/decimal.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ func RescalePair(a *Decimal, b *Decimal) (*Decimal, *Decimal, error) {
211211
return a, bChanged, nil
212212
}
213213

214+
func NewDecimalZero() *Decimal {
215+
return &Decimal{Value: 0, Scale: 0}
216+
}
217+
214218
func NewDecimalFromInt(v int) *Decimal {
215219
return &Decimal{Value: int64(v), Scale: 0}
216220
}

rpc/api_service.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ func (as *APIService) GetAccount(ctx context.Context, req *rpcpb.GetAccountReque
309309
ret := toPbAccount(acc)
310310

311311
// pack balance and ram information
312-
balance := dbVisitor.TokenBalanceFixed("iost", req.GetName()).Float64()
313-
ret.Balance = balance
312+
balance := dbVisitor.TokenBalanceDecimal("iost", req.GetName())
314313
ramInfo := dbVisitor.RAMHandler.GetAccountRAMInfo(req.GetName())
315314
ret.RamInfo = &rpcpb.Account_RAMInfo{
316315
Available: ramInfo.Available,
@@ -344,10 +343,10 @@ func (as *APIService) GetAccount(ctx context.Context, req *rpcpb.GetAccountReque
344343
}
345344

346345
// pack frozen balance information
347-
frozen := dbVisitor.AllFreezedTokenBalanceFixed("iost", req.GetName())
346+
frozen := dbVisitor.AllFreezedTokenBalanceDecimal("iost", req.GetName())
348347
unfrozen, stillFrozen := as.getUnfrozenToken(frozen, req.ByLongestChain)
349348
ret.FrozenBalances = stillFrozen
350-
ret.Balance += unfrozen
349+
ret.Balance = unfrozen.Add(balance).Float64()
351350

352351
voteInfo := dbVisitor.GetAccountVoteInfo(req.GetName())
353352
for _, v := range voteInfo {
@@ -376,12 +375,12 @@ func (as *APIService) GetTokenBalance(ctx context.Context, req *rpcpb.GetTokenBa
376375
//if acc == nil {
377376
// return nil, errors.New("account not found")
378377
//}
379-
balance := dbVisitor.TokenBalanceFixed(req.GetToken(), req.GetAccount()).Float64()
378+
balance := dbVisitor.TokenBalanceDecimal(req.GetToken(), req.GetAccount())
380379
// pack frozen balance information
381-
frozen := dbVisitor.AllFreezedTokenBalanceFixed(req.GetToken(), req.GetAccount())
380+
frozen := dbVisitor.AllFreezedTokenBalanceDecimal(req.GetToken(), req.GetAccount())
382381
unfrozen, stillFrozen := as.getUnfrozenToken(frozen, req.ByLongestChain)
383382
return &rpcpb.GetTokenBalanceResponse{
384-
Balance: balance + unfrozen,
383+
Balance: balance.Add(unfrozen).Float64(),
385384
FrozenBalances: stillFrozen,
386385
}, nil
387386
}
@@ -1026,18 +1025,18 @@ func (as *APIService) getStateDBVisitor(longestChain bool) (*database.Visitor, *
10261025
return nil, nil, err
10271026
}
10281027

1029-
func (as *APIService) getUnfrozenToken(frozens []database.FreezeItemFixed, longestChain bool) (float64, []*rpcpb.FrozenBalance) {
1028+
func (as *APIService) getUnfrozenToken(frozens []database.FreezeItemDecimal, longestChain bool) (*common.Decimal, []*rpcpb.FrozenBalance) {
10301029
var blockTime int64
10311030
if longestChain {
10321031
blockTime = as.bc.Head().Head.Time
10331032
} else {
10341033
blockTime = as.bc.LinkedRoot().Head.Time
10351034
}
1036-
var unfrozen float64
1035+
var unfrozen *common.Decimal = common.NewDecimalZero()
10371036
var stillFrozen []*rpcpb.FrozenBalance
10381037
for _, f := range frozens {
10391038
if f.Ftime <= blockTime {
1040-
unfrozen += f.Amount.Float64()
1039+
unfrozen = unfrozen.Add(&f.Amount)
10411040
} else {
10421041
stillFrozen = append(stillFrozen, &rpcpb.FrozenBalance{
10431042
Amount: f.Amount.Float64(),

test/integration/gas_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func TestGas_PledgeunpledgeForOther(t *testing.T) {
335335
signerList := make(map[string]bool)
336336
signerList[otherAcc+"@active"] = true
337337
h.Context().Set("signer_list", signerList)
338-
h.DB().SetTokenBalanceFixed("iost", otherAcc, "20")
338+
h.DB().SetTokenBalanceDecimal("iost", otherAcc, "20")
339339
_, _, err = e.LoadAndCall(h, code, "pledge", otherAcc, otherAcc, "20")
340340
So(err, ShouldBeNil)
341341
_, _, err = e.LoadAndCall(h, code, "unpledge", otherAcc, otherAcc, "20")

test/integration/verifier_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func TestTransfer(t *testing.T) {
3030
createToken(t, s, acc)
3131

3232
Reset(func() {
33-
s.Visitor.SetTokenBalanceFixed("iost", acc0.ID, "1000")
34-
s.Visitor.SetTokenBalanceFixed("iost", acc1.ID, "0")
33+
s.Visitor.SetTokenBalanceDecimal("iost", acc0.ID, "1000")
34+
s.Visitor.SetTokenBalanceDecimal("iost", acc1.ID, "0")
3535
s.SetGas(acc.ID, 100000)
3636
s.SetRAM(acc.ID, 10000)
3737
})
@@ -186,8 +186,8 @@ func TestAmountLimit(t *testing.T) {
186186
s.SetRAM(acc0.ID, 10000)
187187

188188
Reset(func() {
189-
s.Visitor.SetTokenBalanceFixed("iost", acc0.ID, "1000")
190-
s.Visitor.SetTokenBalanceFixed("iost", acc1.ID, "0")
189+
s.Visitor.SetTokenBalanceDecimal("iost", acc0.ID, "1000")
190+
s.Visitor.SetTokenBalanceDecimal("iost", acc1.ID, "0")
191191
s.SetGas(acc0.ID, 100000)
192192
s.SetRAM(acc0.ID, 10000)
193193
})
@@ -329,7 +329,7 @@ func TestAmountLimit(t *testing.T) {
329329

330330
Convey("test amount limit transfer from multi signers", func() {
331331
s.SetAccount(acc2.ToAccount())
332-
s.Visitor.SetTokenBalanceFixed("iost", acc2.ID, "1000")
332+
s.Visitor.SetTokenBalanceDecimal("iost", acc2.ID, "1000")
333333

334334
trx := tx.NewTx([]*tx.Action{{
335335
Contract: "Contracttransfer",
@@ -397,8 +397,8 @@ func TestTxAmountLimit(t *testing.T) {
397397
s.SetRAM(acc0.ID, 10000)
398398

399399
Reset(func() {
400-
s.Visitor.SetTokenBalanceFixed("iost", acc0.ID, "1000")
401-
s.Visitor.SetTokenBalanceFixed("iost", acc1.ID, "0")
400+
s.Visitor.SetTokenBalanceDecimal("iost", acc0.ID, "1000")
401+
s.Visitor.SetTokenBalanceDecimal("iost", acc1.ID, "0")
402402
s.SetGas(acc0.ID, 100000)
403403
s.SetRAM(acc0.ID, 10000)
404404
})
@@ -528,8 +528,8 @@ func TestTokenMemo(t *testing.T) {
528528
s.SetRAM(acc0.ID, 10000)
529529

530530
Reset(func() {
531-
s.Visitor.SetTokenBalanceFixed("iost", acc0.ID, "1000")
532-
s.Visitor.SetTokenBalanceFixed("iost", acc1.ID, "0")
531+
s.Visitor.SetTokenBalanceDecimal("iost", acc0.ID, "1000")
532+
s.Visitor.SetTokenBalanceDecimal("iost", acc1.ID, "0")
533533
s.SetGas(acc0.ID, 100000)
534534
s.SetRAM(acc0.ID, 10000)
535535
})
@@ -591,7 +591,7 @@ func TestNativeVM_GasPledgeShortCut(t *testing.T) {
591591
So(r.Status.Message, ShouldEqual, "")
592592
txGasUsage := r.GasUsage / 100
593593
So(s.GetGas(acc0.ID), ShouldEqual, expectedGasAfterPlegde-txGasUsage)
594-
So(s.Visitor.TokenBalanceFixed("iost", acc0.ID).String(), ShouldEqual, strconv.Itoa(int(initialBalance-pledgeAmount)))
594+
So(s.Visitor.TokenBalanceDecimal("iost", acc0.ID).String(), ShouldEqual, strconv.Itoa(int(initialBalance-pledgeAmount)))
595595
})
596596
SkipConvey("vm can kill tx if gas limit is not enough(TODO it is not possible in current code)", func() {
597597
s.SetGas(acc0.ID, 0)
@@ -609,7 +609,7 @@ func TestNativeVM_GasPledgeShortCut(t *testing.T) {
609609
So(r.Status.Message, ShouldContainSubstring, "out of gas")
610610
So(r.Status.Code, ShouldEqual, tx.ErrorRuntime)
611611
So(s.GetGas(acc0.ID), ShouldEqual, expectedGasAfterPlegde-txGasLimit)
612-
So(s.Visitor.TokenBalanceFixed("iost", acc0.ID).String(), ShouldEqual, strconv.Itoa(int(initialBalance-pledgeAmount)))
612+
So(s.Visitor.TokenBalanceDecimal("iost", acc0.ID).String(), ShouldEqual, strconv.Itoa(int(initialBalance-pledgeAmount)))
613613
})
614614
})
615615
}
@@ -709,8 +709,8 @@ func TestGasLimit2(t *testing.T) {
709709
assert.NotNil(t, ca)
710710
s.SetContract(ca)
711711

712-
s.Visitor.SetTokenBalanceFixed("iost", acc0.ID, "1000")
713-
s.Visitor.SetTokenBalanceFixed("iost", acc1.ID, "0")
712+
s.Visitor.SetTokenBalanceDecimal("iost", acc0.ID, "1000")
713+
s.Visitor.SetTokenBalanceDecimal("iost", acc1.ID, "0")
714714
s.SetGas(acc0.ID, 2000000)
715715
s.SetRAM(acc0.ID, 10000)
716716

@@ -733,8 +733,8 @@ func TestGasLimit2(t *testing.T) {
733733
assert.Equal(t, "20", balance2.String())
734734

735735
// out of gas
736-
s.Visitor.SetTokenBalanceFixed("iost", acc0.ID, "1000")
737-
s.Visitor.SetTokenBalanceFixed("iost", acc1.ID, "0")
736+
s.Visitor.SetTokenBalanceDecimal("iost", acc0.ID, "1000")
737+
s.Visitor.SetTokenBalanceDecimal("iost", acc1.ID, "0")
738738
s.SetGas(acc0.ID, 2000000)
739739
s.SetRAM(acc0.ID, 10000)
740740
acts = []*tx.Action{}

test/integration/vm_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ func Test_callWithAuth(t *testing.T) {
3737
So(r.Status.Code, ShouldEqual, tx.Success)
3838

3939
Convey("test of callWithoutAuth", func() {
40-
s.Visitor.SetTokenBalanceFixed("iost", cname, "1000")
40+
s.Visitor.SetTokenBalanceDecimal("iost", cname, "1000")
4141
r, err := s.Call(cname, "withdrawWithoutAuth", fmt.Sprintf(`["%v", "%v"]`, acc0.ID, "10"), acc0.ID, acc0.KeyPair)
4242
So(err, ShouldBeNil)
4343
So(r.Status.Message, ShouldContainSubstring, "transaction has no permission")
4444
s.Visitor.Commit()
4545
})
4646

4747
Convey("test of callWithAuth", func() {
48-
s.Visitor.SetTokenBalanceFixed("iost", cname, "1000")
48+
s.Visitor.SetTokenBalanceDecimal("iost", cname, "1000")
4949
r, err = s.Call(cname, "withdraw", fmt.Sprintf(`["%v", "%v"]`, acc0.ID, "10"), acc0.ID, acc0.KeyPair)
5050
s.Visitor.Commit()
5151

@@ -56,7 +56,7 @@ func Test_callWithAuth(t *testing.T) {
5656
})
5757

5858
Convey("test of callWithoutAuth after callWithAuth", func() {
59-
s.Visitor.SetTokenBalanceFixed("iost", cname, "1000")
59+
s.Visitor.SetTokenBalanceDecimal("iost", cname, "1000")
6060
r, err = s.Call(cname, "withdrawWithoutAuthAfterWithAuth", fmt.Sprintf(`["%v", "%v"]`, acc0.ID, "10"), acc0.ID, acc0.KeyPair)
6161
s.Visitor.Commit()
6262
So(err, ShouldBeNil)
@@ -267,7 +267,7 @@ func Test_RamPayer(t *testing.T) {
267267
ram0 = s.GetRAM(acc0.ID)
268268
ram4 := s.GetRAM(acc2.ID)
269269
ram6 := s.GetRAM(acc3.ID)
270-
s.Visitor.SetTokenBalanceFixed("iost", acc2.ID, "100")
270+
s.Visitor.SetTokenBalanceDecimal("iost", acc2.ID, "100")
271271
r, err = s.Call(cname0, "call", fmt.Sprintf(`["%v", "test", "%v"]`, cname1,
272272
fmt.Sprintf(`[\"%v\", \"%v\"]`, acc2.ID, acc3.ID)), acc2.ID, acc2.KeyPair)
273273
So(err, ShouldBeNil)
@@ -425,8 +425,8 @@ func Test_SpecialChar(t *testing.T) {
425425
s.Visitor.Commit()
426426
So(err, ShouldBeNil)
427427

428-
s.Visitor.SetTokenBalanceFixed("iost", acc.ID, "1000")
429-
s.Visitor.SetTokenBalanceFixed("iost", acc1.ID, "1000")
428+
s.Visitor.SetTokenBalanceDecimal("iost", acc.ID, "1000")
429+
s.Visitor.SetTokenBalanceDecimal("iost", acc1.ID, "1000")
430430
params := []any{
431431
acc.ID,
432432
acc1.ID,
@@ -440,7 +440,7 @@ func Test_SpecialChar(t *testing.T) {
440440
r, err := s.Call(cname, "transfer", string(paramsByte), acc.ID, acc.KeyPair)
441441
So(err, ShouldBeNil)
442442
So(r.Status.Message, ShouldEqual, "")
443-
So(s.Visitor.TokenBalanceFixed("iost", acc1.ID).String(), ShouldEqual, "2000")
443+
So(s.Visitor.TokenBalanceDecimal("iost", acc1.ID).String(), ShouldEqual, "2000")
444444
})
445445
}
446446

test/native/token_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ func TestToken_TransferFreeze(t *testing.T) {
574574
So(err, ShouldBeNil)
575575
So(true, ShouldEqual, len(rs) > 0 && rs[0] == "0")
576576

577-
freezedBalance := host.DB().FreezedTokenBalanceFixed("iost", "user0")
577+
freezedBalance := host.DB().FreezedTokenBalanceDecimal("iost", "user0")
578578
So(freezedBalance.String(), ShouldEqual, "22.3")
579579

580580
rs, cost, err = e.LoadAndCall(host, code, "balanceOf", "iost", "issuer0")
@@ -591,7 +591,7 @@ func TestToken_TransferFreeze(t *testing.T) {
591591
So(err, ShouldBeNil)
592592
So(true, ShouldEqual, len(rs) > 0 && rs[0] == "22.3")
593593

594-
freezedBalance = host.DB().FreezedTokenBalanceFixed("iost", "user0")
594+
freezedBalance = host.DB().FreezedTokenBalanceDecimal("iost", "user0")
595595
So(freezedBalance.String(), ShouldEqual, "0")
596596

597597
// transferFreeze to self
@@ -612,23 +612,23 @@ func TestToken_TransferFreeze(t *testing.T) {
612612
So(err, ShouldBeNil)
613613
So(true, ShouldEqual, len(rs) > 0 && rs[0] == "11.3")
614614

615-
freezedBalance = host.DB().FreezedTokenBalanceFixed("iost", "user0")
615+
freezedBalance = host.DB().FreezedTokenBalanceDecimal("iost", "user0")
616616
So(freezedBalance.String(), ShouldEqual, "11")
617617

618618
host.Context().Set("time", now+11)
619619
rs, cost, err = e.LoadAndCall(host, code, "balanceOf", "iost", "user0")
620620
So(err, ShouldBeNil)
621621
So(true, ShouldEqual, len(rs) > 0 && rs[0] == "21.3")
622622

623-
freezedBalance = host.DB().FreezedTokenBalanceFixed("iost", "user0")
623+
freezedBalance = host.DB().FreezedTokenBalanceDecimal("iost", "user0")
624624
So(freezedBalance.String(), ShouldEqual, "1")
625625

626626
host.Context().Set("time", now+21)
627627
rs, cost, err = e.LoadAndCall(host, code, "balanceOf", "iost", "user0")
628628
So(err, ShouldBeNil)
629629
So(true, ShouldEqual, len(rs) > 0 && rs[0] == "22.3")
630630

631-
freezedBalance = host.DB().FreezedTokenBalanceFixed("iost", "user0")
631+
freezedBalance = host.DB().FreezedTokenBalanceDecimal("iost", "user0")
632632
So(freezedBalance.String(), ShouldEqual, "0")
633633
})
634634

test/native/token_v2_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ func TestTokenV2_TransferFreeze(t *testing.T) {
602602
So(err, ShouldBeNil)
603603
So(true, ShouldEqual, len(rs) > 0 && rs[0] == "0")
604604

605-
freezedBalance := host.DB().FreezedTokenBalanceFixed("iost", "user0")
605+
freezedBalance := host.DB().FreezedTokenBalanceDecimal("iost", "user0")
606606
So(freezedBalance.String(), ShouldEqual, "22.3")
607607

608608
rs, cost, err = e.LoadAndCall(host, code, "balanceOf", "iost", "issuer0")
@@ -619,7 +619,7 @@ func TestTokenV2_TransferFreeze(t *testing.T) {
619619
So(err, ShouldBeNil)
620620
So(true, ShouldEqual, len(rs) > 0 && rs[0] == "22.3")
621621

622-
freezedBalance = host.DB().FreezedTokenBalanceFixed("iost", "user0")
622+
freezedBalance = host.DB().FreezedTokenBalanceDecimal("iost", "user0")
623623
So(freezedBalance.String(), ShouldEqual, "0")
624624

625625
// transferFreeze to self
@@ -640,23 +640,23 @@ func TestTokenV2_TransferFreeze(t *testing.T) {
640640
So(err, ShouldBeNil)
641641
So(true, ShouldEqual, len(rs) > 0 && rs[0] == "11.3")
642642

643-
freezedBalance = host.DB().FreezedTokenBalanceFixed("iost", "user0")
643+
freezedBalance = host.DB().FreezedTokenBalanceDecimal("iost", "user0")
644644
So(freezedBalance.String(), ShouldEqual, "11")
645645

646646
host.Context().Set("time", now+11)
647647
rs, cost, err = e.LoadAndCall(host, code, "balanceOf", "iost", "user0")
648648
So(err, ShouldBeNil)
649649
So(true, ShouldEqual, len(rs) > 0 && rs[0] == "21.3")
650650

651-
freezedBalance = host.DB().FreezedTokenBalanceFixed("iost", "user0")
651+
freezedBalance = host.DB().FreezedTokenBalanceDecimal("iost", "user0")
652652
So(freezedBalance.String(), ShouldEqual, "1")
653653

654654
host.Context().Set("time", now+21)
655655
rs, cost, err = e.LoadAndCall(host, code, "balanceOf", "iost", "user0")
656656
So(err, ShouldBeNil)
657657
So(true, ShouldEqual, len(rs) > 0 && rs[0] == "22.3")
658658

659-
freezedBalance = host.DB().FreezedTokenBalanceFixed("iost", "user0")
659+
freezedBalance = host.DB().FreezedTokenBalanceDecimal("iost", "user0")
660660
So(freezedBalance.String(), ShouldEqual, "0")
661661
})
662662

vm/database/token_handler.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type FreezeItem struct {
2323
Ftime int64
2424
}
2525

26-
// FreezeItemFixed ...
27-
type FreezeItemFixed struct {
26+
// FreezeItemDecimal ...
27+
type FreezeItemDecimal struct {
2828
Amount common.Decimal
2929
Ftime int64
3030
}
@@ -53,8 +53,8 @@ func (m *TokenHandler) TokenBalance(tokenName, acc string) int64 {
5353
return ib
5454
}
5555

56-
// TokenBalanceFixed get token balance of acc
57-
func (m *TokenHandler) TokenBalanceFixed(tokenName, acc string) *common.Decimal {
56+
// TokenBalanceDecimal get token balance of acc
57+
func (m *TokenHandler) TokenBalanceDecimal(tokenName, acc string) *common.Decimal {
5858
ib := m.TokenBalance(tokenName, acc)
5959
return &common.Decimal{Value: ib, Scale: m.Decimal(tokenName)}
6060
}
@@ -97,18 +97,18 @@ func (m *TokenHandler) AllFreezedTokenBalance(tokenName, acc string) []FreezeIte
9797
return freezeList
9898
}
9999

100-
// AllFreezedTokenBalanceFixed get freezed token balance of acc
101-
func (m *TokenHandler) AllFreezedTokenBalanceFixed(tokenName, acc string) []FreezeItemFixed {
100+
// AllFreezedTokenBalanceDecimal get freezed token balance of acc
101+
func (m *TokenHandler) AllFreezedTokenBalanceDecimal(tokenName, acc string) []FreezeItemDecimal {
102102
freezeList := m.AllFreezedTokenBalance(tokenName, acc)
103-
result := make([]FreezeItemFixed, 0)
103+
result := make([]FreezeItemDecimal, 0)
104104
for _, item := range freezeList {
105-
result = append(result, FreezeItemFixed{Amount: common.Decimal{Value: item.Amount, Scale: m.Decimal(tokenName)}, Ftime: item.Ftime})
105+
result = append(result, FreezeItemDecimal{Amount: common.Decimal{Value: item.Amount, Scale: m.Decimal(tokenName)}, Ftime: item.Ftime})
106106
}
107107
return result
108108
}
109109

110-
// FreezedTokenBalanceFixed get token balance of acc
111-
func (m *TokenHandler) FreezedTokenBalanceFixed(tokenName, acc string) *common.Decimal {
110+
// FreezedTokenBalanceDecimal get token balance of acc
111+
func (m *TokenHandler) FreezedTokenBalanceDecimal(tokenName, acc string) *common.Decimal {
112112
ib := m.FreezedTokenBalance(tokenName, acc)
113113
return &common.Decimal{Value: ib, Scale: m.Decimal(tokenName)}
114114
}
@@ -118,11 +118,11 @@ func (m *TokenHandler) SetTokenBalance(tokenName, acc string, amount int64) {
118118
m.db.Put(m.balanceKey(tokenName, acc), MustMarshal(amount))
119119
}
120120

121-
// SetTokenBalanceFixed set token balance of acc, used for test
122-
func (m *TokenHandler) SetTokenBalanceFixed(tokenName, acc string, amountStr string) {
121+
// SetTokenBalanceDecimal set token balance of acc, used for test
122+
func (m *TokenHandler) SetTokenBalanceDecimal(tokenName, acc string, amountStr string) {
123123
amountNumber, err := common.NewDecimalFromString(amountStr, m.Decimal(tokenName))
124124
if err != nil {
125-
panic(errors.New("construct Fixed number failed. str = " + amountStr + ", decimal = " + fmt.Sprintf("%d", m.Decimal(tokenName))))
125+
panic(errors.New("construct decimal number failed. str = " + amountStr + ", decimal = " + fmt.Sprintf("%d", m.Decimal(tokenName))))
126126
}
127127
m.db.Put(m.balanceKey(tokenName, acc), MustMarshal(amountNumber.Value))
128128
}

vm/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func CheckTxGasLimitValid(t *tx.Tx, currentGas *common.Decimal, dbVisitor *datab
2727
if !(args[0] == t.Publisher && args[1] == t.Publisher) {
2828
return defaultErr
2929
}
30-
balance := dbVisitor.TokenBalanceFixed("iost", t.Publisher)
30+
balance := dbVisitor.TokenBalanceDecimal("iost", t.Publisher)
3131
pledgeAmount, err := common.NewDecimalFromString(args[2].(string), 8)
3232
if err != nil {
3333
return fmt.Errorf("invalid gas pledge amount %v %v", err, args[2].(string))

0 commit comments

Comments
 (0)