Skip to content

Commit

Permalink
Merge bitcoin#7: Wrap primary token check in FREEDEX conditional
Browse files Browse the repository at this point in the history
c37ffc3 omni_getactivedexsells display indivisible tokens correctly (Peter Bushnell)
6e242b4 Corrections to DEx pay call (Bushstar)

Pull request description:

Tree-SHA512: a60e26ba6b0401385e84ba498a1debca7ce5a84d4c79d07bff96d5f636b2044bd52ad6c97b3a11ac072a775c18b48aa4135b03c63041a0c96dacf0542b750291
  • Loading branch information
dexX7 committed May 2, 2020
2 parents 8f13b84 + c37ffc3 commit 01915f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/omnicore/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,9 @@ static UniValue omni_getactivedexsells(const JSONRPCRequest& request)
double unitPriceFloat = 0.0;
if ((sellOfferAmount > 0) && (sellBitcoinDesired > 0)) {
unitPriceFloat = (double) sellBitcoinDesired / (double) sellOfferAmount; // divide by zero protection
if (!isPropertyDivisible(propertyId)) {
unitPriceFloat /= 100000000;
}
}
int64_t unitPrice = rounduint64(unitPriceFloat * COIN);
int64_t bitcoinDesired = calculateDesiredBTC(sellOfferAmount, sellBitcoinDesired, amountAvailable);
Expand All @@ -1935,7 +1938,7 @@ static UniValue omni_getactivedexsells(const JSONRPCRequest& request)
responseObj.pushKV("txid", txid);
responseObj.pushKV("propertyid", (uint64_t) propertyId);
responseObj.pushKV("seller", seller);
responseObj.pushKV("amountavailable", FormatDivisibleMP(amountAvailable));
responseObj.pushKV("amountavailable", isPropertyDivisible(propertyId) ? FormatDivisibleMP(amountAvailable) : FormatIndivisibleMP(amountAvailable));
responseObj.pushKV("bitcoindesired", FormatDivisibleMP(bitcoinDesired));
responseObj.pushKV("unitprice", FormatDivisibleMP(unitPrice));
responseObj.pushKV("timelimit", timeLimit);
Expand All @@ -1961,7 +1964,7 @@ static UniValue omni_getactivedexsells(const JSONRPCRequest& request)
matchedAccept.pushKV("buyer", buyer);
matchedAccept.pushKV("block", blockOfAccept);
matchedAccept.pushKV("blocksleft", blocksLeftToPay);
matchedAccept.pushKV("amount", FormatDivisibleMP(amountAccepted));
matchedAccept.pushKV("amount", (isPropertyDivisible(propertyId) ? FormatDivisibleMP(amountAccepted) : FormatIndivisibleMP(amountAccepted)));
matchedAccept.pushKV("amounttopay", FormatDivisibleMP(amountToPayInBTC));
acceptsMatched.push_back(matchedAccept);
}
Expand Down
6 changes: 4 additions & 2 deletions src/omnicore/rpctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ static UniValue omni_senddexpay(const JSONRPCRequest& request)
std::string buyerAddress = ParseText(request.params[0]);
std::string sellerAddress = ParseText(request.params[1]);
uint32_t propertyId = ParsePropertyId(request.params[2]);
CAmount nAmount = ParseAmount(request.params[3], isPropertyDivisible(propertyId));
CAmount nAmount = ParseAmount(request.params[3], true);

// Check parameters are valid
if (nAmount <= 0)
Expand All @@ -702,7 +702,9 @@ static UniValue omni_senddexpay(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid seller address");
}

RequirePrimaryToken(propertyId);
if (!IsFeatureActivated(FEATURE_FREEDEX, GetHeight())) {
RequirePrimaryToken(propertyId);
}
RequireMatchingDExAccept(sellerAddress, propertyId, buyerAddress);

// Get accept offer and make sure buyer is not trying to overpay
Expand Down

0 comments on commit 01915f3

Please sign in to comment.