diff --git a/AccountState.h b/AccountState.h index 6aceb7d5a..5faefbdd9 100644 --- a/AccountState.h +++ b/AccountState.h @@ -31,8 +31,8 @@ public: bool credit(uint64 a) { mBalance+=a; } bool charge(uint64 a) { assert(mBalance>=a); mBalance-=a; } - void incSeq(void) { mAccountSeq++; } - void decSeq(void) { assert(mAccountSeq!=0); mAccountSeq--; } + void incSeq() { mAccountSeq++; } + void decSeq() { assert(mAccountSeq!=0); mAccountSeq--; } std::vector getRaw() const; }; diff --git a/Application.h b/Application.h index 17dba6765..6da425ea8 100644 --- a/Application.h +++ b/Application.h @@ -30,7 +30,6 @@ class Application ConnectionPool mConnectionPool; PeerDoor* mPeerDoor; RPCDoor* mRPCDoor; - //Serializer* mSerializer; std::map mPeerMap; boost::recursive_mutex mPeerMapLock; @@ -43,14 +42,20 @@ public: Application(); 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; } + Database* getDB() { return(mDatabase); } //Serializer* getSerializer(){ return(mSerializer); } //void setSerializer(Serializer* ser){ mSerializer=ser; } diff --git a/Hanko.h b/Hanko.h index b4a0ecc81..9220c6e71 100644 --- a/Hanko.h +++ b/Hanko.h @@ -35,8 +35,8 @@ public: std::string GetHankoString(HankoFormat format) const; std::vector GetHankoBinary(HankoFormat format) const; - const std::vector& GetContactBlock(void) const { return mContactBlock; } - const CKey& GetPublicKey(void) const { return mPubKey; } + const std::vector& GetContactBlock() const { return mContactBlock; } + const CKey& GetPublicKey() const { return mPubKey; } int UpdateContact(std::vector& Contact); diff --git a/NetworkStatus.h b/NetworkStatus.h index e50478349..d14760057 100644 --- a/NetworkStatus.h +++ b/NetworkStatus.h @@ -14,9 +14,10 @@ struct NetworkStatus static const int nsbFastSynching=2; // catching up, skipping transactions static const int nsbSlowSynching=3; // catching up, txn by txn 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 nsbStuck=7; // unable to sync + static const int nsbShuttingDown=8; // node is shutting down static const int nnbCount=32; std::bitset nsbValues; diff --git a/NewcoinAddress.cpp b/NewcoinAddress.cpp index 1ce4af930..816985a01 100644 --- a/NewcoinAddress.cpp +++ b/NewcoinAddress.cpp @@ -7,7 +7,7 @@ bool NewcoinAddress::SetHash160(const uint160& hash160) { - SetData(theConfig.TEST_NET ? 112 : 1, &hash160, 20); + SetData(51, &hash160, 20); return true; } @@ -18,21 +18,7 @@ bool NewcoinAddress::SetPubKey(const std::vector& vchPubKey) bool NewcoinAddress::IsValid() { - int nExpectedSize = 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; + return nVersion == 51 && vchData.size() == 20; } NewcoinAddress::NewcoinAddress() diff --git a/PubKeyCache.cpp b/PubKeyCache.cpp index ec1fb967e..a6f4cfe1b 100644 --- a/PubKeyCache.cpp +++ b/PubKeyCache.cpp @@ -72,7 +72,7 @@ CKey::pointer PubKeyCache::store(const uint160& id, CKey::pointer key) std::string encodedPK; theApp->getDB()->escape(&(pk.front()), pk.size(), encodedPK); sql+=encodedPK; - sql.append(";"); + sql.append(");"); ScopedLock sl(theApp->getDBLock()); theApp->getDB()->executeSQL(sql.c_str()); return key; diff --git a/PubKeyCache.h b/PubKeyCache.h index 06378e3d9..7e9a0f622 100644 --- a/PubKeyCache.h +++ b/PubKeyCache.h @@ -19,7 +19,7 @@ public: CKey::pointer locate(const uint160& id); CKey::pointer store(const uint160& id, CKey::pointer key); - void clear(void); + void clear(); }; #endif diff --git a/SHAMap.h b/SHAMap.h index 1ea063483..61e6588b4 100644 --- a/SHAMap.h +++ b/SHAMap.h @@ -46,7 +46,7 @@ public: bool isLeaf() const { return mDepth==leafDepth; } bool isChildLeaf() const { return mDepth==(leafDepth-1); } 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 getChildNodeID(int m); @@ -59,8 +59,8 @@ public: bool operator<=(const SHAMapNode&) const; bool operator>=(const SHAMapNode&) const; - virtual std::string getString(void) const; - void dump(void); + virtual std::string getString() const; + void dump(); static void ClassInit(); static uint256 getNodeID(int depth, const uint256& hash); @@ -85,9 +85,9 @@ public: // for account balances SHAMapItem(const uint160& tag, const std::vector& data); - const uint256& getTag(void) const { return mTag; } - std::vector getData(void) const { return mData; } - const std::vector& peekData(void) const { return mData; } + const uint256& getTag() const { return mTag; } + std::vector getData() const { return mData; } + const std::vector& peekData() const { return mData; } void updateData(const std::vector& 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; } - virtual void dump(void); + virtual void dump(); }; class SHAMapLeafNode : public SHAMapNode @@ -135,9 +135,9 @@ public: 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; } const uint256& getNodeHash() const { return mHash; } @@ -151,7 +151,7 @@ public: SHAMapItem::pointer nextItem(const uint256& tag); SHAMapItem::pointer prevItem(const uint256& tag); - virtual void dump(void); + virtual void dump(); }; @@ -182,18 +182,18 @@ public: void addRaw(Serializer&); - uint32 getSeq(void) const { return mSeq; } + uint32 getSeq() const { return mSeq; } 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]; } const uint256& getNodeHash() const { return mHash; } const uint256& getChildHash(int m) const; bool isEmpty() const; - virtual void dump(void); - virtual std::string getString(void) const; + virtual void dump(); + virtual std::string getString() const; }; enum SHAMapException @@ -300,7 +300,7 @@ public: virtual bool writeLeafNode(const uint256& hash, const SHAMapNode& id, const std::vector& rawNode); static bool TestSHAMap(); - virtual void dump(void); + virtual void dump(); }; #endif diff --git a/SHAMapNodes.cpp b/SHAMapNodes.cpp index 31cf9a1e8..9554cc2a9 100644 --- a/SHAMapNodes.cpp +++ b/SHAMapNodes.cpp @@ -209,7 +209,7 @@ SHAMapItem::pointer SHAMapLeafNode::findItem(const uint256& tag) return SHAMapItem::pointer(); } -SHAMapItem::pointer SHAMapLeafNode::firstItem(void) +SHAMapItem::pointer SHAMapLeafNode::firstItem() { if(mItems.size()==0) return SHAMapItem::pointer(); return *(mItems.begin()); @@ -252,14 +252,14 @@ SHAMapItem::pointer SHAMapLeafNode::prevItem(const uint256& tag) return SHAMapItem::pointer(); } -SHAMapItem::pointer SHAMapLeafNode::lastItem(void) +SHAMapItem::pointer SHAMapLeafNode::lastItem() { if(mItems.size()==0) return SHAMapItem::pointer(); return *(mItems.rbegin()); } -bool SHAMapLeafNode::updateHash(void) +bool SHAMapLeafNode::updateHash() { uint256 nh; if(mItems.size()!=0) diff --git a/SQLiteDatabases.sql b/SQLiteDatabases.sql index aa8843f9c..57d47e137 100644 --- a/SQLiteDatabases.sql +++ b/SQLiteDatabases.sql @@ -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, LedgerSeq BIGINT UNSIGNED, PrevHash CHARACTER(64), FeeHeld BIGINT UNSIGNED, + ClosingTime BIGINT UNSINGED, AccountSetHash 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); diff --git a/Serializer.cpp b/Serializer.cpp index 3fc1f014b..3561d840d 100644 --- a/Serializer.cpp +++ b/Serializer.cpp @@ -184,7 +184,7 @@ bool Serializer::addSignature(CKey& key) return true; } -void Serializer::TestSerializer(void) +void Serializer::TestSerializer() { Serializer s(64); } diff --git a/Serializer.h b/Serializer.h index 56c7f9c39..faaee95ac 100644 --- a/Serializer.h +++ b/Serializer.h @@ -49,7 +49,7 @@ class Serializer int getLength() const { return mData.size(); } const std::vector& peekData() const { return mData; } std::vector getData() const { return mData; } - void secureErase(void) { memset(&(mData.front()), 0, mData.size()); } + void secureErase() { memset(&(mData.front()), 0, mData.size()); } // signature functions bool checkSignature(int pubkeyOffset, int signatureOffset) const; @@ -57,7 +57,7 @@ class Serializer bool makeSignature(std::vector &signature, CKey& rkey) const; bool addSignature(CKey& rkey); - static void TestSerializer(void); + static void TestSerializer(); }; #endif diff --git a/Transaction.cpp b/Transaction.cpp index 74791080c..01cefc731 100644 --- a/Transaction.cpp +++ b/Transaction.cpp @@ -154,7 +154,7 @@ bool Transaction::save() const std::string signature; theApp->getDB()->escape(&(mSignature.front()), mSignature.size(), signature); sql.append(signature); - sql.append(";"); + sql.append(");"); ScopedLock sl(theApp->getDBLock()); Database* db=theApp->getDB(); diff --git a/UniqueNodeList.cpp b/UniqueNodeList.cpp index 21efa2496..77500afb6 100644 --- a/UniqueNodeList.cpp +++ b/UniqueNodeList.cpp @@ -9,13 +9,14 @@ void UniqueNodeList::addNode(uint160& hanko, vector& publicKey) Database* db=theApp->getDB(); string sql="INSERT INTO UNL (Hanko,PubKey) values ("; string hashStr; - db->escape(hanko.begin(),hanko.GetSerializeSize(),hashStr); + db->escape(hanko.begin(), hanko.GetSerializeSize(), hashStr); sql.append(hashStr); sql.append(","); - db->escape(&(publicKey[0]),publicKey.size(),hashStr); + db->escape(&(publicKey[0]), publicKey.size(), hashStr); sql.append(hashStr); sql.append(")"); + ScopedLock sl(theApp->getDBLock()); db->executeSQL(sql.c_str()); } @@ -24,12 +25,15 @@ void UniqueNodeList::removeNode(uint160& hanko) Database* db=theApp->getDB(); string sql="DELETE FROM UNL where hanko="; string hashStr; - db->escape(hanko.begin(),hanko.GetSerializeSize(),hashStr); + db->escape(hanko.begin(), hanko.GetSerializeSize(), hashStr); sql.append(hashStr); + + ScopedLock sl(theApp->getDBLock()); db->executeSQL(sql.c_str()); } // 0- we don't care, 1- we care and is valid, 2-invalid signature +#if 0 int UniqueNodeList::checkValid(newcoin::Validation& valid) { 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); sql.append(hashStr); + ScopedLock sl(theApp->getDBLock()); if( db->executeSQL(sql.c_str()) ) { if(db->startIterRows() && db->getNextRow()) @@ -55,21 +60,23 @@ int UniqueNodeList::checkValid(newcoin::Validation& valid) } return(0); // not on our list } - +#endif void UniqueNodeList::dumpUNL(std::string& retStr) { Database* db=theApp->getDB(); string sql="SELECT * FROM UNL"; + + ScopedLock sl(theApp->getDBLock()); if( db->executeSQL(sql.c_str()) ) { db->startIterRows(); while(db->getNextRow()) { uint160 hanko; - int size=db->getBinary("Hanko",hanko.begin(),hanko.GetSerializeSize()); + int size=db->getBinary("Hanko", hanko.begin(), hanko.GetSerializeSize()); string tstr; - u160ToHuman(hanko,tstr); + u160ToHuman(hanko, tstr); retStr.append(tstr); retStr.append("\n"); diff --git a/Wallet.h b/Wallet.h index a9ecd1510..813b8c05d 100644 --- a/Wallet.h +++ b/Wallet.h @@ -34,7 +34,7 @@ public: CKey& peekPrivKey() { return mPrivateKey; } CKey::pointer peekPubKey() { return mPublicKey; } - uint160 getAddress(void) const { return mAddress.GetHash160(); } + uint160 getAddress() const { return mAddress.GetHash160(); } }; class Wallet : public CBasicKeyStore