Minor clean up for human formats and DB.

This commit is contained in:
Arthur Britto
2012-03-19 12:11:56 -07:00
parent ddb3f501b1
commit b4751f9a3a
4 changed files with 27 additions and 32 deletions

View File

@@ -32,8 +32,7 @@ void AccountState::addJson(Json::Value& val)
{
Json::Value as(Json::objectValue);
// XXX Might want account public here, if available.
as["Account"]=mAccountID.humanAccountID();
as["AccountID"]=mAccountID.humanAccountID();
as["Balance"]=boost::lexical_cast<std::string>(mBalance);
as["SendSequence"]=mAccountSeq;
if(!mValid) as["Invalid"]=true;

View File

@@ -4,11 +4,11 @@
const char *TxnDBInit[] = {
"CREATE TABLE Transactions ( \
TransID CHARACTER(64) PRIMARY KEY, \
FromAcct CHARACTER(40), \
FromAcct CHARACTER(35), \
FromSeq BIGINT UNSIGNED, \
FromLedger BIGINT UNSIGNED, \
Identifier BIGINT UNSIGNED, \
ToAcct CHARACTER(40), \
ToAcct CHARACTER(35), \
Amount BIGINT UNSIGNED, \
Fee BIGINT UNSIGNED, \
FirstSeen TEXT, \
@@ -17,7 +17,7 @@ const char *TxnDBInit[] = {
Signature BLOB \
);",
"CREATE TABLE PubKeys ( \
ID CHARACTER(40) PRIMARY KEY, \
ID CHARACTER(35) PRIMARY KEY, \
PubKey BLOB \
);" };
@@ -35,14 +35,17 @@ const char *LedgerDBInit[] = {
TransSetHash CHARACTER(64) \
);",
"CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);",
#if 0
"CREATE TABLE LedgerConfirmations ( \
LedgerSeq BIGINT UNSIGNED, \
LedgerHash CHARACTER(64), \
Hanko CHARACTER(40), \
Hanko CHARACTER(35), \
Signature BLOB \
);",
"CREATE INDEX LedgerConfByHash ON \
LedgerConfirmations(LedgerHash)l" };
LedgerConfirmations(LedgerHash)"
#endif
};
int LedgerDBCount=sizeof(LedgerDBInit)/sizeof(const char *);
@@ -53,22 +56,22 @@ const char *WalletDBInit[] = {
Seq BIGINT UNSIGNED, \
Comment TEXT \
);",
"CREATE TABLE TrustedNodes ( \
Hanko CHARACTER(35) PRIMARY KEY, \
PubKey CHARACTER(53), \
Comment TEXT \
);" };
#if 0
"CREATE TABLE LocalAccounts ( \
ID CHARACTER(40) PRIMARY KEY, \
KeyType CHARACTER(1), \
ID CHARACTER(35) PRIMARY KEY, \
PrivateKey TEXT \
Seq BIGINT UNSIGNED, \
Balance BIGINT UNSIGNED, \
LedgerSeq BIGINT UNSIGNED, \
Comment TEXT \
);",
"CREATE TABLE TrustedNodes ( \
Hanko CHARACTER(40) PRIMARY KEY, \
PubKey CHARACTER(66), \
Comment TEXT \
);" };
// TrustLevel SMALLINT,
#endif
int WalletDBCount=sizeof(WalletDBInit)/sizeof(const char *);
@@ -89,11 +92,12 @@ int HashNodeDBCount=sizeof(HashNodeDBInit)/sizeof(const char *);
// Net node database holds nodes seen on the network
const char *NetNodeDBInit[] = {
"CREATE TABLE KnownNodes ( \
Hanko CHARACTER(40) PRIMARY KEY, \
Hanko CHARACTER(35) PRIMARY KEY, \
LastSeen TEXT, \
HaveContactInfo CHARACTER(1), \
ContactObject BLOB \
);" };
);"
};
int NetNodeDBCount=sizeof(NetNodeDBInit)/sizeof(const char *);

View File

@@ -35,7 +35,7 @@ CKey::pointer PubKeyCache::locate(const NewcoinAddress& id)
assert(false); // bad data in DB
return CKey::pointer();
}
if(1)
{ // put it in cache (okay if we race with another retriever)
boost::mutex::scoped_lock sl(mLock);
@@ -53,15 +53,17 @@ CKey::pointer PubKeyCache::store(const NewcoinAddress& id, CKey::pointer key)
if(!pit.second) // there was an existing key
return pit.first->second;
}
std::string sql="INSERT INTO PubKeys (ID,PubKey) VALUES ('";
sql+=id.humanAccountID();
sql+="',";
std::vector<unsigned char> pk=key->GetPubKey();
std::string encodedPK;
theApp->getTxnDB()->getDB()->escape(&(pk.front()), pk.size(), encodedPK);
std::string sql="INSERT INTO PubKeys (ID,PubKey) VALUES ('";
sql+=id.humanAccountID();
sql+="',";
sql+=encodedPK;
sql.append(");");
ScopedLock dbl(theApp->getTxnDB()->getDBLock());
theApp->getTxnDB()->getDB()->executeSQL(sql.c_str(), true);
return key;

View File

@@ -154,15 +154,6 @@ void LocalAccountFamily::write(bool is_new)
sql.append(mFamily.humanFamilyGenerator());
sql.append("','");
// EC_GROUP* grp=EC_GROUP_new_by_curve_name(NID_secp256k1);
// if(!grp) return;
// char *rpk=EC_POINT_point2hex(grp, mRootPubKey, POINT_CONVERSION_COMPRESSED, NULL);
// EC_GROUP_free(grp);
// if(!rpk) return;
// sql.append(rpk);
// OPENSSL_free(rpk);
// sql.append("','");
sql.append(boost::lexical_cast<std::string>(mLastSeq));
sql.append("',");
@@ -374,7 +365,6 @@ void Wallet::load()
LocalAccountFamily::pointer f(doPublic(familyGenerator, true, false));
if(f)
{
// XXX Compare could be better.
assert(f->getFamily().getFamilyGenerator()==familyGenerator.getFamilyGenerator());
f->setSeq(seq);
f->setComment(comment);