Minor bugfix

This commit is contained in:
luk3yx 2020-10-04 17:03:19 +13:00
parent a5e8911855
commit 8e87b4b806
2 changed files with 15 additions and 10 deletions

View File

@ -35,7 +35,7 @@ import (
) )
const SYMBOL = "¤" const SYMBOL = "¤"
const VERSION = "3.0.5" const VERSION = "3.0.6"
// 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"

View File

@ -53,6 +53,9 @@ func (sourceServer *Server) Pay(source, target string,
// No stealing // No stealing
if !sentAmount.GtZero() || !amount.GtZero() { if !sentAmount.GtZero() || !amount.GtZero() {
if amount.IsZero() {
return nil, errors.New("ERR_CANNOTPAYNOTHING")
}
return nil, errors.New("ERR_INVALIDAMOUNT") return nil, errors.New("ERR_INVALIDAMOUNT")
} }
@ -60,14 +63,13 @@ func (sourceServer *Server) Pay(source, target string,
return nil, errors.New("ERR_TRANSACTIONLIMIT") return nil, errors.New("ERR_TRANSACTIONLIMIT")
} }
// Remove the amount var receivedAmount Currency
success := sourceServer.ChangeBal(amount.Neg()) if sourceServer == targetServer {
if !success { receivedAmount = sentAmount
return nil, errors.New("ERR_CANNOTAFFORD") } else {
receivedAmount, _ = targetServer.GetExchangeRate(amount, false)
} }
receivedAmount, _ := targetServer.GetExchangeRate(amount, false)
if !receivedAmount.GtZero() { if !receivedAmount.GtZero() {
return nil, errors.New("ERR_CANNOTPAYNOTHING") return nil, errors.New("ERR_CANNOTPAYNOTHING")
} }
@ -76,10 +78,13 @@ func (sourceServer *Server) Pay(source, target string,
return nil, errors.New("ERR_TRANSACTIONLIMIT") return nil, errors.New("ERR_TRANSACTIONLIMIT")
} }
success = targetServer.ChangeBal(amount) // Remove the amount
if !sourceServer.ChangeBal(amount.Neg()) {
return nil, errors.New("ERR_CANNOTAFFORD")
}
// This should always be true if !targetServer.ChangeBal(amount) {
if !success { // This should never happen
// Revert the previous balance change before returning // Revert the previous balance change before returning
sourceServer.ChangeBal(amount) sourceServer.ChangeBal(amount)
return nil, errors.New("ERR_INTERNALERROR") return nil, errors.New("ERR_INTERNALERROR")