Decrease max spend to 10,000 and check this when getting exchange rate

This commit is contained in:
luk3yx 2021-07-25 14:59:27 +12:00
parent dd0549ba8b
commit d0e433e209
2 changed files with 17 additions and 3 deletions

View File

@ -35,14 +35,14 @@ import (
) )
const SYMBOL = "¤" const SYMBOL = "¤"
const VERSION = "3.0.9" const VERSION = "3.0.10"
// Note that public source code is required by the AGPL // Note that public source code is required by the AGPL
const SOURCE_URL = "https://github.com/luk3yx/lurkcoin-core" const SOURCE_URL = "https://github.com/luk3yx/lurkcoin-core"
const REPORT_SECURITY = "https://gitlab.com/luk3yx/lurkcoin-core/-/issues/new" const REPORT_SECURITY = "https://gitlab.com/luk3yx/lurkcoin-core/-/issues/new"
// Copyrights should be separated by newlines // Copyrights should be separated by newlines
const COPYRIGHT = "Copyright © 2020 by luk3yx" const COPYRIGHT = "Copyright © 2021 by luk3yx"
func PrintASCIIArt() { func PrintASCIIArt() {
log.Print(`/\___/\ _ _ _`) log.Print(`/\___/\ _ _ _`)
@ -141,12 +141,20 @@ func GetExchangeRate(db Database, source, target string, amount Currency) (Curre
return amount, nil return amount, nil
} }
// Check the amount against the transaction limit
if amount.Gt(transactionLimit) {
return c0, errors.New("ERR_TRANSACTIONLIMIT")
}
if source != "" { if source != "" {
sourceServer, ok := tr.GetOneServer(source) sourceServer, ok := tr.GetOneServer(source)
if !ok { if !ok {
return c0, errors.New("ERR_SOURCESERVERNOTFOUND") return c0, errors.New("ERR_SOURCESERVERNOTFOUND")
} }
amount, _ = sourceServer.GetExchangeRate(amount, true) amount, _ = sourceServer.GetExchangeRate(amount, true)
if amount.Gt(transactionLimit) {
return c0, errors.New("ERR_TRANSACTIONLIMIT")
}
// Abort the transaction now to get the target server // Abort the transaction now to get the target server
tr.Abort() tr.Abort()
@ -157,6 +165,9 @@ func GetExchangeRate(db Database, source, target string, amount Currency) (Curre
return c0, errors.New("ERR_TARGETSERVERNOTFOUND") return c0, errors.New("ERR_TARGETSERVERNOTFOUND")
} }
amount, _ = targetServer.GetExchangeRate(amount, false) amount, _ = targetServer.GetExchangeRate(amount, false)
if amount.Gt(transactionLimit) {
return c0, errors.New("ERR_TRANSACTIONLIMIT")
}
} }
return amount, nil return amount, nil
} }

View File

@ -25,7 +25,10 @@ import (
// The transaction limit, currently 1e+11 so clients that parse JSON numbers as // The transaction limit, currently 1e+11 so clients that parse JSON numbers as
// 64-bit floats won't run into issues. // 64-bit floats won't run into issues.
var transactionLimit Currency = CurrencyFromInt64(100000000000) // var transactionLimit Currency = CurrencyFromInt64(100000000000)
// Temporarily changed to 10,000 due to broken exchange rate calculations
var transactionLimit Currency = CurrencyFromInt64(10000)
// Sends a payment. // Sends a payment.
func (sourceServer *Server) Pay(source, target string, func (sourceServer *Server) Pay(source, target string,