Removed ppszTypeName from protocol.cpp

(cherry picked from commit sipa/bitcoin@e35d0200eb)
This commit is contained in:
Eric Lombrozo 2016-01-10 23:55:11 -08:00 committed by Jack Grigg
parent d1f6072841
commit cf7e89bb8e
2 changed files with 24 additions and 29 deletions

View File

@ -12,14 +12,6 @@
# include <arpa/inet.h>
#endif
static const char* ppszTypeName[] =
{
"ERROR",
"tx",
"block",
"filtered block"
};
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn)
{
memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE);
@ -105,17 +97,13 @@ CInv::CInv(int typeIn, const uint256& hashIn)
CInv::CInv(const std::string& strType, const uint256& hashIn)
{
unsigned int i;
for (i = 1; i < ARRAYLEN(ppszTypeName); i++)
{
if (strType == ppszTypeName[i])
{
type = i;
break;
}
}
if (i == ARRAYLEN(ppszTypeName))
if (strType == "tx")
type = MSG_TX;
else if (strType == "block")
type = MSG_BLOCK;
else
throw std::out_of_range(strprintf("CInv::CInv(string, uint256): unknown type '%s'", strType));
hash = hashIn;
}
@ -126,14 +114,18 @@ bool operator<(const CInv& a, const CInv& b)
bool CInv::IsKnownType() const
{
return (type >= 1 && type < (int)ARRAYLEN(ppszTypeName));
return (type >= 1 && type <= MSG_TYPE_MAX);
}
const char* CInv::GetCommand() const
{
if (!IsKnownType())
switch (type)
{
case MSG_TX: return "tx";
case MSG_BLOCK: return "block";
default:
throw std::out_of_range(strprintf("CInv::GetCommand(): type=%d unknown type", type));
return ppszTypeName[type];
}
}
std::string CInv::ToString() const

View File

@ -119,6 +119,17 @@ public:
unsigned int nTime;
};
/** getdata message types */
enum GetDataMsg
{
MSG_TX = 1,
MSG_BLOCK,
MSG_TYPE_MAX = MSG_BLOCK,
// The following can only occur in getdata. Invs always use TX or BLOCK.
MSG_FILTERED_BLOCK,
UNDEFINED,
};
/** inv message data */
class CInv
{
@ -148,12 +159,4 @@ public:
uint256 hash;
};
enum {
MSG_TX = 1,
MSG_BLOCK,
// Nodes may always request a MSG_FILTERED_BLOCK in a getdata, however,
// MSG_FILTERED_BLOCK should not appear in any invs except as a part of getdata.
MSG_FILTERED_BLOCK,
};
#endif // BITCOIN_PROTOCOL_H