diff --git a/src/DBInit.cpp b/src/DBInit.cpp index 0c4826e943..a2b5be277b 100644 --- a/src/DBInit.cpp +++ b/src/DBInit.cpp @@ -7,10 +7,7 @@ const char *TxnDBInit[] = { TransType CHARACTER(24) \ FromAcct CHARACTER(35), \ FromSeq BIGINT UNSIGNED, \ - OtherAcct CHARACTER(40), \ - Amount BIGINT UNSIGNED, \ - FirstSeen TEXT, \ - CommitSeq BIGINT UNSIGNED, \ + LedgerSeq BIGINT UNSIGNED, \ Status CHARACTER(1), \ RawTxn BLOB \ );", diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp index d5b7aac3e1..a5fce40f25 100644 --- a/src/SerializedTransaction.cpp +++ b/src/SerializedTransaction.cpp @@ -1,5 +1,6 @@ #include "SerializedTransaction.h" +#include "Application.h" #include "Log.h" @@ -297,4 +298,33 @@ Json::Value SerializedTransaction::getJson(int options) const ret["Inner"] = mInnerTxn.getJson(options); return ret; } + +std::string SerializedTransaction::getSQLValueHeader() +{ + return "(TransID, TransType, FromAcct, FromSeq, CommitSeq, Status, RawTxn)"; +} + +std::string SerializedTransaction::getSQLInsertHeader() +{ + return "INSERT INTO Transactions " + getSQLValueHeader() + " VALUES "; +} + +std::string SerializedTransaction::getSQL(uint32 inLedger, char status) const +{ + Serializer s; + add(s); + return getSQL(s, inLedger, status); +} + +std::string SerializedTransaction::getSQL(Serializer rawTxn, uint32 inLedger, char status) const +{ + std::string rTxn; + theApp->getTxnDB()->getDB()->escape( + reinterpret_cast(rawTxn.getDataPtr()), rawTxn.getLength(), rTxn); + return str(boost::format("('%s', '%s', '%s', %d, %d, %c, '%s')") + % getTransactionID().GetHex() % getTransactionType() % getSourceAccount().humanAccountID() + % getSequence() % inLedger % status % rTxn); +} + + // vim:ts=4 diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h index 024bbfa548..07b1dca83b 100644 --- a/src/SerializedTransaction.h +++ b/src/SerializedTransaction.h @@ -116,6 +116,14 @@ public: bool sign(const NewcoinAddress& naAccountPrivate); bool checkSign(const NewcoinAddress& naAccountPublic) const; + + // SQL Functions + static std::string getSQLValueHeader(); + static std::string getSQLInsertHeader(); + std::string getSQL(std::string& sql, uint32 inLedger, char status) const; + std::string getSQL(uint32 inLedger, char status) const; + std::string getSQL(Serializer rawTxn, uint32 inLedger, char status) const; + }; #endif diff --git a/src/Transaction.cpp b/src/Transaction.cpp index 328a7aa6fc..a724516a16 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -510,6 +510,7 @@ void Transaction::saveTransaction(Transaction::pointer txn) bool Transaction::save() const { // This code needs to be fixed to support new-style transactions - FIXME + // This code is going away. It will be handled from SerializedTransaction #if 0 // Identify minimums fields to write for now. // Also maybe write effected accounts for use later.