diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 33769f557d..ac6acc799c 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -826,7 +826,7 @@ web3._extend({ new web3._extend.Method({ name: 'updateBalance', call: 'les_updateBalance', - params: 4 + params: 3 }), ], properties: diff --git a/les/api.go b/les/api.go index f8e406fc20..7582ccc45e 100644 --- a/les/api.go +++ b/les/api.go @@ -235,8 +235,8 @@ loop: // UpdateBalance updates the balance of a client (either overwrites it or adds to it). // It also updates the balance meta info string. -func (api *PrivateLightServerAPI) UpdateBalance(id enode.ID, value int64, add bool, meta string) error { - return api.server.clientPool.updateBalance(id, value, add, meta) +func (api *PrivateLightServerAPI) UpdateBalance(id enode.ID, value int64, meta string) error { + return api.server.clientPool.updateBalance(id, value, meta) } // SetClientParams sets client parameters for all clients listed in the ids list diff --git a/les/clientpool.go b/les/clientpool.go index d12deed032..78b24fe3e7 100644 --- a/les/clientpool.go +++ b/les/clientpool.go @@ -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). // 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() defer f.lock.Unlock() @@ -588,27 +588,17 @@ func (f *clientPool) updateBalance(id enode.ID, amount int64, add bool, meta str c.balanceMetaInfo = meta }() } - if add { - if amount > 0 { - 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 { + if amount > 0 { + if amount > maxBalance || pb.value > maxBalance-uint64(amount) { return errBalanceOverflow } - if amount < 0 { - amount = 0 + pb.value += uint64(amount) + } else { + if uint64(-amount) > pb.value { + pb.value = 0 + } else { + pb.value -= uint64(-amount) } - pb.value = uint64(amount) } pb.meta = meta f.ndb.setPB(id, pb)