Give Arthur a way to get all the accounts changed by a ledger.

This commit is contained in:
JoelKatz
2012-06-25 23:16:20 -07:00
parent cbdb6724e5
commit cc6052d294
3 changed files with 35 additions and 8 deletions

View File

@@ -24,6 +24,8 @@ const char *TxnDBInit[] = {
);",
"CREATE INDEX AcctTxindex ON \
AccountTransactions(Account, LedgerSeq, TransID);",
"CREATE INDEX AcctLgrIndex ON \
AccountTransactions(LedgerSeq, Account, TransID);",
"END TRANSACTION;"
};

View File

@@ -629,22 +629,46 @@ std::vector< std::pair<uint32, uint256> >
std::string sql =
str(boost::format("SELECT LedgerSeq,TransID FROM AccountTransactions INDEXED BY AcctTxIndex "
" WHERE Account = '%s' AND LedgerSeq <= '%d' AND LedgerSeq >= '%d' ORDER BY LedgerSeq LIMIT 1000")
" WHERE Account = '%s' AND LedgerSeq <= '%d' AND LedgerSeq >= '%d' ORDER BY LedgerSeq LIMIT 1000;")
% account.humanAccountID() % maxLedger % minLedger);
Database *db = theApp->getTxnDB()->getDB();
ScopedLock dbLock = theApp->getTxnDB()->getDBLock();
SQL_FOREACH(db, sql)
{
std::string txID;
db->getStr("TransID", txID);
affectedAccounts.push_back(std::make_pair<uint32, uint256>(db->getInt("LedgerSeq"), uint256(txID)));
Database* db = theApp->getTxnDB()->getDB();
ScopedLock dbLock = theApp->getTxnDB()->getDBLock();
SQL_FOREACH(db, sql)
{
std::string txID;
db->getStr("TransID", txID);
affectedAccounts.push_back(std::make_pair<uint32, uint256>(db->getInt("LedgerSeq"), uint256(txID)));
}
}
return affectedAccounts;
}
std::vector<NewcoinAddress>
NetworkOPs::getAffectedAccounts(uint32 ledgerSeq)
{
std::vector<NewcoinAddress> accounts;
std::string sql = str(boost::format
("SELECT DISTINCT Account FROM AccountTransactions INDEXED BY AcctLgrIndex WHERE LedgerSeq = '%d';")
% ledgerSeq);
NewcoinAddress acct;
{
Database* db = theApp->getTxnDB()->getDB();
ScopedLock dblock = theApp->getTxnDB()->getDBLock();
SQL_FOREACH(db, sql)
{
std::string str;
db->getStr("Account", str);
if (acct.setAccountID(str))
accounts.push_back(acct);
}
}
return accounts;
}
bool NetworkOPs::recvValidation(SerializedValidation::pointer val)
{
Log(lsINFO) << "recvValidation " << val->getLedgerHash().GetHex();

View File

@@ -148,6 +148,7 @@ public:
// client information retrieval functions
std::vector< std::pair<uint32, uint256> >
getAffectedAccounts(const NewcoinAddress& account, uint32 minLedger, uint32 maxLedger);
std::vector<NewcoinAddress> getAffectedAccounts(uint32 ledgerSeq);
//
// Monitoring: publisher side