Get the databases up and running.

This commit is contained in:
JoelKatz
2011-12-30 16:08:25 -08:00
parent 86ce1e39d8
commit 983f4560f3
4 changed files with 127 additions and 22 deletions

View File

@@ -44,30 +44,26 @@ Application::Application() :
{
theConfig.load();
uint160 rootFamily=mWallet.addFamily("This is my payphrase.", true);
LocalAccount::pointer rootAccount=mWallet.getLocalAccount(rootFamily, 0);
assert(!!rootAccount);
uint160 rootAddress=rootAccount->getAddress();
assert(!!rootAddress);
Ledger::pointer firstLedger(new Ledger(rootAddress, 1000000));
firstLedger->setClosed();
firstLedger->setAccepted();
mMasterLedger.pushLedger(firstLedger);
Ledger::pointer secondLedger=firstLedger->closeLedger(time(NULL));
mMasterLedger.pushLedger(secondLedger);
mMasterLedger.setSynced();
}
extern std::string TxnDBInit, LedgerDBInit, WalletDBInit, HashNodeDBInit, NetNodeDBInit;
void Application::run()
{
mTxnDB=new DatabaseCon("transaction.db");
mTxnDB->getDB()->executeSQL(TxnDBInit.c_str());
mLedgerDB=new DatabaseCon("ledger.db");
mLedgerDB->getDB()->executeSQL(LedgerDBInit.c_str());
mWalletDB=new DatabaseCon("wallet.db");
mWalletDB->getDB()->executeSQL(WalletDBInit.c_str());
mHashNodeDB=new DatabaseCon("hashnode.db");
mHashNodeDB->getDB()->executeSQL(HashNodeDBInit.c_str());
mNetNodeDB=new DatabaseCon("netnode.db");
mNetNodeDB->getDB()->executeSQL(NetNodeDBInit.c_str());
if(theConfig.PEER_PORT)
{
@@ -84,6 +80,19 @@ void Application::run()
std::cout << "Before Run." << std::endl;
mIOService.run(); // This blocks
// TEMPORARY CODE
uint160 rootFamily=mWallet.addFamily("This is my payphrase.", true);
LocalAccount::pointer rootAccount=mWallet.getLocalAccount(rootFamily, 0);
assert(!!rootAccount);
uint160 rootAddress=rootAccount->getAddress();
assert(!!rootAddress);
Ledger::pointer firstLedger(new Ledger(rootAddress, 1000000));
firstLedger->setClosed();
firstLedger->setAccepted();
mMasterLedger.pushLedger(firstLedger);
Ledger::pointer secondLedger=firstLedger->closeLedger(time(NULL));
mMasterLedger.pushLedger(secondLedger);
mMasterLedger.setSynced();
// temporary
return;
mWallet.load();

View File

@@ -24,7 +24,7 @@ Config::Config()
RPC_USER="admin";
RPC_PASSWORD="pass";
DATA_DIR="";
DATA_DIR="db/";
TRANSACTION_FEE_BASE=1000;
}

97
DBInit.cpp Normal file
View File

@@ -0,0 +1,97 @@
#include <string>
// Transaction database holds transactions and public keys
std::string TxnDBInit(" \
CREATE TABLE Transactions ( \
TransID CHARACTER(64) PRIMARY KEY, \
FromAcct CHARACTER(40), \
FromSeq BIGINT UNSIGNED, \
FromLedger BIGINT UNSIGNED, \
Identifier BIGINT UNSIGNED, \
ToAcct CHARACTER(40), \
Amount BIGINT UNSIGNED, \
Fee BIGINT UNSIGNED, \
FirstSeen TEXT, \
CommitSeq BIGINT UNSIGNED, \
Status CHARACTER(1), \
Signature BLOB \
); \
\
CREATE TABLE PubKeys ( \
ID CHARACTER(40) PRIMARY KEY, \
PubKey BLOB \
); \
");
// Ledger database holds ledgers and ledger confirmations
std::string LedgerDBInit(" \
CREATE TABLE Ledgers ( \
LedgerHash CHARACTER(64) PRIMARY KEY, \
LedgerSeq BIGINT UNSIGNED, \
PrevHash CHARACTER(64), \
FeeHeld BIGINT UNSIGNED, \
ClosingTime BIGINT UNSINGED, \
AccountSetHash CHARACTER(64), \
TransSetHash CHARACTER(64) \
); \
CREATE INDEX SeqLedger ON Ledgers(LedgerSeq); \
\
CREATE TABLE LedgerConfirmations ( \
LedgerSeq BIGINT UNSIGNED, \
LedgerHash CHARACTER(64), \
Hanko CHARACTER(40), \
Signature BLOB \
); \
CREATE INDEX LedgerConfByHash ON \
LedgerConfirmations(LedgerHash); \
");
// Wallet database holds local accounts and trusted nodes
std::string WalletDBInit(" \
CREATE TABLE LocalAcctFamilies ( \
FamilyName CHARACTER(40) PRIMARY KEY, \
RootPubKey CHARACTER(66), \
Seq BIGINT UNSIGNED, \
Name TEXT, \
Comment TEXT \
); \
\
CREATE TABLE LocalAccounts ( \
ID CHARACTER(40) PRIMARY KEY, \
DKID CHARACTER(40), \
DKSeq BIGINT UNSIGNED, \
Seq BIGINT UNSIGNED, \
Balance BIGINT UNSIGNED, \
LedgerSeq BIGINT UNSIGNED, \
Comment TEXT \
); \
\
CREATE TABLE TrustedNodes ( ` \
Hanko CHARACTER(40) PRIMARY KEY, \
TrustLevel SMALLINT, \
Comment TEXT \
); \
");
// Hash node database holds nodes indexed by hash
std::string HashNodeDBInit(" \
CREATE TABLE CommittedObjects ( \
Hash CHARACTER(64) PRIMARY KEY, \
ObjType CHAR(1) NOT NULL, \
LedgerIndex BIGINT UNSIGNED, \
Object BLOB \
); \
CREATE INDEX ObjectLocate ON \
CommittedObjects(LedgerIndex, ObjType); \
");
// Net node database holds nodes seen on the network
std::string NetNodeDBInit(" \
CREATE TABLE KnownNodes ( \
Hanko CHARACTER(40) PRIMARY KEY, \
LastSeen TEXT, \
HaveContactInfo CHARACTER(1), \
ContactObject BLOB \
); \
");

View File

@@ -1,5 +1,4 @@
CREATE TABLE Transactions ( -- transactions in all states
TransID CHARACTER(64) PRIMARY KEY, -- in hex
FromAcct CHARACTER(40), -- 20 byte hash of pub key in hex
@@ -15,13 +14,14 @@ CREATE TABLE Transactions ( -- transactions in all states
Signature BLOB
);
CREATE TABLE PubKeys ( -- holds pub keys for nodes and accounts
ID CHARACTER(40) PRIMARY KEY,
PubKey BLOB
);
CREATE TABLE Ledgers ( -- closed/accepted ledgers
LedgerHash CHARACTER(64) PRIMARY KEY,
LedgerSeq BIGINT UNSIGNED,
@@ -29,12 +29,11 @@ CREATE TABLE Ledgers ( -- closed/accepted ledgers
FeeHeld BIGINT UNSIGNED,
ClosingTime BIGINT UNSINGED,
AccountSetHash CHARACTER(64),
TransSetHash CHARACTER(64),
TransSetHash CHARACTER(64)
);
CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);
CREATE TABLE LedgerConfirmations (
LedgerSeq BIGINT UNSIGNED,
LedgerHash CHARACTER(64),
@@ -45,6 +44,8 @@ CREATE TABLE LedgerConfirmations (
CREATE INDEX LedgerConfByHash ON LedgerConfirmations(LedgerHash);
CREATE TABLE TrustedNodes (
Hanko CHARACTER(40) PRIMARY KEY,
TrustLevel SMALLINT,
@@ -74,7 +75,7 @@ CREATE TABLE LocalAcctFamilies ( -- a family of accounts that share a payphrase
Seq BIGINT UNSIGNED, -- next one to issue
Name TEXT,
Comment TEXT
)
);
CREATE TABLE LocalAccounts ( -- an individual account
ID CHARACTER(40) PRIMARY KEY,
@@ -85,5 +86,3 @@ CREATE TABLE LocalAccounts ( -- an individual account
LedgerSeq BIGINT UNSIGNED, -- ledger this balance is from
Comment TEXT
);
CREATE UNIQUE INDEX AccountLocate ON LocalAccounts(DKID, DKSeq);