diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index b02bef0c1..34f3304e9 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -117,6 +117,8 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, TER r = mLedgerMaster->doTransaction(*trans->getSTransaction(), tapOPEN_LEDGER); + trans->setResult(r); + #ifdef DEBUG if (r != tesSUCCESS) { @@ -136,7 +138,7 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, mLedgerMaster->addHeldTransaction(trans); return trans; } - if ((r == tefPAST_SEQ)) + if (r == tefPAST_SEQ) { // duplicate or conflict cLog(lsINFO) << "Transaction is obsolete"; trans->setStatus(OBSOLETE); @@ -894,12 +896,12 @@ Json::Value NetworkOPs::pubBootstrapAccountInfo(Ledger::ref lpAccepted, const Ne { Json::Value jvObj(Json::objectValue); - jvObj["type"] = "accountInfoBootstrap"; - jvObj["account"] = naAccountID.humanAccountID(); - jvObj["owner"] = getOwnerInfo(lpAccepted, naAccountID); - jvObj["seq"] = lpAccepted->getLedgerSeq(); - jvObj["hash"] = lpAccepted->getHash().ToString(); - jvObj["time"] = Json::Value::UInt(lpAccepted->getCloseTimeNC()); + jvObj["type"] = "accountInfoBootstrap"; + jvObj["account"] = naAccountID.humanAccountID(); + jvObj["owner"] = getOwnerInfo(lpAccepted, naAccountID); + jvObj["ledger_closed_index"] = lpAccepted->getLedgerSeq(); + jvObj["ledger_closed"] = lpAccepted->getHash().ToString(); + jvObj["time"] = Json::Value::UInt(lpAccepted->getCloseTimeNC()); return jvObj; } @@ -934,7 +936,7 @@ void NetworkOPs::pubLedger(Ledger::ref lpAccepted) { Json::Value jvObj(Json::objectValue); - jvObj["type"] = "ledgerAccepted"; + jvObj["type"] = "ledgerClosed"; jvObj["ledger_closed_index"] = lpAccepted->getLedgerSeq(); jvObj["ledger_closed"] = lpAccepted->getHash().ToString(); jvObj["time"] = Json::Value::UInt(lpAccepted->getCloseTimeNC()); @@ -959,11 +961,11 @@ void NetworkOPs::pubLedger(Ledger::ref lpAccepted) Json::Value jvObj(Json::objectValue); - jvObj["type"] = "ledgerAcceptedAccounts"; - jvObj["seq"] = lpAccepted->getLedgerSeq(); - jvObj["hash"] = lpAccepted->getHash().ToString(); - jvObj["time"] = Json::Value::UInt(lpAccepted->getCloseTimeNC()); - jvObj["accounts"] = jvAccounts; + jvObj["type"] = "ledgerClosedAccounts"; + jvObj["ledger_closed_index"] = lpAccepted->getLedgerSeq(); + jvObj["ledger_closed"] = lpAccepted->getHash().ToString(); + jvObj["time"] = Json::Value::UInt(lpAccepted->getCloseTimeNC()); + jvObj["accounts"] = jvAccounts; BOOST_FOREACH(InfoSub* ispListener, mSubLedgerAccounts) { @@ -990,12 +992,12 @@ void NetworkOPs::pubLedger(Ledger::ref lpAccepted) if (bAll) { - pubTransactionAll(lpAccepted, *stTxn, terResult, "accepted"); + pubTransactionAll(lpAccepted, *stTxn, terResult, "closed"); } if (bAccounts) { - pubTransactionAccounts(lpAccepted, *stTxn, terResult, "accepted"); + pubTransactionAccounts(lpAccepted, *stTxn, terResult, "closed"); } } } @@ -1020,27 +1022,35 @@ void NetworkOPs::pubLedger(Ledger::ref lpAccepted) // XXX Publish delta information for accounts. } -Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TER terResult, const std::string& strStatus, int iSeq, const std::string& strType) +Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TER terResult, bool bAccepted, Ledger::ref lpCurrent, const std::string& strType) { Json::Value jvObj(Json::objectValue); - std::string strToken; - std::string strHuman; + std::string sToken; + std::string sHuman; - transResultInfo(terResult, strToken, strHuman); + transResultInfo(terResult, sToken, sHuman); jvObj["type"] = strType; jvObj["transaction"] = stTxn.getJson(0); - jvObj["transaction"]["inLedger"] = iSeq; - jvObj["transaction"]["status"] = strStatus; - jvObj["result"] = strToken; - jvObj["result_code"] = terResult; + if (bAccepted) { + jvObj["ledger_closed_index"] = lpCurrent->getLedgerSeq(); + jvObj["ledger_closed"] = lpCurrent->getHash().ToString(); + } + else + { + jvObj["ledger_current_index"] = lpCurrent->getLedgerSeq(); + } + jvObj["status"] = bAccepted ? "closed" : "proposed"; + jvObj["engine_result"] = sToken; + jvObj["engine_result_code"] = terResult; + jvObj["engine_result_message"] = sHuman; return jvObj; } -void NetworkOPs::pubTransactionAll(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, const char* pState) +void NetworkOPs::pubTransactionAll(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, bool bAccepted) { - Json::Value jvObj = transJson(stTxn, terResult, pState, lpCurrent->getLedgerSeq(), "transaction"); + Json::Value jvObj = transJson(stTxn, terResult, bAccepted, lpCurrent, "transaction"); BOOST_FOREACH(InfoSub* ispListener, mSubTransaction) { @@ -1048,7 +1058,7 @@ void NetworkOPs::pubTransactionAll(Ledger::ref lpCurrent, const SerializedTransa } } -void NetworkOPs::pubTransactionAccounts(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, const char* pState) +void NetworkOPs::pubTransactionAccounts(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, bool bAccepted) { boost::unordered_set usisNotify; @@ -1074,7 +1084,7 @@ void NetworkOPs::pubTransactionAccounts(Ledger::ref lpCurrent, const SerializedT if (!usisNotify.empty()) { - Json::Value jvObj = transJson(stTxn, terResult, pState, lpCurrent->getLedgerSeq(), "account"); + Json::Value jvObj = transJson(stTxn, terResult, bAccepted, lpCurrent, "account"); BOOST_FOREACH(InfoSub* ispListener, usisNotify) { diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index ea4180d8d..931364054 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -82,9 +82,9 @@ protected: void setMode(OperatingMode); - Json::Value transJson(const SerializedTransaction& stTxn, TER terResult, const std::string& strStatus, int iSeq, const std::string& strType); - void pubTransactionAll(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, const char* pState); - void pubTransactionAccounts(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, const char* pState); + Json::Value transJson(const SerializedTransaction& stTxn, TER terResult, bool bAccepted, Ledger::ref lpCurrent, const std::string& strType); + void pubTransactionAll(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, bool bAccepted); + void pubTransactionAccounts(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, bool bAccepted); bool haveConsensusObject(); Json::Value pubBootstrapAccountInfo(Ledger::ref lpAccepted, const NewcoinAddress& naAccountID); diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp index 0c5ebdd41..dbe3ffbf2 100644 --- a/src/SerializedTransaction.cpp +++ b/src/SerializedTransaction.cpp @@ -162,7 +162,9 @@ void SerializedTransaction::setSourceAccount(const NewcoinAddress& naSource) Json::Value SerializedTransaction::getJson(int options) const { Json::Value ret = STObject::getJson(0); - ret["id"] = getTransactionID().GetHex(); + + ret["hash"] = getTransactionID().GetHex(); + return ret; } diff --git a/src/Transaction.cpp b/src/Transaction.cpp index e56e12f0f..9a368c1c6 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -14,7 +14,7 @@ #include "Log.h" Transaction::Transaction(const SerializedTransaction::pointer& sit, bool bValidate) - : mInLedger(0), mStatus(INVALID), mTransaction(sit) + : mInLedger(0), mStatus(INVALID), mResult(temUNCERTAIN), mTransaction(sit) { try { @@ -60,7 +60,7 @@ Transaction::Transaction( uint32 uSeq, const STAmount& saFee, uint32 uSourceTag) : - mStatus(NEW) + mStatus(NEW), mResult(temUNCERTAIN) { mAccountFrom = naSourceAccount; mFromPubKey = naPublicKey; @@ -710,18 +710,18 @@ Json::Value Transaction::getJson(int options) const if (mInLedger) ret["inLedger"]=mInLedger; - switch(mStatus) + switch (mStatus) { - case NEW: ret["status"] = "new"; break; - case INVALID: ret["status"] = "invalid"; break; - case INCLUDED: ret["status"] = "included"; break; - case CONFLICTED: ret["status"] = "conflicted"; break; - case COMMITTED: ret["status"] = "committed"; break; - case HELD: ret["status"] = "held"; break; - case REMOVED: ret["status"] = "removed"; break; - case OBSOLETE: ret["status"] = "obsolete"; break; - case INCOMPLETE: ret["status"] = "incomplete"; break; - default: ret["status"] = "unknown"; + case NEW: ret["status"] = "new"; break; + case INVALID: ret["status"] = "invalid"; break; + case INCLUDED: ret["status"] = "included"; break; + case CONFLICTED: ret["status"] = "conflicted"; break; + case COMMITTED: ret["status"] = "committed"; break; + case HELD: ret["status"] = "held"; break; + case REMOVED: ret["status"] = "removed"; break; + case OBSOLETE: ret["status"] = "obsolete"; break; + case INCOMPLETE: ret["status"] = "incomplete"; break; + default: ret["status"] = "unknown"; break; } return ret; diff --git a/src/Transaction.h b/src/Transaction.h index 0837f83c7..7cd94aedd 100644 --- a/src/Transaction.h +++ b/src/Transaction.h @@ -15,6 +15,7 @@ #include "Serializer.h" #include "SHAMap.h" #include "SerializedTransaction.h" +#include "TransactionErr.h" enum TransStatus { @@ -43,6 +44,7 @@ private: uint32 mInLedger; TransStatus mStatus; + TER mResult; SerializedTransaction::pointer mTransaction; @@ -280,6 +282,9 @@ public: uint32 getLedger() const { return mInLedger; } TransStatus getStatus() const { return mStatus; } + TER getResult() { return mResult; } + void setResult(TER terResult) { mResult = terResult; } + void setStatus(TransStatus status, uint32 ledgerSeq); void setStatus(TransStatus status) { mStatus=status; } void setLedger(uint32 ledger) { mInLedger = ledger; } diff --git a/src/WSDoor.cpp b/src/WSDoor.cpp index 7aaa64009..d0c23e2c7 100644 --- a/src/WSDoor.cpp +++ b/src/WSDoor.cpp @@ -959,7 +959,19 @@ void WSConnection::doSubmit(Json::Value& jvResult, const Json::Value& jvRequest) try { - jvResult["submitted"] = tpTrans->getJson(0); + jvResult["transaction"] = tpTrans->getJson(0); + + if (temUNCERTAIN != tpTrans->getResult()) + { + std::string sToken; + std::string sHuman; + + transResultInfo(tpTrans->getResult(), sToken, sHuman); + + jvResult["engine_result"] = sToken; + jvResult["engine_result_code"] = tpTrans->getResult(); + jvResult["engine_result_message"] = sHuman; + } } catch (std::exception& e) {