Set max amount for Withdraw and Deposit methods

These methods initiate `transfer` call on internal
balance method that have Fixed12 precision. With this
limit it will not overflow JSON integer bound 2**53-1

Actual limit is 9007, but it was floored.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-26 18:26:04 +03:00
parent 332e1ceca9
commit 6a881a2baa

View file

@ -81,6 +81,8 @@ const (
blockDiff = 20 // change base on performance evaluation
publicKeySize = 33
minInnerRingSize = 3
maxBalanceAmount = 9000 // Max integer of Fixed12 in JSON bound (2**53-1)
)
var (
@ -199,6 +201,10 @@ func Deposit(from []byte, amount int, rcv []byte) bool {
panic("deposit: you should be the owner of the wallet")
}
if amount > maxBalanceAmount {
panic("deposit: out of max amount limit")
}
if amount <= 0 {
return false
}
@ -233,6 +239,10 @@ func Withdraw(user []byte, amount int) bool {
panic("withdraw: non positive amount number")
}
if amount > maxBalanceAmount {
panic("withdraw: out of max amount limit")
}
amount = amount * 100000000
tx := runtime.GetScriptContainer()