mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 15:35:50 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
14
CHANGELOG
Normal file
14
CHANGELOG
Normal file
@@ -0,0 +1,14 @@
|
||||
Critical protocol changes
|
||||
-------------------------
|
||||
|
||||
* date
|
||||
* The JSON field "metaData" changing to "meta".
|
||||
* RPC ledger will no longer take "ledger", use "ledger_hash" or "ledger_index".
|
||||
* "closedLedger" events:
|
||||
** "hash" DEPRECATED: use "ledger_hash"
|
||||
** "seqNum" DEPRECATED: use "ledger_index"
|
||||
** "closeTime" DEPRECATED: use "close" or "close_human"
|
||||
* stream "rt_accounts" --> "accounts_proposed"
|
||||
* stream "rt_transactions" --> "transactions_proposed"
|
||||
* subscribe "username" --> "url_username"
|
||||
* subscribe "password" --> "url_password"
|
||||
@@ -828,26 +828,34 @@ Json::Value Ledger::getJson(int options)
|
||||
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
ledger["parentHash"] = mParentHash.GetHex();
|
||||
ledger["seqNum"] = boost::lexical_cast<std::string>(mLedgerSeq);
|
||||
ledger["seqNum"] = boost::lexical_cast<std::string>(mLedgerSeq); // DEPRECATED
|
||||
|
||||
ledger["parent_hash"] = mParentHash.GetHex();
|
||||
ledger["ledger_index"] = boost::lexical_cast<std::string>(mLedgerSeq);
|
||||
|
||||
if (mClosed || bFull)
|
||||
{
|
||||
if (mClosed)
|
||||
ledger["closed"] = true;
|
||||
ledger["hash"] = mHash.GetHex();
|
||||
ledger["transactionHash"] = mTransHash.GetHex();
|
||||
ledger["accountHash"] = mAccountHash.GetHex();
|
||||
ledger["accepted"] = mAccepted;
|
||||
ledger["totalCoins"] = boost::lexical_cast<std::string>(mTotCoins);
|
||||
|
||||
ledger["hash"] = mHash.GetHex(); // DEPRECATED
|
||||
ledger["totalCoins"] = boost::lexical_cast<std::string>(mTotCoins); // DEPRECATED
|
||||
|
||||
ledger["ledger_hash"] = mHash.GetHex();
|
||||
ledger["transaction_hash"] = mTransHash.GetHex();
|
||||
ledger["account_hash"] = mAccountHash.GetHex();
|
||||
ledger["accepted"] = mAccepted;
|
||||
ledger["total_coins"] = boost::lexical_cast<std::string>(mTotCoins);
|
||||
|
||||
if (mCloseTime != 0)
|
||||
{
|
||||
if ((mCloseFlags & sLCF_NoConsensusTime) != 0)
|
||||
ledger["closeTimeEstimate"] = boost::posix_time::to_simple_string(ptFromSeconds(mCloseTime));
|
||||
ledger["close_time_estimate"] = boost::posix_time::to_simple_string(ptFromSeconds(mCloseTime));
|
||||
else
|
||||
{
|
||||
ledger["closeTime"] = boost::posix_time::to_simple_string(ptFromSeconds(mCloseTime));
|
||||
ledger["closeTimeResolution"] = mCloseResolution;
|
||||
ledger["close_time"] = mCloseTime;
|
||||
ledger["close_time_human"] = boost::posix_time::to_simple_string(ptFromSeconds(mCloseTime));
|
||||
ledger["close_time_resolution"] = mCloseResolution;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1299,6 +1307,9 @@ std::vector< std::pair<uint32, uint256> > Ledger::getLedgerHashes()
|
||||
return ret;
|
||||
}
|
||||
|
||||
// XRP to XRP not allowed.
|
||||
// Currencies must have appropriate issuer.
|
||||
// Currencies or accounts must differ.
|
||||
bool Ledger::isValidBook(const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuerID,
|
||||
const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuerID)
|
||||
{
|
||||
@@ -1338,9 +1349,6 @@ bool Ledger::isValidBook(const uint160& uTakerPaysCurrency, const uint160& uTake
|
||||
uint256 Ledger::getBookBase(const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuerID,
|
||||
const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuerID)
|
||||
{
|
||||
bool bInNative = uTakerPaysCurrency.isZero();
|
||||
bool bOutNative = uTakerGetsCurrency.isZero();
|
||||
|
||||
Serializer s(82);
|
||||
|
||||
s.add16(spaceBookDir); // 2
|
||||
@@ -1358,10 +1366,7 @@ uint256 Ledger::getBookBase(const uint160& uTakerPaysCurrency, const uint160& uT
|
||||
% RippleAddress::createHumanAccountID(uTakerGetsIssuerID)
|
||||
% uBaseIndex.ToString());
|
||||
|
||||
assert(!bInNative || !bOutNative); // XRP to XRP not allowed.
|
||||
assert(bInNative == uTakerPaysIssuerID.isZero()); // Make sure issuer is specified as needed.
|
||||
assert(bOutNative == uTakerGetsIssuerID.isZero()); // Make sure issuer is specified as needed.
|
||||
assert(uTakerPaysCurrency != uTakerGetsCurrency || uTakerPaysIssuerID != uTakerGetsIssuerID); // Currencies or accounts must differ.
|
||||
assert(isValidBook(uTakerPaysCurrency, uTakerPaysIssuerID, uTakerGetsCurrency, uTakerGetsIssuerID));
|
||||
|
||||
return uBaseIndex;
|
||||
}
|
||||
|
||||
@@ -2617,14 +2617,6 @@ boost::unordered_set<RippleAddress> RPCHandler::parseAccountIds(const Json::Valu
|
||||
return usnaResult;
|
||||
}
|
||||
|
||||
/*
|
||||
server : Sends a message anytime the server status changes such as network connectivity.
|
||||
ledger : Sends a message at every ledger close.
|
||||
transactions : Sends a message for every transaction that makes it into a ledger.
|
||||
rt_transactions
|
||||
accounts
|
||||
rt_accounts
|
||||
*/
|
||||
Json::Value RPCHandler::doSubscribe(Json::Value jvRequest, int& cost)
|
||||
{
|
||||
InfoSub::pointer ispSub;
|
||||
@@ -2647,8 +2639,16 @@ Json::Value RPCHandler::doSubscribe(Json::Value jvRequest, int& cost)
|
||||
return rpcError(rpcNO_PERMISSION);
|
||||
|
||||
std::string strUrl = jvRequest["url"].asString();
|
||||
std::string strUsername = jvRequest.isMember("username") ? jvRequest["username"].asString() : "";
|
||||
std::string strPassword = jvRequest.isMember("password") ? jvRequest["password"].asString() : "";
|
||||
std::string strUsername = jvRequest.isMember("url_username") ? jvRequest["url_username"].asString() : "";
|
||||
std::string strPassword = jvRequest.isMember("url_password") ? jvRequest["url_password"].asString() : "";
|
||||
|
||||
// DEPRECATED
|
||||
if (jvRequest.isMember("username"))
|
||||
strUsername = jvRequest["username"].asString();
|
||||
|
||||
// DEPRECATED
|
||||
if (jvRequest.isMember("password"))
|
||||
strPassword = jvRequest["password"].asString();
|
||||
|
||||
ispSub = mNetOps->findRpcSub(strUrl);
|
||||
if (!ispSub)
|
||||
@@ -2704,7 +2704,8 @@ Json::Value RPCHandler::doSubscribe(Json::Value jvRequest, int& cost)
|
||||
{
|
||||
mNetOps->subTransactions(ispSub);
|
||||
}
|
||||
else if (streamName=="rt_transactions")
|
||||
else if (streamName=="transactions_proposed"
|
||||
|| streamName=="rt_transactions") // DEPRECATED
|
||||
{
|
||||
mNetOps->subRTTransactions(ispSub);
|
||||
}
|
||||
@@ -2720,7 +2721,8 @@ Json::Value RPCHandler::doSubscribe(Json::Value jvRequest, int& cost)
|
||||
}
|
||||
}
|
||||
|
||||
if (jvRequest.isMember("rt_accounts"))
|
||||
if (jvRequest.isMember("accounts_proposed")
|
||||
|| jvRequest.isMember("rt_accounts")) // DEPRECATED
|
||||
{
|
||||
boost::unordered_set<RippleAddress> usnaAccoundIds = parseAccountIds(jvRequest["rt_accounts"]);
|
||||
|
||||
@@ -2751,12 +2753,25 @@ Json::Value RPCHandler::doSubscribe(Json::Value jvRequest, int& cost)
|
||||
}
|
||||
|
||||
if (jvRequest.isMember("books"))
|
||||
{ // FIXME: This can crash the server if the parameters to things like getBookPage are invalid
|
||||
{
|
||||
for (Json::Value::iterator it = jvRequest["books"].begin(); it != jvRequest["books"].end(); it++)
|
||||
{
|
||||
uint160 uTakerPaysCurrencyID;
|
||||
uint160 uTakerPaysIssuerID;
|
||||
Json::Value jvTakerPays = (*it)["taker_pays"];
|
||||
Json::Value& jvSubRequest = *it;
|
||||
uint160 uTakerPaysCurrencyID;
|
||||
uint160 uTakerPaysIssuerID;
|
||||
uint160 uTakerGetsCurrencyID;
|
||||
uint160 uTakerGetsIssuerID;
|
||||
bool bBoth = (jvSubRequest.isMember("both") && jvSubRequest["both"].asBool())
|
||||
|| (jvSubRequest.isMember("both_sides") && jvSubRequest["both_sides"].asBool()); // DEPRECATED
|
||||
bool bSnapshot = (jvSubRequest.isMember("snapshot") && jvSubRequest["snapshot"].asBool())
|
||||
|| (jvSubRequest.isMember("start_now") && jvSubRequest["start_now"].asBool()); // DEPRECATED
|
||||
|
||||
|
||||
if (!jvSubRequest.isMember("taker_pays") || !jvSubRequest.isMember("taker_gets"))
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
|
||||
Json::Value jvTakerPays = jvSubRequest["taker_pays"];
|
||||
Json::Value jvTakerGets = jvSubRequest["taker_gets"];
|
||||
|
||||
// Parse mandatory currency.
|
||||
if (!jvTakerPays.isMember("currency")
|
||||
@@ -2779,10 +2794,6 @@ Json::Value RPCHandler::doSubscribe(Json::Value jvRequest, int& cost)
|
||||
return rpcError(rpcSRC_ISR_MALFORMED);
|
||||
}
|
||||
|
||||
uint160 uTakerGetsCurrencyID;
|
||||
uint160 uTakerGetsIssuerID;
|
||||
Json::Value jvTakerGets = (*it)["taker_gets"];
|
||||
|
||||
// Parse mandatory currency.
|
||||
if (!jvTakerGets.isMember("currency")
|
||||
|| !STAmount::currencyFromString(uTakerGetsCurrencyID, jvTakerGets["currency"].asString()))
|
||||
@@ -2814,38 +2825,45 @@ Json::Value RPCHandler::doSubscribe(Json::Value jvRequest, int& cost)
|
||||
|
||||
RippleAddress raTakerID;
|
||||
|
||||
if (!(*it).isMember("taker"))
|
||||
if (!jvSubRequest.isMember("taker"))
|
||||
{
|
||||
raTakerID.setAccountID(ACCOUNT_ONE);
|
||||
}
|
||||
else if (!raTakerID.setAccountID((*it)["taker"].asString()))
|
||||
else if (!raTakerID.setAccountID(jvSubRequest["taker"].asString()))
|
||||
{
|
||||
return rpcError(rpcBAD_ISSUER);
|
||||
}
|
||||
|
||||
bool bothSides = (*it)["both_sides"].asBool();
|
||||
|
||||
if (!Ledger::isValidBook(uTakerPaysCurrencyID, uTakerPaysIssuerID, uTakerGetsCurrencyID, uTakerGetsIssuerID))
|
||||
{
|
||||
cLog(lsWARNING) << "Bad market: " <<
|
||||
uTakerPaysCurrencyID << ":" << uTakerPaysIssuerID << " -> " <<
|
||||
uTakerPaysCurrencyID << ":" << uTakerPaysIssuerID << " -> " <<
|
||||
uTakerGetsCurrencyID << ":" << uTakerGetsIssuerID;
|
||||
return rpcError(rpcBAD_MARKET);
|
||||
}
|
||||
|
||||
mNetOps->subBook(ispSub, uTakerPaysCurrencyID, uTakerGetsCurrencyID, uTakerPaysIssuerID, uTakerGetsIssuerID);
|
||||
if (bothSides) mNetOps->subBook(ispSub, uTakerGetsCurrencyID, uTakerPaysCurrencyID, uTakerGetsIssuerID, uTakerPaysIssuerID);
|
||||
if ((*it)["state_now"].asBool())
|
||||
if (bBoth) mNetOps->subBook(ispSub, uTakerGetsCurrencyID, uTakerPaysCurrencyID, uTakerGetsIssuerID, uTakerPaysIssuerID);
|
||||
|
||||
if (bSnapshot)
|
||||
{
|
||||
Ledger::pointer ledger= theApp->getLedgerMaster().getClosedLedger();
|
||||
Ledger::pointer lpLedger= theApp->getLedgerMaster().getClosedLedger();
|
||||
const Json::Value jvMarker = Json::Value(Json::nullValue);
|
||||
mNetOps->getBookPage(ledger, uTakerPaysCurrencyID, uTakerPaysIssuerID, uTakerGetsCurrencyID, uTakerGetsIssuerID, raTakerID.getAccountID(), false, 0, jvMarker, jvResult);
|
||||
if (bothSides)
|
||||
|
||||
if (bBoth)
|
||||
{
|
||||
Json::Value tempJson(Json::objectValue);
|
||||
if (jvResult.isMember("offers")) jvResult["bids"]=jvResult["offers"];
|
||||
mNetOps->getBookPage(ledger, uTakerGetsCurrencyID, uTakerGetsIssuerID, uTakerPaysCurrencyID, uTakerPaysIssuerID, raTakerID.getAccountID(), false, 0, jvMarker, tempJson);
|
||||
if (tempJson.isMember("offers")) jvResult["asks"]=tempJson["offers"];
|
||||
Json::Value jvBids(Json::objectValue);
|
||||
Json::Value jvAsks(Json::objectValue);
|
||||
|
||||
mNetOps->getBookPage(lpLedger, uTakerPaysCurrencyID, uTakerPaysIssuerID, uTakerGetsCurrencyID, uTakerGetsIssuerID, raTakerID.getAccountID(), false, 0, jvMarker, jvBids);
|
||||
if (jvBids.isMember("offers")) jvResult["bids"]=jvBids["offers"];
|
||||
|
||||
mNetOps->getBookPage(lpLedger, uTakerGetsCurrencyID, uTakerGetsIssuerID, uTakerPaysCurrencyID, uTakerPaysIssuerID, raTakerID.getAccountID(), false, 0, jvMarker, jvAsks);
|
||||
if (jvAsks.isMember("offers")) jvResult["asks"]=jvAsks["offers"];
|
||||
}
|
||||
else
|
||||
{
|
||||
mNetOps->getBookPage(lpLedger, uTakerPaysCurrencyID, uTakerPaysIssuerID, uTakerGetsCurrencyID, uTakerGetsIssuerID, raTakerID.getAccountID(), false, 0, jvMarker, jvResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user