les: removed "add" field from UpdateBalance

This commit is contained in:
Zsolt Felfoldi 2019-11-02 20:21:08 +01:00
parent 61d6ebab84
commit 8248dfea19
3 changed files with 12 additions and 22 deletions

View file

@ -826,7 +826,7 @@ web3._extend({
new web3._extend.Method({ new web3._extend.Method({
name: 'updateBalance', name: 'updateBalance',
call: 'les_updateBalance', call: 'les_updateBalance',
params: 4 params: 3
}), }),
], ],
properties: properties:

View file

@ -235,8 +235,8 @@ loop:
// UpdateBalance updates the balance of a client (either overwrites it or adds to it). // UpdateBalance updates the balance of a client (either overwrites it or adds to it).
// It also updates the balance meta info string. // It also updates the balance meta info string.
func (api *PrivateLightServerAPI) UpdateBalance(id enode.ID, value int64, add bool, meta string) error { func (api *PrivateLightServerAPI) UpdateBalance(id enode.ID, value int64, meta string) error {
return api.server.clientPool.updateBalance(id, value, add, meta) return api.server.clientPool.updateBalance(id, value, meta)
} }
// SetClientParams sets client parameters for all clients listed in the ids list // SetClientParams sets client parameters for all clients listed in the ids list

View file

@ -564,7 +564,7 @@ func (f *clientPool) getPosBalance(id enode.ID) posBalance {
// updateBalance updates the balance of a client (either overwrites it or adds to it). // updateBalance updates the balance of a client (either overwrites it or adds to it).
// It also updates the balance meta info string. // It also updates the balance meta info string.
func (f *clientPool) updateBalance(id enode.ID, amount int64, add bool, meta string) error { func (f *clientPool) updateBalance(id enode.ID, amount int64, meta string) error {
f.lock.Lock() f.lock.Lock()
defer f.lock.Unlock() defer f.lock.Unlock()
@ -588,27 +588,17 @@ func (f *clientPool) updateBalance(id enode.ID, amount int64, add bool, meta str
c.balanceMetaInfo = meta c.balanceMetaInfo = meta
}() }()
} }
if add { if amount > 0 {
if amount > 0 { if amount > maxBalance || pb.value > maxBalance-uint64(amount) {
if amount > maxBalance || pb.value > maxBalance-uint64(amount) {
return errBalanceOverflow
}
pb.value += uint64(amount)
} else {
if uint64(-amount) > pb.value {
pb.value = 0
} else {
pb.value -= uint64(-amount)
}
}
} else {
if amount > maxBalance {
return errBalanceOverflow return errBalanceOverflow
} }
if amount < 0 { pb.value += uint64(amount)
amount = 0 } else {
if uint64(-amount) > pb.value {
pb.value = 0
} else {
pb.value -= uint64(-amount)
} }
pb.value = uint64(amount)
} }
pb.meta = meta pb.meta = meta
f.ndb.setPB(id, pb) f.ndb.setPB(id, pb)