Skip to content

Commit

Permalink
When creating DEx offer, check there is no other
Browse files Browse the repository at this point in the history
  • Loading branch information
dexX7 committed Oct 29, 2019
1 parent 158250d commit f57de0e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/omnicore/dex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ bool DEx_offerExists(const std::string& addressSeller, uint32_t propertyId)
return !(my_offers.find(key) == my_offers.end());
}

/**
* Checks, if the seller has any open offer.
*/
bool DEx_hasOffer(const std::string& addressSeller)
{
for (auto const& offer : my_offers) {
if (offer.first.find(addressSeller) == 0) {
return true;
}
}

return false;
}

/**
* Retrieves a sell offer.
*
Expand Down
1 change: 1 addition & 0 deletions src/omnicore/dex.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ extern AcceptMap my_accepts;
int64_t calculateDesiredBTC(const int64_t amountOffered, const int64_t amountDesired, const int64_t amountAvailable);

bool DEx_offerExists(const std::string& addressSeller, uint32_t propertyId);
bool DEx_hasOffer(const std::string& addressSeller);
CMPOffer* DEx_getOffer(const std::string& addressSeller, uint32_t propertyId);
bool DEx_acceptExists(const std::string& addressSeller, uint32_t propertyId, const std::string& addressBuyer);
CMPAccept* DEx_getAccept(const std::string& addressSeller, uint32_t propertyId, const std::string& addressBuyer);
Expand Down
2 changes: 1 addition & 1 deletion src/omnicore/rpcrequirements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void RequireMatchingDExOffer(const std::string& address, uint32_t propertyId)
void RequireNoOtherDExOffer(const std::string& address, uint32_t propertyId)
{
LOCK(cs_tally);
if (mastercore::DEx_offerExists(address, propertyId)) {
if (mastercore::DEx_hasOffer(address)) {
throw JSONRPCError(RPC_TYPE_ERROR, "Another active sell offer from the given address already exists on the distributed exchange");
}
}
Expand Down

0 comments on commit f57de0e

Please sign in to comment.