Structures for tracking transactions by which accounts they affect.

This commit is contained in:
JoelKatz
2012-06-08 18:13:13 -07:00
parent b70cdd7fa4
commit ea5ae2a113
3 changed files with 35 additions and 17 deletions

View File

@@ -20,7 +20,7 @@ Application* theApp = NULL;
DatabaseCon::DatabaseCon(const std::string& name, const char *initStrings[], int initCount)
{
std::string path=strprintf("%s%s", theConfig.DATA_DIR.c_str(), name.c_str());
mDatabase=new SqliteDatabase(path.c_str());
mDatabase = new SqliteDatabase(path.c_str());
mDatabase->connect();
for(int i = 0; i < initCount; ++i)
mDatabase->executeSQL(initStrings[i], true);
@@ -35,15 +35,16 @@ DatabaseCon::~DatabaseCon()
Application::Application() :
mUNL(mIOService),
mNetOps(mIOService, &mMasterLedger), mNodeCache(16384, 600),
mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL),
mTxnDB(NULL), mAcctTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL),
mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL)
{
RAND_bytes(mNonce256.begin(), mNonce256.size());
RAND_bytes(reinterpret_cast<unsigned char *>(&mNonceST), sizeof(mNonceST));
}
extern const char *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], *NetNodeDBInit[];
extern int TxnDBCount, LedgerDBCount, WalletDBCount, HashNodeDBCount, NetNodeDBCount;
extern const char *AcctTxnDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[],
*HashNodeDBInit[], *NetNodeDBInit[];
extern int TxnDBCount, AcctTxnDBCount, LedgerDBCount, WalletDBCount, HashNodeDBCount, NetNodeDBCount;
void Application::stop()
{
@@ -59,11 +60,12 @@ void Application::run()
//
// Construct databases.
//
mTxnDB=new DatabaseCon("transaction.db", TxnDBInit, TxnDBCount);
mLedgerDB=new DatabaseCon("ledger.db", LedgerDBInit, LedgerDBCount);
mWalletDB=new DatabaseCon("wallet.db", WalletDBInit, WalletDBCount);
mHashNodeDB=new DatabaseCon("hashnode.db", HashNodeDBInit, HashNodeDBCount);
mNetNodeDB=new DatabaseCon("netnode.db", NetNodeDBInit, NetNodeDBCount);
mTxnDB = new DatabaseCon("transaction.db", TxnDBInit, TxnDBCount);
mAcctTxnDB = new DatabaseCon("transacct.db", AcctTxnDBInit, AcctTxnDBCount);
mLedgerDB = new DatabaseCon("ledger.db", LedgerDBInit, LedgerDBCount);
mWalletDB = new DatabaseCon("wallet.db", WalletDBInit, WalletDBCount);
mHashNodeDB = new DatabaseCon("hashnode.db", HashNodeDBInit, HashNodeDBCount);
mNetNodeDB = new DatabaseCon("netnode.db", NetNodeDBInit, NetNodeDBCount);
//
// Begin validation and ip maintenance.
@@ -76,7 +78,7 @@ void Application::run()
//
if(!theConfig.PEER_IP.empty() && theConfig.PEER_PORT)
{
mPeerDoor=new PeerDoor(mIOService);
mPeerDoor = new PeerDoor(mIOService);
}
else
{
@@ -88,7 +90,7 @@ void Application::run()
//
if(!theConfig.RPC_IP.empty() && theConfig.RPC_PORT)
{
mRPCDoor=new RPCDoor(mIOService);
mRPCDoor = new RPCDoor(mIOService);
}
else
{
@@ -138,6 +140,7 @@ void Application::run()
Application::~Application()
{
delete mTxnDB;
delete mAcctTxnDB;
delete mLedgerDB;
delete mWalletDB;
delete mHashNodeDB;

View File

@@ -45,7 +45,7 @@ class Application
NetworkOPs mNetOps;
NodeCache mNodeCache;
DatabaseCon* mTxnDB, *mLedgerDB, *mWalletDB, *mHashNodeDB, *mNetNodeDB;
DatabaseCon *mTxnDB, *mAcctTxnDB, *mLedgerDB, *mWalletDB, *mHashNodeDB, *mNetNodeDB;
ConnectionPool mConnectionPool;
PeerDoor* mPeerDoor;
@@ -76,6 +76,7 @@ public:
NodeCache& getNodeCache() { return mNodeCache; }
DatabaseCon* getTxnDB() { return mTxnDB; }
DatabaseCon* getAcctTxnDB() { return mAcctTxnDB; }
DatabaseCon* getLedgerDB() { return mLedgerDB; }
DatabaseCon* getWalletDB() { return mWalletDB; }
DatabaseCon* getHashNodeDB() { return mHashNodeDB; }

View File

@@ -20,7 +20,21 @@ const char *TxnDBInit[] = {
);"
};
int TxnDBCount=sizeof(TxnDBInit)/sizeof(const char *);
int TxnDBCount = sizeof(TxnDBInit) / sizeof(const char *);
const char *AcctTxnDBInit[] = {
"CREATE TABLE AccountTransactions ( \
TransID CHARACTER964) PRIMARY KEY \
Account CHARACTER(64), \
LedgerSeq BIGINT UNSIGNED, \
);",
"CREATE INDEX AcctTxindex ON \
AccountTransactions(Account), \
AccountTransactions(LedgerSeq), \
AccountTransactions(TransID);"
};
int AcctTxnDBCount = sizeof(AcctTxnDBInit) / sizeof(const char *);
// Ledger database holds ledgers and ledger confirmations
const char *LedgerDBInit[] = {
@@ -46,7 +60,7 @@ const char *LedgerDBInit[] = {
#endif
};
int LedgerDBCount=sizeof(LedgerDBInit)/sizeof(const char *);
int LedgerDBCount = sizeof(LedgerDBInit) / sizeof(const char *);
// Wallet database holds local accounts and trusted nodes
const char *WalletDBInit[] = {
@@ -212,7 +226,7 @@ const char *WalletDBInit[] = {
PeerIps(ScanNext);"
};
int WalletDBCount=sizeof(WalletDBInit)/sizeof(const char *);
int WalletDBCount = sizeof(WalletDBInit) / sizeof(const char *);
// Hash node database holds nodes indexed by hash
const char *HashNodeDBInit[] = {
@@ -227,7 +241,7 @@ const char *HashNodeDBInit[] = {
CommittedObjects(LedgerIndex, ObjType);"
};
int HashNodeDBCount=sizeof(HashNodeDBInit)/sizeof(const char *);
int HashNodeDBCount = sizeof(HashNodeDBInit) / sizeof(const char *);
// Net node database holds nodes seen on the network
// XXX Not really used needs replacement.
@@ -241,6 +255,6 @@ const char *NetNodeDBInit[] = {
};
int NetNodeDBCount=sizeof(NetNodeDBInit)/sizeof(const char *);
int NetNodeDBCount = sizeof(NetNodeDBInit) / sizeof(const char *);
// vim:ts=4