Merge branch 'master' of github.com:jedmccaleb/NewCoin into serialize

This commit is contained in:
JoelKatz
2012-09-27 14:15:56 -07:00
13 changed files with 235 additions and 61 deletions

View File

@@ -12,6 +12,7 @@
uint64 STAmount::uRateOne = STAmount::getRate(STAmount(1), STAmount(1));
// --> sCurrency: "", "XNS", or three letter ISO code.
bool STAmount::currencyFromString(uint160& uDstCurrency, const std::string& sCurrency)
{
bool bSuccess = true;

View File

@@ -10,6 +10,8 @@ boost::recursive_mutex Log::sLock;
LogSeverity Log::sMinSeverity = lsINFO;
std::ofstream* Log::outStream = NULL;
boost::filesystem::path *Log::pathToLog = NULL;
uint32 Log::logRotateCounter = 0;
Log::~Log()
{
@@ -31,6 +33,48 @@ Log::~Log()
(*outStream) << logMsg << std::endl;
}
std::string Log::rotateLog(void)
{
boost::recursive_mutex::scoped_lock sl(sLock);
boost::filesystem::path abs_path;
std::string abs_path_str;
uint32 failsafe = 0;
std::string abs_new_path_str;
do {
std::string s;
std::stringstream out;
failsafe++;
if (failsafe == std::numeric_limits<uint32>::max()) {
return "unable to create new log file; too many log files!";
}
abs_path = boost::filesystem::absolute("");
abs_path /= *pathToLog;
abs_path_str = abs_path.parent_path().string();
out << logRotateCounter;
s = out.str();
abs_new_path_str = abs_path_str + "/" + s + + "_" + pathToLog->filename().string();
logRotateCounter++;
} while (boost::filesystem::exists(boost::filesystem::path(abs_new_path_str)));
outStream->close();
boost::filesystem::rename(abs_path, boost::filesystem::path(abs_new_path_str));
setLogFile(*pathToLog);
return abs_new_path_str;
}
void Log::setMinSeverity(LogSeverity s)
{
boost::recursive_mutex::scoped_lock sl(sLock);
@@ -52,4 +96,6 @@ void Log::setLogFile(boost::filesystem::path path)
outStream = newStream;
if (outStream)
Log(lsINFO) << "Starting up";
pathToLog = new boost::filesystem::path(path);
}

View File

@@ -9,6 +9,9 @@
// Ensure that we don't get value.h without writer.h
#include "../json/json.h"
#include "types.h"
#include <limits>
enum LogSeverity
{
lsTRACE = 0,
@@ -33,6 +36,9 @@ protected:
mutable std::ostringstream oss;
LogSeverity mSeverity;
static boost::filesystem::path *pathToLog;
static uint32 logRotateCounter;
public:
Log(LogSeverity s) : mSeverity(s)
{ ; }
@@ -51,6 +57,7 @@ public:
static void setMinSeverity(LogSeverity);
static void setLogFile(boost::filesystem::path);
static std::string rotateLog(void);
};
#endif

View File

@@ -104,9 +104,15 @@ public:
return mMode >= omTRACKING;
}
Ledger::pointer getCurrentLedger() { return mLedgerMaster->getCurrentLedger(); }
Ledger::pointer getLedgerByHash(const uint256& hash) { return mLedgerMaster->getLedgerByHash(hash); }
Ledger::pointer getLedgerBySeq(const uint32 seq) { return mLedgerMaster->getLedgerBySeq(seq); }
uint256 getClosedLedger()
{ return mLedgerMaster->getClosedLedger()->getHash(); }
SLE::pointer getSLE(Ledger::pointer lpLedger, const uint256& uHash) { return lpLedger->getSLE(uHash); }
//
// Transaction operations
//

View File

@@ -73,6 +73,9 @@ public:
bool setAccountID(const std::string& strAccountID);
void setAccountID(const uint160& hash160In);
static NewcoinAddress createAccountID(const std::string& strAccountID)
{ NewcoinAddress na; na.setAccountID(strAccountID); return na; }
static NewcoinAddress createAccountID(const uint160& uiAccountID);
static std::string createHumanAccountID(const uint160& uiAccountID)

View File

@@ -14,6 +14,11 @@
#include "Log.h"
#include "RippleLines.h"
#include "Pathfinder.h"
#include "Conversion.h"
extern uint160 humanTo160(const std::string& buf);
#include <iostream>
#include <boost/bind.hpp>
@@ -1779,6 +1784,16 @@ Json::Value RPCServer::doSend(const Json::Value& params)
STPathSet spsPaths;
uint160 srcCurrencyID;
bool ret_b;
ret_b = false;
STAmount::currencyFromString(srcCurrencyID, sSrcCurrency);
Pathfinder pf(naSrcAccountID, naDstAccountID, srcCurrencyID, saDstAmount);
ret_b = pf.findPaths(5, 1, spsPaths);
// TODO: Nope; the above can't be right
trans = Transaction::sharedPayment(
naAccountPublic, naAccountPrivate,
naSrcAccountID,
@@ -2499,6 +2514,11 @@ Json::Value RPCServer::doLogin(const Json::Value& params)
}
}
Json::Value RPCServer::doLogRotate(const Json::Value& params)
{
return Log::rotateLog();
}
Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params)
{
Log(lsTRACE) << "RPC:" << command;
@@ -2524,6 +2544,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
{ "data_fetch", &RPCServer::doDataFetch, 1, 1, true },
{ "data_store", &RPCServer::doDataStore, 2, 2, true },
{ "ledger", &RPCServer::doLedger, 0, 2, false, optNetwork },
{ "logrotate", &RPCServer::doLogRotate, 0, 0, true, optCurrent },
{ "nickname_info", &RPCServer::doNicknameInfo, 1, 1, false, optCurrent },
{ "nickname_set", &RPCServer::doNicknameSet, 2, 3, false, optCurrent },
{ "offer_create", &RPCServer::doOfferCreate, 9, 10, false, optCurrent },

View File

@@ -141,6 +141,7 @@ private:
Json::Value doDataFetch(const Json::Value& params);
Json::Value doDataStore(const Json::Value& params);
Json::Value doLedger(const Json::Value& params);
Json::Value doLogRotate(const Json::Value& params);
Json::Value doNicknameInfo(const Json::Value& params);
Json::Value doNicknameSet(const Json::Value& params);
Json::Value doOfferCreate(const Json::Value& params);
@@ -184,6 +185,7 @@ private:
Json::Value doLogin(const Json::Value& params);
public:
static pointer create(boost::asio::io_service& io_service, NetworkOPs* mNetOps)
{

View File

@@ -567,11 +567,48 @@ void WSConnection::doLedgerCurrent(Json::Value& jvResult, const Json::Value& jvR
void WSConnection::doLedgerEntry(Json::Value& jvResult, const Json::Value& jvRequest)
{
// Get from request.
uint256 uLedger;
NetworkOPs& noNetwork = theApp->getOPs();
uint256 uLedger = jvRequest.isMember("ledger") ? uint256(jvRequest["ledger"].asString()) : 0;
uint32 uLedgerIndex = jvRequest.isMember("ledger_index") && jvRequest["ledger_index"].isNumeric() ? jvRequest["ledger_index"].asUInt() : 0;
jvResult["ledger_index"] = theApp->getOPs().getLedgerID(uLedger);
jvResult["ledger"] = uLedger.ToString();
Ledger::pointer lpLedger;
if (!!uLedger)
{
// Ledger directly specified.
lpLedger = noNetwork.getLedgerByHash(uLedger);
if (!lpLedger)
{
jvResult["error"] = "ledgerNotFound";
return;
}
uLedgerIndex = lpLedger->getLedgerSeq(); // Set the current index, override if needed.
}
else if (!!uLedgerIndex)
{
lpLedger = noNetwork.getLedgerBySeq(uLedgerIndex);
if (!lpLedger)
{
jvResult["error"] = "ledgerNotFound"; // ledger_index from future?
return;
}
}
else
{
// Default to current ledger.
lpLedger = noNetwork.getCurrentLedger();
uLedgerIndex = lpLedger->getLedgerSeq(); // Set the current index.
}
if (!!uLedger)
jvResult["ledger"] = uLedger.ToString();
jvResult["ledger_index"] = uLedgerIndex;
uint256 uNodeIndex;
if (jvRequest.isMember("index"))
{
@@ -579,7 +616,16 @@ void WSConnection::doLedgerEntry(Json::Value& jvResult, const Json::Value& jvReq
}
else if (jvRequest.isMember("account_root"))
{
jvResult["error"] = "notImplemented";
NewcoinAddress naAccount;
if (!naAccount.setAccountID(jvRequest["account_root"].asString()))
{
jvResult["error"] = "malformedAddress";
}
else
{
uNodeIndex = Ledger::getAccountRootIndex(naAccount.getAccountID());
}
}
else if (jvRequest.isMember("directory"))
{
@@ -595,12 +641,48 @@ void WSConnection::doLedgerEntry(Json::Value& jvResult, const Json::Value& jvReq
}
else if (jvRequest.isMember("ripple_state"))
{
jvResult["error"] = "notImplemented";
NewcoinAddress naA;
NewcoinAddress naB;
uint160 uCurrency;
if (!jvRequest.isMember("accounts")
|| !jvRequest.isMember("currency")
|| !jvRequest["accounts"].isArray()
|| 2 != jvRequest["accounts"].size()) {
jvResult["error"] = "malformedRequest";
}
else if (!naA.setAccountID(jvRequest["accounts"][0u].asString())
|| !naB.setAccountID(jvRequest["accounts"][1u].asString())) {
jvResult["error"] = "malformedAddress";
}
else if (!STAmount::currencyFromString(uCurrency, jvRequest["currency"].asString())) {
jvResult["error"] = "malformedCurrency";
}
else
{
uNodeIndex = Ledger::getRippleStateIndex(naA, naB, uCurrency);
}
}
else
{
jvResult["error"] = "unknownOption";
}
if (!!uNodeIndex)
{
SLE::pointer sleNode = noNetwork.getSLE(lpLedger, uNodeIndex);
if (!sleNode)
{
// Not found.
// XXX We should also provide proof.
jvResult["error"] = "entryNotFound";
}
else
{
jvResult["node"] = sleNode->getJson(0);
}
}
}
void WSConnection::doTransactionSubcribe(Json::Value& jvResult, const Json::Value& jvRequest)

View File

@@ -51,6 +51,7 @@ void printHelp(const po::options_description& desc)
cout << " data_fetch <key>" << endl;
cout << " data_store <key> <value>" << endl;
cout << " ledger [<id>|current|lastclosed] [full]" << endl;
cout << " logrotate " << endl;
cout << " nickname_info <nickname>" << endl;
cout << " nickname_set <seed> <paying_account> <nickname> [<offer_minimum>] [<authorization>]" << endl;
cout << " offer_create <seed> <paying_account> <taker_pays_amount> <taker_pays_currency> <taker_pays_issuer> <takers_gets_amount> <takers_gets_currency> <takers_gets_issuer> <expires> [passive]" << endl;