Browse Source

Merge pull request #4398

86fe1b8 update coding.md to reflect changes by pull (Philip Kaufmann)
e10dcf2 ensure clean and consistent "namespace" usage (Philip Kaufmann)
0.10
Wladimir J. van der Laan 10 years ago
parent
commit
9125ef9421
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 25
      doc/coding.md
  2. 4
      src/base58.cpp
  3. 7
      src/checkpoints.cpp
  4. 7
      src/checkpoints.h
  5. 2
      src/init.h
  6. 3
      src/key.cpp
  7. 11
      src/main.cpp
  8. 3
      src/net.h
  9. 5
      src/script.cpp
  10. 3
      src/util.cpp

25
doc/coding.md

@ -4,7 +4,7 @@ Coding
Please be consistent with the existing coding style. Please be consistent with the existing coding style.
Block style: Block style:
```c++
bool Function(char* psz, int n) bool Function(char* psz, int n)
{ {
// Comment summarising what this section of code does // Comment summarising what this section of code does
@ -19,12 +19,33 @@ Block style:
// Success return is usually at the end // Success return is usually at the end
return true; return true;
} }
```
- ANSI/Allman block style - ANSI/Allman block style
- 4 space indenting, no tabs - 4 space indenting, no tabs
- No extra spaces inside parenthesis; please don't do ( this ) - No extra spaces inside parenthesis; please don't do ( this )
- No space after function names, one space after if, for and while - No space after function names, one space after if, for and while
- Includes need to be ordered alphabetically, separate own and foreign headers with a new-line (example key.cpp):
```c++
#include "key.h"
#include "crypto/sha2.h"
#include "util.h"
#include <openssl/foo.h>
```
- Class or struct keywords in header files need to be ordered alphabetically:
```c++
class CAlpha;
class CBeta;
```
- When using namespace keyword use the following form:
```c++
namespace Foo {
...
} // Foo
```
Variable names begin with the type in lowercase, like nSomeVariable. Variable names begin with the type in lowercase, like nSomeVariable.
Please don't put the first word of the variable name in lowercase like Please don't put the first word of the variable name in lowercase like
someVariable. someVariable.

4
src/base58.cpp

@ -186,6 +186,7 @@ int CBase58Data::CompareTo(const CBase58Data& b58) const {
} }
namespace { namespace {
class CBitcoinAddressVisitor : public boost::static_visitor<bool> { class CBitcoinAddressVisitor : public boost::static_visitor<bool> {
private: private:
CBitcoinAddress *addr; CBitcoinAddress *addr;
@ -196,7 +197,8 @@ namespace {
bool operator()(const CScriptID &id) const { return addr->Set(id); } bool operator()(const CScriptID &id) const { return addr->Set(id); }
bool operator()(const CNoDestination &no) const { return false; } bool operator()(const CNoDestination &no) const { return false; }
}; };
};
} // anon namespace
bool CBitcoinAddress::Set(const CKeyID &id) { bool CBitcoinAddress::Set(const CKeyID &id) {
SetData(Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS), &id, 20); SetData(Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS), &id, 20);

7
src/checkpoints.cpp

@ -12,8 +12,8 @@
#include <boost/assign/list_of.hpp> // for 'map_list_of()' #include <boost/assign/list_of.hpp> // for 'map_list_of()'
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
namespace Checkpoints namespace Checkpoints {
{
typedef std::map<int, uint256> MapCheckpoints; typedef std::map<int, uint256> MapCheckpoints;
// How many times we expect transactions after the last checkpoint to // How many times we expect transactions after the last checkpoint to
@ -161,4 +161,5 @@ namespace Checkpoints
} }
return NULL; return NULL;
} }
}
} // namespace Checkpoints

7
src/checkpoints.h

@ -13,8 +13,8 @@ class uint256;
/** Block-chain checkpoints are compiled-in sanity checks. /** Block-chain checkpoints are compiled-in sanity checks.
* They are updated every release or three. * They are updated every release or three.
*/ */
namespace Checkpoints namespace Checkpoints {
{
// Returns true if block passes checkpoint checks // Returns true if block passes checkpoint checks
bool CheckBlock(int nHeight, const uint256& hash); bool CheckBlock(int nHeight, const uint256& hash);
@ -27,6 +27,7 @@ namespace Checkpoints
double GuessVerificationProgress(CBlockIndex *pindex, bool fSigchecks = true); double GuessVerificationProgress(CBlockIndex *pindex, bool fSigchecks = true);
extern bool fEnabled; extern bool fEnabled;
}
} //namespace Checkpoints
#endif #endif

2
src/init.h

@ -12,7 +12,7 @@ class CWallet;
namespace boost { namespace boost {
class thread_group; class thread_group;
}; } // namespace boost
extern CWallet* pwalletMain; extern CWallet* pwalletMain;

3
src/key.cpp

@ -377,8 +377,7 @@ const unsigned char vchMaxModHalfOrder[32] = {
const unsigned char vchZero[0] = {}; const unsigned char vchZero[0] = {};
} // anon namespace
}; // end of anonymous namespace
bool CKey::Check(const unsigned char *vch) { bool CKey::Check(const unsigned char *vch) {
return CompareBigEndian(vch, 32, vchZero, 0) > 0 && return CompareBigEndian(vch, 32, vchZero, 0) > 0 &&

11
src/main.cpp

@ -72,6 +72,7 @@ const string strMessageMagic = "Bitcoin Signed Message:\n";
// Internal stuff // Internal stuff
namespace { namespace {
struct CBlockIndexWorkComparator struct CBlockIndexWorkComparator
{ {
bool operator()(CBlockIndex *pa, CBlockIndex *pb) { bool operator()(CBlockIndex *pa, CBlockIndex *pb) {
@ -120,7 +121,8 @@ namespace {
}; };
map<uint256, pair<NodeId, list<QueuedBlock>::iterator> > mapBlocksInFlight; map<uint256, pair<NodeId, list<QueuedBlock>::iterator> > mapBlocksInFlight;
map<uint256, pair<NodeId, list<uint256>::iterator> > mapBlocksToDownload; map<uint256, pair<NodeId, list<uint256>::iterator> > mapBlocksToDownload;
}
} // anon namespace
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
@ -130,6 +132,7 @@ namespace {
// These functions dispatch to one or all registered wallets // These functions dispatch to one or all registered wallets
namespace { namespace {
struct CMainSignals { struct CMainSignals {
// Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. // Notifies listeners of updated transaction data (transaction, and optionally the block it is found in.
boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction; boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction;
@ -144,7 +147,8 @@ struct CMainSignals {
// Tells listeners to broadcast their data. // Tells listeners to broadcast their data.
boost::signals2::signal<void ()> Broadcast; boost::signals2::signal<void ()> Broadcast;
} g_signals; } g_signals;
}
} // anon namespace
void RegisterWallet(CWalletInterface* pwalletIn) { void RegisterWallet(CWalletInterface* pwalletIn) {
g_signals.SyncTransaction.connect(boost::bind(&CWalletInterface::SyncTransaction, pwalletIn, _1, _2)); g_signals.SyncTransaction.connect(boost::bind(&CWalletInterface::SyncTransaction, pwalletIn, _1, _2));
@ -274,7 +278,6 @@ void MarkBlockAsReceived(const uint256 &hash, NodeId nodeFrom = -1) {
state->nLastBlockReceive = GetTimeMicros(); state->nLastBlockReceive = GetTimeMicros();
mapBlocksInFlight.erase(itInFlight); mapBlocksInFlight.erase(itInFlight);
} }
} }
// Requires cs_main. // Requires cs_main.
@ -310,7 +313,7 @@ void MarkBlockAsInFlight(NodeId nodeid, const uint256 &hash) {
mapBlocksInFlight[hash] = std::make_pair(nodeid, it); mapBlocksInFlight[hash] = std::make_pair(nodeid, it);
} }
} } // anon namespace
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
LOCK(cs_main); LOCK(cs_main);

3
src/net.h

@ -28,14 +28,13 @@
#include <boost/signals2/signal.hpp> #include <boost/signals2/signal.hpp>
#include <openssl/rand.h> #include <openssl/rand.h>
class CAddrMan; class CAddrMan;
class CBlockIndex; class CBlockIndex;
class CNode; class CNode;
namespace boost { namespace boost {
class thread_group; class thread_group;
} } // namespace boost
/** Time between pings automatically sent out for latency probing and keepalive (in seconds). */ /** Time between pings automatically sent out for latency probing and keepalive (in seconds). */
static const int PING_INTERVAL = 2 * 60; static const int PING_INTERVAL = 2 * 60;

5
src/script.cpp

@ -974,6 +974,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
namespace { namespace {
/** Wrapper that serializes like CTransaction, but with the modifications /** Wrapper that serializes like CTransaction, but with the modifications
* required for the signature hash done in-place * required for the signature hash done in-place
*/ */
@ -1066,7 +1067,8 @@ public:
::Serialize(s, txTo.nLockTime, nType, nVersion); ::Serialize(s, txTo.nLockTime, nType, nVersion);
} }
}; };
}
} // anon namespace
uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType) uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
{ {
@ -1092,7 +1094,6 @@ uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsig
return ss.GetHash(); return ss.GetHash();
} }
// Valid signature cache, to avoid doing expensive ECDSA signature checking // Valid signature cache, to avoid doing expensive ECDSA signature checking
// twice for every transaction (once when accepted into memory pool, and // twice for every transaction (once when accepted into memory pool, and
// again when accepted into the block chain) // again when accepted into the block chain)

3
src/util.cpp

@ -77,11 +77,12 @@
// See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options // See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options
// http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION // http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION
namespace boost { namespace boost {
namespace program_options { namespace program_options {
std::string to_internal(const std::string&); std::string to_internal(const std::string&);
} }
}
} // namespace boost
using namespace std; using namespace std;

Loading…
Cancel
Save