Skip to content

Commit

Permalink
Deserialize AddrV1 first if fails deserialize AddrV2
Browse files Browse the repository at this point in the history
  • Loading branch information
Liquid369 authored Jul 7, 2023
1 parent afd0c73 commit 6d3d535
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/rpc/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "masternode-payments.h"
#include "masternodeconfig.h"
#include "masternodeman.h"
#include "netaddress.h"
#include "netbase.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "rpc/server.h"
Expand Down Expand Up @@ -390,7 +391,7 @@ void RelayMNB(CMasternodeBroadcast& mnb, const bool fSucces)

void SerializeMNB(UniValue& statusObjRet, const CMasternodeBroadcast& mnb, const bool fSuccess, int& successful, int& failed)
{
bool isBIP155 = PROTOCOL_VERSION >= MIN_BIP155_PROTOCOL_VERSION;
bool isBIP155 = mnb.addr.IsAddrV1Compatible();
int version = isBIP155 ? PROTOCOL_VERSION | ADDRV2_FORMAT : PROTOCOL_VERSION;
if(fSuccess) {
successful++;
Expand Down Expand Up @@ -877,15 +878,9 @@ UniValue getmasternodescores(const JSONRPCRequest& request)
return obj;
}

bool DecodeHexMnb(CMasternodeBroadcast& mnb, std::string strHexMnb) {

if (!IsHex(strHexMnb))
return false;

bool isBIP155 = PROTOCOL_VERSION >= MIN_BIP155_PROTOCOL_VERSION;
int version = isBIP155 ? PROTOCOL_VERSION | ADDRV2_FORMAT : PROTOCOL_VERSION;
bool DecodeAddrV1(CMasternodeBroadcast& mnb, std::string strHexMnb) {
std::vector<unsigned char> mnbData(ParseHex(strHexMnb));
CDataStream ssData(mnbData, SER_NETWORK, version);
CDataStream ssData(mnbData, SER_NETWORK, PROTOCOL_VERSION);
try {
ssData >> mnb;
}
Expand All @@ -895,6 +890,27 @@ bool DecodeHexMnb(CMasternodeBroadcast& mnb, std::string strHexMnb) {

return true;
}

bool DecodeHexMnb(CMasternodeBroadcast& mnb, std::string strHexMnb) {

if (!IsHex(strHexMnb))
return false;

bool MNAddrV1 = DecodeAddrV1(mnb, strHexMnb);
if (!MNAddrV1) {
std::vector<unsigned char> mnbData(ParseHex(strHexMnb));
CDataStream ssData(mnbData, SER_NETWORK, PROTOCOL_VERSION | ADDRV2_FORMAT);
try {
ssData >> mnb;
}
catch (const std::exception&) {
return false;
}
return true;
}
return true;
}

UniValue createmasternodebroadcast(const JSONRPCRequest& request)
{
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
Expand Down

0 comments on commit 6d3d535

Please sign in to comment.