Skip to content

Commit 51cb59e

Browse files
committed
Reject "over-offers" after DEx feature activation
After this feature is enabled, it is no longer valid to create orders, which offer more than the seller has available, and the amounts are no longer adjusted based on the actual balance. The second check can be left untouched, because the order adjustment is desired, as long as the feature is not enabled, and after the feature is enabled, it's body is no longer reached.
1 parent ca6be69 commit 51cb59e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/omnicore/dex.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "omnicore/errors.h"
1111
#include "omnicore/log.h"
1212
#include "omnicore/omnicore.h"
13+
#include "omnicore/rules.h"
1314

1415
#include "main.h"
1516
#include "tinyformat.h"
@@ -112,7 +113,7 @@ static int64_t calculateDesiredBTC(const int64_t amountOffered, const int64_t am
112113
/**
113114
* Determines the amount of bitcoins desired, in case it needs to be recalculated.
114115
*
115-
* TODO: use plain integers, don't expose it!
116+
* TODO: don't expose it!
116117
* @return The amount of bitcoins desired
117118
*/
118119
int64_t calculateDesiredBTC(const int64_t amountOffered, const int64_t amountDesired, const int64_t amountAvailable)
@@ -151,6 +152,21 @@ int DEx_offerCreate(const std::string& addressSeller, uint32_t propertyId, int64
151152

152153
const int64_t balanceReallyAvailable = getMPbalance(addressSeller, propertyId, BALANCE);
153154

155+
/**
156+
* After this feature is enabled, it is no longer valid to create orders, which offer more than
157+
* the seller has available, and the amounts are no longer adjusted based on the actual balance.
158+
*/
159+
if (IsFeatureActivated(FEATURE_DEXMATH, block)) {
160+
if (amountOffered > balanceReallyAvailable) {
161+
PrintToLog("%s: rejected: sender %s has insufficient balance of property %d [%s < %s]\n", __func__,
162+
addressSeller, propertyId, FormatDivisibleMP(balanceReallyAvailable), FormatDivisibleMP(amountOffered));
163+
return (DEX_ERROR_SELLOFFER -25);
164+
}
165+
}
166+
167+
// -------------------------------------------------------------------------
168+
// legacy::
169+
154170
// if offering more than available -- put everything up on sale
155171
if (amountOffered > balanceReallyAvailable) {
156172
PrintToLog("%s: adjusting order: %s offers %s %s, but has only %s %s available\n", __func__,
@@ -165,6 +181,7 @@ int DEx_offerCreate(const std::string& addressSeller, uint32_t propertyId, int64
165181
PrintToLog("%s: adjusting order: updated amount for sale: %s %s, offered for: %s BTC\n", __func__,
166182
FormatDivisibleMP(amountOffered), strMPProperty(propertyId), FormatDivisibleMP(amountDesired));
167183
}
184+
// -------------------------------------------------------------------------
168185

169186
if (amountOffered > 0) {
170187
assert(update_tally_map(addressSeller, propertyId, -amountOffered, BALANCE));

0 commit comments

Comments
 (0)