mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge branch 'master' into misc
Conflicts: src/TransactionEngine.cpp
This commit is contained in:
@@ -317,7 +317,7 @@ Ledger::pointer Ledger::loadByHash(const uint256& ledgerHash)
|
||||
return getSQL(sql);
|
||||
}
|
||||
|
||||
void Ledger::addJson(Json::Value& ret)
|
||||
void Ledger::addJson(Json::Value& ret, int options)
|
||||
{
|
||||
Json::Value ledger(Json::objectValue);
|
||||
|
||||
@@ -336,6 +336,22 @@ void Ledger::addJson(Json::Value& ret)
|
||||
else ledger["Closed"] = false;
|
||||
if (mCloseTime != 0)
|
||||
ledger["CloseTime"] = boost::posix_time::to_simple_string(ptFromSeconds(mCloseTime));
|
||||
if ((options & LEDGER_JSON_DUMP_TXNS) != 0)
|
||||
{
|
||||
Json::Value txns(Json::arrayValue);
|
||||
for (SHAMapItem::pointer item = mTransactionMap->peekFirstItem(); !!item;
|
||||
item = mTransactionMap->peekNextItem(item->getTag()))
|
||||
txns.append(item->getTag().GetHex());
|
||||
ledger["Transactions"] = txns;
|
||||
}
|
||||
if ((options & LEDGER_JSON_DUMP_STATE) != 0)
|
||||
{
|
||||
Json::Value state(Json::arrayValue);
|
||||
for (SHAMapItem::pointer item = mAccountStateMap->peekFirstItem(); !!item;
|
||||
item = mAccountStateMap->peekNextItem(item->getTag()))
|
||||
state.append(item->getTag().GetHex());
|
||||
ledger["AccountState"] = state;
|
||||
}
|
||||
ret[boost::lexical_cast<std::string>(mLedgerSeq)] = ledger;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ enum LedgerStateParms
|
||||
lepERROR = 32, // error
|
||||
};
|
||||
|
||||
#define LEDGER_JSON_DUMP_TXNS 0x10000000
|
||||
#define LEDGER_JSON_DUMP_STATE 0x20000000
|
||||
|
||||
class Ledger : public boost::enable_shared_from_this<Ledger>
|
||||
{ // The basic Ledger structure, can be opened, closed, or synching
|
||||
friend class TransactionEngine;
|
||||
@@ -222,7 +225,7 @@ public:
|
||||
bool isCompatible(boost::shared_ptr<Ledger> other);
|
||||
// bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko);
|
||||
|
||||
void addJson(Json::Value&);
|
||||
void addJson(Json::Value&, int options);
|
||||
|
||||
static bool unitTest();
|
||||
};
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "../json/writer.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "NetworkOPs.h"
|
||||
#include "LedgerTiming.h"
|
||||
@@ -661,6 +663,17 @@ void LedgerConsensus::accept(SHAMap::pointer set)
|
||||
|
||||
Ledger::pointer newLCL = boost::make_shared<Ledger>(false, boost::ref(*mPreviousLedger));
|
||||
|
||||
#ifdef DEBUG
|
||||
Json::StyledStreamWriter ssw;
|
||||
if (1)
|
||||
{
|
||||
Log(lsTRACE) << "newLCL before transactions";
|
||||
Json::Value p;
|
||||
newLCL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE);
|
||||
ssw.write(std::cerr, p);
|
||||
}
|
||||
#endif
|
||||
|
||||
std::deque<SerializedTransaction::pointer> failedTransactions;
|
||||
applyTransactions(set, newLCL, failedTransactions);
|
||||
newLCL->setClosed();
|
||||
@@ -668,8 +681,27 @@ void LedgerConsensus::accept(SHAMap::pointer set)
|
||||
newLCL->updateHash();
|
||||
uint256 newLCLHash = newLCL->getHash();
|
||||
|
||||
#ifdef DEBUG
|
||||
if (1)
|
||||
{
|
||||
Log(lsTRACE) << "newLCL after transactions";
|
||||
Json::Value p;
|
||||
newLCL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE);
|
||||
ssw.write(std::cerr, p);
|
||||
}
|
||||
#endif
|
||||
|
||||
Ledger::pointer newOL = boost::make_shared<Ledger>(true, boost::ref(*newLCL));
|
||||
|
||||
#ifdef DEBUG
|
||||
if (1)
|
||||
{
|
||||
Log(lsTRACE) << "newOL before transactions";
|
||||
Json::Value p;
|
||||
newOL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE);
|
||||
ssw.write(std::cerr, p);
|
||||
}
|
||||
#endif
|
||||
ScopedLock sl = theApp->getMasterLedger().getLock();
|
||||
|
||||
applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(),
|
||||
@@ -677,6 +709,16 @@ void LedgerConsensus::accept(SHAMap::pointer set)
|
||||
theApp->getMasterLedger().pushLedger(newLCL, newOL);
|
||||
mState = lcsACCEPTED;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (1)
|
||||
{
|
||||
Log(lsTRACE) << "newOL after transactions";
|
||||
Json::Value p;
|
||||
newOL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE);
|
||||
ssw.write(std::cerr, p);
|
||||
}
|
||||
#endif
|
||||
|
||||
sl.unlock();
|
||||
|
||||
SerializedValidation v(newLCLHash, mOurPosition->peekKey(), true);
|
||||
|
||||
@@ -1279,8 +1279,8 @@ Json::Value RPCServer::doLedger(Json::Value& params)
|
||||
if (getParamCount(params)== 0)
|
||||
{
|
||||
Json::Value ret(Json::objectValue), current(Json::objectValue), closed(Json::objectValue);
|
||||
theApp->getMasterLedger().getCurrentLedger()->addJson(current);
|
||||
theApp->getMasterLedger().getClosedLedger()->addJson(closed);
|
||||
theApp->getMasterLedger().getCurrentLedger()->addJson(current, 0);
|
||||
theApp->getMasterLedger().getClosedLedger()->addJson(closed, 0);
|
||||
ret["open"] = current;
|
||||
ret["closed"] = closed;
|
||||
return ret;
|
||||
|
||||
@@ -274,6 +274,7 @@ public:
|
||||
bool isNegative() const { return mIsNegative && !isZero(); }
|
||||
bool isPositive() const { return !mIsNegative && !isZero(); }
|
||||
bool isGEZero() const { return !mIsNegative; }
|
||||
operator bool() const { return !isZero(); }
|
||||
|
||||
void changeSign() { if (!isZero()) mIsNegative = !mIsNegative; }
|
||||
void zero() { mOffset = mIsNative ? -100 : 0; mValue = 0; mIsNegative = false; }
|
||||
|
||||
@@ -394,7 +394,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
|
||||
if (terSUCCESS == result && (params & tepNO_CHECK_FEE) == tepNONE)
|
||||
{
|
||||
if (saCost)
|
||||
if (!saCost.isZero())
|
||||
{
|
||||
if (saPaid < saCost)
|
||||
{
|
||||
@@ -471,9 +471,9 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
default:
|
||||
if (!sleSrc->getIFieldPresent(sfAuthorizedKey))
|
||||
{
|
||||
std::cerr << "applyTransaction: Souce is an unclaimed account." << std::endl;
|
||||
std::cerr << "applyTransaction: Source is an unclaimed account." << std::endl;
|
||||
|
||||
result = tenUNCLAIMED;
|
||||
result = terUNCLAIMED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -514,9 +514,9 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
// Verify the transaction's signing public key is the key authorized for signing.
|
||||
if (naSigningPubKey.getAccountID() != sleSrc->getIValueFieldAccount(sfAuthorizedKey).getAccountID())
|
||||
{
|
||||
std::cerr << "applyTransaction: Not authorized to use account." << std::endl;
|
||||
std::cerr << "applyTransaction: Delay: Not authorized to use account." << std::endl;
|
||||
|
||||
result = tenBAD_AUTH;
|
||||
result = terBAD_AUTH;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -532,8 +532,8 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
{
|
||||
std::cerr
|
||||
<< str(boost::format("applyTransaction: Delay transaction: insufficent balance: balance=%s paid=%s")
|
||||
% saSrcBalance
|
||||
% saPaid)
|
||||
% saSrcBalance.getText()
|
||||
% saPaid.getText())
|
||||
<< std::endl;
|
||||
|
||||
result = terINSUF_FEE_B;
|
||||
@@ -548,13 +548,12 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
{
|
||||
nothing();
|
||||
}
|
||||
else if (saCost.isZero())
|
||||
else if (!saCost.isZero())
|
||||
{
|
||||
uint32 a_seq = sleSrc->getIFieldU32(sfSequence);
|
||||
|
||||
Log(lsINFO) << "Aseq=" << a_seq << ", Tseq=" << t_seq;
|
||||
if (t_seq != a_seq)
|
||||
{
|
||||
// WRITEME: Special case code for changing transaction key
|
||||
if (a_seq < t_seq)
|
||||
{
|
||||
std::cerr << "applyTransaction: future sequence number" << std::endl;
|
||||
@@ -576,11 +575,12 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
}
|
||||
else
|
||||
{
|
||||
sleSrc->setIFieldU32(sfSequence, t_seq);
|
||||
sleSrc->setIFieldU32(sfSequence, t_seq + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(lsINFO) << "Zero cost transaction";
|
||||
if (t_seq)
|
||||
{
|
||||
std::cerr << "applyTransaction: bad sequence for pre-paid transaction" << std::endl;
|
||||
@@ -654,7 +654,6 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
|
||||
if (terSUCCESS == result)
|
||||
{ // Write back the account states and add the transaction to the ledger
|
||||
// WRITEME: Special case code for changing transaction key
|
||||
for (std::vector<AffectedAccount>::iterator it = accounts.begin(), end = accounts.end();
|
||||
it != end; ++it)
|
||||
{
|
||||
@@ -1231,8 +1230,8 @@ TransactionEngineResult TransactionEngine::doWalletAdd(const SerializedTransacti
|
||||
{
|
||||
std::cerr
|
||||
<< str(boost::format("WalletAdd: Delay transaction: insufficent balance: balance=%s amount=%s")
|
||||
% saSrcBalance
|
||||
% saAmount)
|
||||
% saSrcBalance.getText()
|
||||
% saAmount.getText())
|
||||
<< std::endl;
|
||||
|
||||
return terUNFUNDED;
|
||||
|
||||
@@ -24,9 +24,7 @@ enum TransactionEngineResult
|
||||
tenBAD_SET_ID, // Malformed.
|
||||
|
||||
// Invalid: Ledger won't allow.
|
||||
tenUNCLAIMED = -200, // Can not use an unclaimed account.
|
||||
tenCLAIMED, // Can not claim a previously claimed account.
|
||||
tenBAD_AUTH, // Transaction's public key is not authorized.
|
||||
tenCLAIMED = -200, // Can not claim a previously claimed account.
|
||||
tenCREATED, // Can't add an already created account.
|
||||
tenMSG_SET, // Can't change a message key.
|
||||
|
||||
@@ -60,6 +58,8 @@ enum TransactionEngineResult
|
||||
terNO_LINE_NO_ZERO, // Can't zero non-existant line, destination might make it.
|
||||
terSET_MISSING_DST, // Can't set password, destination missing.
|
||||
terFUNDS_SPENT, // Can't set password, password set funds already spent.
|
||||
terUNCLAIMED, // Can not use an unclaimed account.
|
||||
terBAD_AUTH, // Transaction's public key is not authorized.
|
||||
};
|
||||
|
||||
enum TransactionEngineParams
|
||||
|
||||
Reference in New Issue
Block a user