Mostly small cleanups and style fixes.

This commit is contained in:
JoelKatz
2011-12-13 18:04:43 -08:00
parent a93d125fce
commit 80a6f7e5ad
15 changed files with 60 additions and 62 deletions

View File

@@ -31,8 +31,8 @@ public:
bool credit(uint64 a) { mBalance+=a; } bool credit(uint64 a) { mBalance+=a; }
bool charge(uint64 a) { assert(mBalance>=a); mBalance-=a; } bool charge(uint64 a) { assert(mBalance>=a); mBalance-=a; }
void incSeq(void) { mAccountSeq++; } void incSeq() { mAccountSeq++; }
void decSeq(void) { assert(mAccountSeq!=0); mAccountSeq--; } void decSeq() { assert(mAccountSeq!=0); mAccountSeq--; }
std::vector<unsigned char> getRaw() const; std::vector<unsigned char> getRaw() const;
}; };

View File

@@ -30,7 +30,6 @@ class Application
ConnectionPool mConnectionPool; ConnectionPool mConnectionPool;
PeerDoor* mPeerDoor; PeerDoor* mPeerDoor;
RPCDoor* mRPCDoor; RPCDoor* mRPCDoor;
//Serializer* mSerializer;
std::map<std::string, Peer::pointer> mPeerMap; std::map<std::string, Peer::pointer> mPeerMap;
boost::recursive_mutex mPeerMapLock; boost::recursive_mutex mPeerMapLock;
@@ -43,14 +42,20 @@ public:
Application(); Application();
ConnectionPool& getConnectionPool() { return(mConnectionPool); } ConnectionPool& getConnectionPool() { return(mConnectionPool); }
UniqueNodeList& getUNL() { return(mUNL); }
Wallet& getWallet() { return(mWallet); }
PubKeyCache& getPubKeyCache() { return mPKCache; }
Database* getDB() { return(mDatabase); }
LedgerMaster& getMasterLedger() { return mMasterLedger; }
ScopedLock getDBLock() { return ScopedLock(dbLock); }
UniqueNodeList& getUNL() { return(mUNL); }
Wallet& getWallet() { return(mWallet); }
PubKeyCache& getPubKeyCache() { return mPKCache; }
boost::asio::io_service& getIOService() { return mIOService; }
LedgerMaster& getMasterLedger() { return mMasterLedger; }
ScopedLock getDBLock() { return ScopedLock(dbLock); }
void setDB(Database* db) { mDatabase=db; } void setDB(Database* db) { mDatabase=db; }
Database* getDB() { return(mDatabase); }
//Serializer* getSerializer(){ return(mSerializer); } //Serializer* getSerializer(){ return(mSerializer); }
//void setSerializer(Serializer* ser){ mSerializer=ser; } //void setSerializer(Serializer* ser){ mSerializer=ser; }

View File

@@ -35,8 +35,8 @@ public:
std::string GetHankoString(HankoFormat format) const; std::string GetHankoString(HankoFormat format) const;
std::vector<unsigned char> GetHankoBinary(HankoFormat format) const; std::vector<unsigned char> GetHankoBinary(HankoFormat format) const;
const std::vector<unsigned char>& GetContactBlock(void) const { return mContactBlock; } const std::vector<unsigned char>& GetContactBlock() const { return mContactBlock; }
const CKey& GetPublicKey(void) const { return mPubKey; } const CKey& GetPublicKey() const { return mPubKey; }
int UpdateContact(std::vector<unsigned char>& Contact); int UpdateContact(std::vector<unsigned char>& Contact);

View File

@@ -14,9 +14,10 @@ struct NetworkStatus
static const int nsbFastSynching=2; // catching up, skipping transactions static const int nsbFastSynching=2; // catching up, skipping transactions
static const int nsbSlowSynching=3; // catching up, txn by txn static const int nsbSlowSynching=3; // catching up, txn by txn
static const int nsbSynched=4; // in synch with the network static const int nsbSynched=4; // in synch with the network
static const int nsbAnonymous=5; // hiding our identity static const int nsbIdentifiable=5; // not hiding our identity
static const int nsbLedgerSync=6; // participating in ledger sync static const int nsbLedgerSync=6; // participating in ledger sync
static const int nsbStuck=7; // unable to sync static const int nsbStuck=7; // unable to sync
static const int nsbShuttingDown=8; // node is shutting down
static const int nnbCount=32; static const int nnbCount=32;
std::bitset<nnbCount> nsbValues; std::bitset<nnbCount> nsbValues;

View File

@@ -7,7 +7,7 @@
bool NewcoinAddress::SetHash160(const uint160& hash160) bool NewcoinAddress::SetHash160(const uint160& hash160)
{ {
SetData(theConfig.TEST_NET ? 112 : 1, &hash160, 20); SetData(51, &hash160, 20);
return true; return true;
} }
@@ -18,21 +18,7 @@ bool NewcoinAddress::SetPubKey(const std::vector<unsigned char>& vchPubKey)
bool NewcoinAddress::IsValid() bool NewcoinAddress::IsValid()
{ {
int nExpectedSize = 20; return nVersion == 51 && vchData.size() == 20;
bool fExpectTestNet = false;
switch(nVersion)
{
case 1:
break;
case 112:
fExpectTestNet = true;
break;
default:
return false;
}
return fExpectTestNet == theConfig.TEST_NET && vchData.size() == nExpectedSize;
} }
NewcoinAddress::NewcoinAddress() NewcoinAddress::NewcoinAddress()

View File

@@ -72,7 +72,7 @@ CKey::pointer PubKeyCache::store(const uint160& id, CKey::pointer key)
std::string encodedPK; std::string encodedPK;
theApp->getDB()->escape(&(pk.front()), pk.size(), encodedPK); theApp->getDB()->escape(&(pk.front()), pk.size(), encodedPK);
sql+=encodedPK; sql+=encodedPK;
sql.append(";"); sql.append(");");
ScopedLock sl(theApp->getDBLock()); ScopedLock sl(theApp->getDBLock());
theApp->getDB()->executeSQL(sql.c_str()); theApp->getDB()->executeSQL(sql.c_str());
return key; return key;

View File

@@ -19,7 +19,7 @@ public:
CKey::pointer locate(const uint160& id); CKey::pointer locate(const uint160& id);
CKey::pointer store(const uint160& id, CKey::pointer key); CKey::pointer store(const uint160& id, CKey::pointer key);
void clear(void); void clear();
}; };
#endif #endif

View File

@@ -46,7 +46,7 @@ public:
bool isLeaf() const { return mDepth==leafDepth; } bool isLeaf() const { return mDepth==leafDepth; }
bool isChildLeaf() const { return mDepth==(leafDepth-1); } bool isChildLeaf() const { return mDepth==(leafDepth-1); }
bool isInner() const { return !isRoot() && !isLeaf(); } bool isInner() const { return !isRoot() && !isLeaf(); }
virtual bool isPopulated(void) const { return false; } virtual bool isPopulated() const { return false; }
SHAMapNode getParentNodeID() { return SHAMapNode(mDepth-1, mNodeID); } SHAMapNode getParentNodeID() { return SHAMapNode(mDepth-1, mNodeID); }
SHAMapNode getChildNodeID(int m); SHAMapNode getChildNodeID(int m);
@@ -59,8 +59,8 @@ public:
bool operator<=(const SHAMapNode&) const; bool operator<=(const SHAMapNode&) const;
bool operator>=(const SHAMapNode&) const; bool operator>=(const SHAMapNode&) const;
virtual std::string getString(void) const; virtual std::string getString() const;
void dump(void); void dump();
static void ClassInit(); static void ClassInit();
static uint256 getNodeID(int depth, const uint256& hash); static uint256 getNodeID(int depth, const uint256& hash);
@@ -85,9 +85,9 @@ public:
// for account balances // for account balances
SHAMapItem(const uint160& tag, const std::vector<unsigned char>& data); SHAMapItem(const uint160& tag, const std::vector<unsigned char>& data);
const uint256& getTag(void) const { return mTag; } const uint256& getTag() const { return mTag; }
std::vector<unsigned char> getData(void) const { return mData; } std::vector<unsigned char> getData() const { return mData; }
const std::vector<unsigned char>& peekData(void) const { return mData; } const std::vector<unsigned char>& peekData() const { return mData; }
void updateData(const std::vector<unsigned char>& data) { mData=data; } void updateData(const std::vector<unsigned char>& data) { mData=data; }
@@ -103,7 +103,7 @@ public:
bool operator!=(const uint256& i) const { return mTag!=i; } bool operator!=(const uint256& i) const { return mTag!=i; }
bool operator<=(const uint256& i) const { return mTag<=i; } bool operator<=(const uint256& i) const { return mTag<=i; }
bool operator>=(const uint256& i) const { return mTag>=i; } bool operator>=(const uint256& i) const { return mTag>=i; }
virtual void dump(void); virtual void dump();
}; };
class SHAMapLeafNode : public SHAMapNode class SHAMapLeafNode : public SHAMapNode
@@ -135,9 +135,9 @@ public:
void addRaw(Serializer &); void addRaw(Serializer &);
virtual bool isPopulated(void) const { return true; } virtual bool isPopulated() const { return true; }
uint32 getSeq(void) const { return mSeq; } uint32 getSeq() const { return mSeq; }
void setSeq(uint32 s) { mSeq=s; } void setSeq(uint32 s) { mSeq=s; }
const uint256& getNodeHash() const { return mHash; } const uint256& getNodeHash() const { return mHash; }
@@ -151,7 +151,7 @@ public:
SHAMapItem::pointer nextItem(const uint256& tag); SHAMapItem::pointer nextItem(const uint256& tag);
SHAMapItem::pointer prevItem(const uint256& tag); SHAMapItem::pointer prevItem(const uint256& tag);
virtual void dump(void); virtual void dump();
}; };
@@ -182,18 +182,18 @@ public:
void addRaw(Serializer&); void addRaw(Serializer&);
uint32 getSeq(void) const { return mSeq; } uint32 getSeq() const { return mSeq; }
void setSeq(uint32 s) { mSeq=s; } void setSeq(uint32 s) { mSeq=s; }
virtual bool isPopulated(void) const { return true; } virtual bool isPopulated() const { return true; }
bool isEmptyBranch(int m) const { return !mHashes[m]; } bool isEmptyBranch(int m) const { return !mHashes[m]; }
const uint256& getNodeHash() const { return mHash; } const uint256& getNodeHash() const { return mHash; }
const uint256& getChildHash(int m) const; const uint256& getChildHash(int m) const;
bool isEmpty() const; bool isEmpty() const;
virtual void dump(void); virtual void dump();
virtual std::string getString(void) const; virtual std::string getString() const;
}; };
enum SHAMapException enum SHAMapException
@@ -300,7 +300,7 @@ public:
virtual bool writeLeafNode(const uint256& hash, const SHAMapNode& id, const std::vector<unsigned char>& rawNode); virtual bool writeLeafNode(const uint256& hash, const SHAMapNode& id, const std::vector<unsigned char>& rawNode);
static bool TestSHAMap(); static bool TestSHAMap();
virtual void dump(void); virtual void dump();
}; };
#endif #endif

View File

@@ -209,7 +209,7 @@ SHAMapItem::pointer SHAMapLeafNode::findItem(const uint256& tag)
return SHAMapItem::pointer(); return SHAMapItem::pointer();
} }
SHAMapItem::pointer SHAMapLeafNode::firstItem(void) SHAMapItem::pointer SHAMapLeafNode::firstItem()
{ {
if(mItems.size()==0) return SHAMapItem::pointer(); if(mItems.size()==0) return SHAMapItem::pointer();
return *(mItems.begin()); return *(mItems.begin());
@@ -252,14 +252,14 @@ SHAMapItem::pointer SHAMapLeafNode::prevItem(const uint256& tag)
return SHAMapItem::pointer(); return SHAMapItem::pointer();
} }
SHAMapItem::pointer SHAMapLeafNode::lastItem(void) SHAMapItem::pointer SHAMapLeafNode::lastItem()
{ {
if(mItems.size()==0) return SHAMapItem::pointer(); if(mItems.size()==0) return SHAMapItem::pointer();
return *(mItems.rbegin()); return *(mItems.rbegin());
} }
bool SHAMapLeafNode::updateHash(void) bool SHAMapLeafNode::updateHash()
{ {
uint256 nh; uint256 nh;
if(mItems.size()!=0) if(mItems.size()!=0)

View File

@@ -22,15 +22,14 @@ CREATE TABLE PubKeys ( -- holds pub keys for nodes and accounts
); );
CREATE TABLE Ledgers ( -- closed ledgers CREATE TABLE Ledgers ( -- closed/accepted ledgers
LedgerHash CHARACTER(64) PRIMARY KEY, LedgerHash CHARACTER(64) PRIMARY KEY,
LedgerSeq BIGINT UNSIGNED, LedgerSeq BIGINT UNSIGNED,
PrevHash CHARACTER(64), PrevHash CHARACTER(64),
FeeHeld BIGINT UNSIGNED, FeeHeld BIGINT UNSIGNED,
ClosingTime BIGINT UNSINGED,
AccountSetHash CHARACTER(64), AccountSetHash CHARACTER(64),
TransSetHash CHARACTER(64), TransSetHash CHARACTER(64),
FullyStored CHARACTER(1), -- all data is in our db
Status CHARACTER(1) -- (A)ccepted, (C)ompatible, (I)ncompatible
); );
CREATE INDEX SeqLedger ON Ledgers(LedgerSeq); CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);

View File

@@ -184,7 +184,7 @@ bool Serializer::addSignature(CKey& key)
return true; return true;
} }
void Serializer::TestSerializer(void) void Serializer::TestSerializer()
{ {
Serializer s(64); Serializer s(64);
} }

View File

@@ -49,7 +49,7 @@ class Serializer
int getLength() const { return mData.size(); } int getLength() const { return mData.size(); }
const std::vector<unsigned char>& peekData() const { return mData; } const std::vector<unsigned char>& peekData() const { return mData; }
std::vector<unsigned char> getData() const { return mData; } std::vector<unsigned char> getData() const { return mData; }
void secureErase(void) { memset(&(mData.front()), 0, mData.size()); } void secureErase() { memset(&(mData.front()), 0, mData.size()); }
// signature functions // signature functions
bool checkSignature(int pubkeyOffset, int signatureOffset) const; bool checkSignature(int pubkeyOffset, int signatureOffset) const;
@@ -57,7 +57,7 @@ class Serializer
bool makeSignature(std::vector<unsigned char> &signature, CKey& rkey) const; bool makeSignature(std::vector<unsigned char> &signature, CKey& rkey) const;
bool addSignature(CKey& rkey); bool addSignature(CKey& rkey);
static void TestSerializer(void); static void TestSerializer();
}; };
#endif #endif

View File

@@ -154,7 +154,7 @@ bool Transaction::save() const
std::string signature; std::string signature;
theApp->getDB()->escape(&(mSignature.front()), mSignature.size(), signature); theApp->getDB()->escape(&(mSignature.front()), mSignature.size(), signature);
sql.append(signature); sql.append(signature);
sql.append(";"); sql.append(");");
ScopedLock sl(theApp->getDBLock()); ScopedLock sl(theApp->getDBLock());
Database* db=theApp->getDB(); Database* db=theApp->getDB();

View File

@@ -9,13 +9,14 @@ void UniqueNodeList::addNode(uint160& hanko, vector<unsigned char>& publicKey)
Database* db=theApp->getDB(); Database* db=theApp->getDB();
string sql="INSERT INTO UNL (Hanko,PubKey) values ("; string sql="INSERT INTO UNL (Hanko,PubKey) values (";
string hashStr; string hashStr;
db->escape(hanko.begin(),hanko.GetSerializeSize(),hashStr); db->escape(hanko.begin(), hanko.GetSerializeSize(), hashStr);
sql.append(hashStr); sql.append(hashStr);
sql.append(","); sql.append(",");
db->escape(&(publicKey[0]),publicKey.size(),hashStr); db->escape(&(publicKey[0]), publicKey.size(), hashStr);
sql.append(hashStr); sql.append(hashStr);
sql.append(")"); sql.append(")");
ScopedLock sl(theApp->getDBLock());
db->executeSQL(sql.c_str()); db->executeSQL(sql.c_str());
} }
@@ -24,12 +25,15 @@ void UniqueNodeList::removeNode(uint160& hanko)
Database* db=theApp->getDB(); Database* db=theApp->getDB();
string sql="DELETE FROM UNL where hanko="; string sql="DELETE FROM UNL where hanko=";
string hashStr; string hashStr;
db->escape(hanko.begin(),hanko.GetSerializeSize(),hashStr); db->escape(hanko.begin(), hanko.GetSerializeSize(), hashStr);
sql.append(hashStr); sql.append(hashStr);
ScopedLock sl(theApp->getDBLock());
db->executeSQL(sql.c_str()); db->executeSQL(sql.c_str());
} }
// 0- we don't care, 1- we care and is valid, 2-invalid signature // 0- we don't care, 1- we care and is valid, 2-invalid signature
#if 0
int UniqueNodeList::checkValid(newcoin::Validation& valid) int UniqueNodeList::checkValid(newcoin::Validation& valid)
{ {
Database* db=theApp->getDB(); Database* db=theApp->getDB();
@@ -38,6 +42,7 @@ int UniqueNodeList::checkValid(newcoin::Validation& valid)
db->escape((unsigned char*) &(valid.hanko()[0]),valid.hanko().size(),hashStr); db->escape((unsigned char*) &(valid.hanko()[0]),valid.hanko().size(),hashStr);
sql.append(hashStr); sql.append(hashStr);
ScopedLock sl(theApp->getDBLock());
if( db->executeSQL(sql.c_str()) ) if( db->executeSQL(sql.c_str()) )
{ {
if(db->startIterRows() && db->getNextRow()) if(db->startIterRows() && db->getNextRow())
@@ -55,21 +60,23 @@ int UniqueNodeList::checkValid(newcoin::Validation& valid)
} }
return(0); // not on our list return(0); // not on our list
} }
#endif
void UniqueNodeList::dumpUNL(std::string& retStr) void UniqueNodeList::dumpUNL(std::string& retStr)
{ {
Database* db=theApp->getDB(); Database* db=theApp->getDB();
string sql="SELECT * FROM UNL"; string sql="SELECT * FROM UNL";
ScopedLock sl(theApp->getDBLock());
if( db->executeSQL(sql.c_str()) ) if( db->executeSQL(sql.c_str()) )
{ {
db->startIterRows(); db->startIterRows();
while(db->getNextRow()) while(db->getNextRow())
{ {
uint160 hanko; uint160 hanko;
int size=db->getBinary("Hanko",hanko.begin(),hanko.GetSerializeSize()); int size=db->getBinary("Hanko", hanko.begin(), hanko.GetSerializeSize());
string tstr; string tstr;
u160ToHuman(hanko,tstr); u160ToHuman(hanko, tstr);
retStr.append(tstr); retStr.append(tstr);
retStr.append("\n"); retStr.append("\n");

View File

@@ -34,7 +34,7 @@ public:
CKey& peekPrivKey() { return mPrivateKey; } CKey& peekPrivKey() { return mPrivateKey; }
CKey::pointer peekPubKey() { return mPublicKey; } CKey::pointer peekPubKey() { return mPublicKey; }
uint160 getAddress(void) const { return mAddress.GetHash160(); } uint160 getAddress() const { return mAddress.GetHash160(); }
}; };
class Wallet : public CBasicKeyStore class Wallet : public CBasicKeyStore