From d0e433e20949c8bdb68b64d956a601de7e417ec3 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Sun, 25 Jul 2021 14:59:27 +1200 Subject: [PATCH] Decrease max spend to 10,000 and check this when getting exchange rate --- lurkcoin/misc.go | 15 +++++++++++++-- lurkcoin/payments.go | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lurkcoin/misc.go b/lurkcoin/misc.go index 39be9a6..585f6a5 100644 --- a/lurkcoin/misc.go +++ b/lurkcoin/misc.go @@ -35,14 +35,14 @@ import ( ) const SYMBOL = "¤" -const VERSION = "3.0.9" +const VERSION = "3.0.10" // Note that public source code is required by the AGPL const SOURCE_URL = "https://github.com/luk3yx/lurkcoin-core" const REPORT_SECURITY = "https://gitlab.com/luk3yx/lurkcoin-core/-/issues/new" // Copyrights should be separated by newlines -const COPYRIGHT = "Copyright © 2020 by luk3yx" +const COPYRIGHT = "Copyright © 2021 by luk3yx" func PrintASCIIArt() { log.Print(`/\___/\ _ _ _`) @@ -141,12 +141,20 @@ func GetExchangeRate(db Database, source, target string, amount Currency) (Curre return amount, nil } + // Check the amount against the transaction limit + if amount.Gt(transactionLimit) { + return c0, errors.New("ERR_TRANSACTIONLIMIT") + } + if source != "" { sourceServer, ok := tr.GetOneServer(source) if !ok { return c0, errors.New("ERR_SOURCESERVERNOTFOUND") } amount, _ = sourceServer.GetExchangeRate(amount, true) + if amount.Gt(transactionLimit) { + return c0, errors.New("ERR_TRANSACTIONLIMIT") + } // Abort the transaction now to get the target server tr.Abort() @@ -157,6 +165,9 @@ func GetExchangeRate(db Database, source, target string, amount Currency) (Curre return c0, errors.New("ERR_TARGETSERVERNOTFOUND") } amount, _ = targetServer.GetExchangeRate(amount, false) + if amount.Gt(transactionLimit) { + return c0, errors.New("ERR_TRANSACTIONLIMIT") + } } return amount, nil } diff --git a/lurkcoin/payments.go b/lurkcoin/payments.go index 64e70f6..9d50299 100644 --- a/lurkcoin/payments.go +++ b/lurkcoin/payments.go @@ -25,7 +25,10 @@ import ( // The transaction limit, currently 1e+11 so clients that parse JSON numbers as // 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. func (sourceServer *Server) Pay(source, target string,