Skip to content

Commit 255773f

Browse files
committed
[BDAP] Fix account registration when less than 16 months
1 parent 36a61b9 commit 255773f

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

src/bdap/domainentrydb.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -658,15 +658,16 @@ bool CheckDomainEntryTx(const CTransactionRef& tx, const CScript& scriptOp, cons
658658
errorMessage = "Failed to get fees to add a new BDAP account";
659659
return false;
660660
}
661-
std::vector<unsigned char> vchMonths = vvchArgs[2];
662-
std::string strMonths = stringFromVch(vchMonths);
663-
if (IsHex(strMonths)) {
664-
vchMonths = ParseHex(strMonths);
665-
}
666-
int nMonths = CScriptNum(vchMonths, false, 10).getint();
661+
std::string strMonths = stringFromVch(vvchArgs[2]);
662+
std::size_t foundMonth = strMonths.find("Month");
663+
if (foundMonth != std::string::npos)
664+
strMonths.replace(foundMonth, 5, "");
665+
666+
uint32_t nMonths;
667+
ParseUInt32(strMonths, &nMonths);
667668
if (nMonths >= 10000)
668669
nMonths = 24;
669-
if (nMonths < 10000 && !GetBDAPFees(OP_BDAP_NEW, OP_BDAP_ACCOUNT_ENTRY, entry.ObjectType(), nMonths, monthlyFee, oneTimeFee, depositFee)) {
670+
if (nMonths < 10000 && !GetBDAPFees(OP_BDAP_NEW, OP_BDAP_ACCOUNT_ENTRY, entry.ObjectType(), (uint16_t)nMonths, monthlyFee, oneTimeFee, depositFee)) {
670671
errorMessage = "Failed to get fees to add a new BDAP account";
671672
return false;
672673
}
@@ -724,15 +725,16 @@ bool CheckDomainEntryTx(const CTransactionRef& tx, const CScript& scriptOp, cons
724725
errorMessage = "Failed to get fees to add a new BDAP account";
725726
return false;
726727
}
727-
std::vector<unsigned char> vchMonths = vvchArgs[2];
728-
std::string strMonths = stringFromVch(vchMonths);
729-
if (IsHex(strMonths)) {
730-
vchMonths = ParseHex(strMonths);
731-
}
732-
int nMonths = CScriptNum(vchMonths, false, 10).getint();
728+
std::string strMonths = stringFromVch(vvchArgs[2]);
729+
std::size_t foundMonth = strMonths.find("Month");
730+
if (foundMonth != std::string::npos)
731+
strMonths.replace(foundMonth, 5, "");
732+
733+
uint32_t nMonths;
734+
ParseUInt32(strMonths, &nMonths);
733735
if (nMonths >= 10000)
734736
nMonths = 24;
735-
if (!GetBDAPFees(OP_BDAP_MODIFY, OP_BDAP_ACCOUNT_ENTRY, entry.ObjectType(), nMonths, monthlyFee, oneTimeFee, depositFee)) {
737+
if (!GetBDAPFees(OP_BDAP_MODIFY, OP_BDAP_ACCOUNT_ENTRY, entry.ObjectType(), (uint16_t)nMonths, monthlyFee, oneTimeFee, depositFee)) {
736738
errorMessage = "Failed to get fees to add a new BDAP account";
737739
return false;
738740
}

src/bdap/rpcdomainentry.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,11 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b
8282

8383
// Create BDAP operation script
8484
CScript scriptPubKey;
85-
std::string strMonths = std::to_string(nMonths);
86-
std::string strHexMonths = HexStr(strMonths.begin(), strMonths.end());
87-
std::vector<unsigned char> vchHexMonths = vchFromString(strHexMonths);
85+
std::string strMonths = std::to_string(nMonths) + "Month";
86+
std::vector<unsigned char> vchMonths = vchFromString(strMonths);
8887
std::vector<unsigned char> vchFullObjectPath = txDomainEntry.vchFullObjectPath();
8988
scriptPubKey << CScript::EncodeOP_N(OP_BDAP_NEW) << CScript::EncodeOP_N(OP_BDAP_ACCOUNT_ENTRY)
90-
<< vchFullObjectPath << txDomainEntry.DHTPublicKey << vchHexMonths << OP_2DROP << OP_2DROP << OP_DROP;
89+
<< vchFullObjectPath << txDomainEntry.DHTPublicKey << vchMonths << OP_2DROP << OP_2DROP << OP_DROP;
9190

9291
CScript scriptDestination;
9392
scriptDestination = GetScriptForDestination(walletAddress.Get());
@@ -453,12 +452,11 @@ static UniValue UpdateDomainEntry(const JSONRPCRequest& request, BDAP::ObjectTyp
453452

454453
// Create BDAP operation script
455454
CScript scriptPubKey;
456-
std::string strMonths = std::to_string(nMonths);
457-
std::string strHexMonths = HexStr(strMonths.begin(), strMonths.end());
458-
std::vector<unsigned char> vchHexMonths = vchFromString(strHexMonths);
455+
std::string strMonths = std::to_string(nMonths) + "Month";
456+
std::vector<unsigned char> vchMonths = vchFromString(strMonths);
459457
std::vector<unsigned char> vchFullObjectPath = txUpdatedEntry.vchFullObjectPath();
460458
scriptPubKey << CScript::EncodeOP_N(OP_BDAP_MODIFY) << CScript::EncodeOP_N(OP_BDAP_ACCOUNT_ENTRY)
461-
<< vchFullObjectPath << txUpdatedEntry.DHTPublicKey << vchHexMonths << OP_2DROP << OP_2DROP << OP_DROP;
459+
<< vchFullObjectPath << txUpdatedEntry.DHTPublicKey << vchMonths << OP_2DROP << OP_2DROP << OP_DROP;
462460

463461
CDynamicAddress walletAddress(stringFromVch(txUpdatedEntry.WalletAddress));
464462
CScript scriptDestination;

src/bdap/rpcrawbdap.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ UniValue createrawbdapaccount(const JSONRPCRequest& request)
5959
CharString vchCommonName = vchFromValue(request.params[1]);
6060

6161
int32_t nMonths = DEFAULT_REGISTRATION_MONTHS; // default to 1 year.
62-
std::string strMonths = std::to_string(nMonths);
63-
std::string strHexMonths = HexStr(strMonths.begin(), strMonths.end());
64-
std::vector<unsigned char> vchHexMonths = vchFromString(strHexMonths);
62+
std::string strMonths = std::to_string(nMonths) + "Month";
63+
std::vector<unsigned char> vchMonths = vchFromString(strMonths);
6564
if (request.params.size() >= 3) {
6665
if (!ParseInt32(request.params[2].get_str(), &nMonths))
6766
throw std::runtime_error("BDAP_CREATE_RAW_TX_RPC_ERROR: ERRCODE: 4500 - " + _("Error converting registration days to int"));
@@ -133,7 +132,7 @@ UniValue createrawbdapaccount(const JSONRPCRequest& request)
133132
CScript scriptPubKey;
134133
std::vector<unsigned char> vchFullObjectPath = txDomainEntry.vchFullObjectPath();
135134
scriptPubKey << CScript::EncodeOP_N(OP_BDAP_NEW) << CScript::EncodeOP_N(OP_BDAP_ACCOUNT_ENTRY)
136-
<< vchFullObjectPath << txDomainEntry.DHTPublicKey << vchHexMonths << OP_2DROP << OP_2DROP << OP_DROP;
135+
<< vchFullObjectPath << txDomainEntry.DHTPublicKey << vchMonths << OP_2DROP << OP_2DROP << OP_DROP;
137136

138137
CScript scriptDestination;
139138
scriptDestination = GetScriptForDestination(walletAddress.Get());

0 commit comments

Comments
 (0)