aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol.cpp')
-rw-r--r--src/protocol.cpp46
1 files changed, 13 insertions, 33 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 2f90fb764c..247c6c2120 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -41,15 +41,6 @@ const char *GETBLOCKTXN="getblocktxn";
const char *BLOCKTXN="blocktxn";
};
-static const char* ppszTypeName[] =
-{
- "ERROR", // Should never occur
- NetMsgType::TX,
- NetMsgType::BLOCK,
- "filtered block", // Should never occur
- "compact block" // Should never occur
-};
-
/** All known message types. Keep this in the same order as the list of
* messages above and in protocol.h.
*/
@@ -166,37 +157,26 @@ CInv::CInv(int typeIn, const uint256& hashIn)
hash = 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))
- throw std::out_of_range(strprintf("CInv::CInv(string, uint256): unknown type '%s'", strType));
- hash = hashIn;
-}
-
bool operator<(const CInv& a, const CInv& b)
{
return (a.type < b.type || (a.type == b.type && a.hash < b.hash));
}
-bool CInv::IsKnownType() const
+std::string CInv::GetCommand() const
{
- return (type >= 1 && type < (int)ARRAYLEN(ppszTypeName));
-}
-
-const char* CInv::GetCommand() const
-{
- if (!IsKnownType())
+ std::string cmd;
+ if (type & MSG_WITNESS_FLAG)
+ cmd.append("witness-");
+ int masked = type & MSG_TYPE_MASK;
+ switch (masked)
+ {
+ case MSG_TX: return cmd.append(NetMsgType::TX);
+ case MSG_BLOCK: return cmd.append(NetMsgType::BLOCK);
+ case MSG_FILTERED_BLOCK: return cmd.append(NetMsgType::MERKLEBLOCK);
+ case MSG_CMPCT_BLOCK: return cmd.append(NetMsgType::CMPCTBLOCK);
+ default:
throw std::out_of_range(strprintf("CInv::GetCommand(): type=%d unknown type", type));
- return ppszTypeName[type];
+ }
}
std::string CInv::ToString() const