tidy up CInv::GetCommand
(cherry picked from commit sipa/bitcoin@97d7402c2c)
This commit is contained in:
parent
37aa712f0e
commit
6d8962b055
|
@ -95,34 +95,19 @@ CInv::CInv(int typeIn, const uint256& hashIn)
|
|||
hash = hashIn;
|
||||
}
|
||||
|
||||
CInv::CInv(const std::string& strType, const uint256& hashIn)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
return (type >= 1 && type <= MSG_TYPE_MAX);
|
||||
}
|
||||
|
||||
const char* CInv::GetCommand() const
|
||||
std::string CInv::GetCommand() const
|
||||
{
|
||||
std::string cmd;
|
||||
switch (type)
|
||||
{
|
||||
case MSG_TX: return "tx";
|
||||
case MSG_BLOCK: return "block";
|
||||
case MSG_TX: return cmd.append("tx");
|
||||
case MSG_BLOCK: return cmd.append("block");
|
||||
case MSG_FILTERED_BLOCK: return cmd.append("merkleblock");
|
||||
default:
|
||||
throw std::out_of_range(strprintf("CInv::GetCommand(): type=%d unknown type", type));
|
||||
}
|
||||
|
|
|
@ -136,7 +136,6 @@ class CInv
|
|||
public:
|
||||
CInv();
|
||||
CInv(int typeIn, const uint256& hashIn);
|
||||
CInv(const std::string& strType, const uint256& hashIn);
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
|
@ -149,8 +148,7 @@ public:
|
|||
|
||||
friend bool operator<(const CInv& a, const CInv& b);
|
||||
|
||||
bool IsKnownType() const;
|
||||
const char* GetCommand() const;
|
||||
std::string GetCommand() const;
|
||||
std::string ToString() const;
|
||||
|
||||
// TODO: make private (improves encapsulation)
|
||||
|
|
Loading…
Reference in New Issue