Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions src/rpc/budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,32 @@ void budgetToJSON(CBudgetProposal* pbudgetProposal, UniValue& bObj)
void checkBudgetInputs(const UniValue& params, std::string &strProposalName, std::string &strURL,
int &nPaymentCount, int &nBlockStart, CBitcoinAddress &address, CAmount &nAmount)
{
int nBlockMin = 0;
CBlockIndex* pindexPrev = chainActive.Tip();

strProposalName = SanitizeString(params[0].get_str());
if (strProposalName.size() > 20)
throw std::runtime_error("Invalid proposal name, limit of 20 characters.");
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid proposal name, limit of 20 characters.");

strURL = SanitizeString(params[1].get_str());
if (strURL.size() > 64)
throw std::runtime_error("Invalid url, limit of 64 characters.");
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid url, limit of 64 characters.");

nPaymentCount = params[2].get_int();
if (nPaymentCount < 1)
throw std::runtime_error("Invalid payment count, must be more than zero.");

// Start must be in the next budget cycle
if (pindexPrev != NULL) nBlockMin = pindexPrev->nHeight - pindexPrev->nHeight % Params().GetBudgetCycleBlocks() + Params().GetBudgetCycleBlocks();
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid payment count, must be more than zero.");

nBlockStart = params[3].get_int();
if (nBlockStart % Params().GetBudgetCycleBlocks() != 0) {
int nNext = pindexPrev->nHeight - pindexPrev->nHeight % Params().GetBudgetCycleBlocks() + Params().GetBudgetCycleBlocks();
throw std::runtime_error(strprintf("Invalid block start - must be a budget cycle block. Next valid block: %d", nNext));
}
CBlockIndex* pindexPrev = chainActive.Tip();
if (!pindexPrev)
throw JSONRPCError(RPC_IN_WARMUP, "Try again after active chain is loaded");

int nBlockEnd = nBlockStart + (Params().GetBudgetCycleBlocks() * nPaymentCount); // End must be AFTER current cycle
// Start must be in the next budget cycle or later
const int budgetCycleBlocks = Params().GetBudgetCycleBlocks();
int pHeight = pindexPrev->nHeight;

if (nBlockStart < nBlockMin)
throw std::runtime_error("Invalid block start, must be more than current height.");
int nBlockMin = pHeight - (pHeight % budgetCycleBlocks) + budgetCycleBlocks;

if (nBlockEnd < pindexPrev->nHeight)
throw std::runtime_error("Invalid ending block, starting block + (payment_cycle*payments) must be more than current height.");
nBlockStart = params[3].get_int();
if ((nBlockStart < nBlockMin) || ((nBlockStart % budgetCycleBlocks) != 0)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid block start - must be a budget cycle block. Next valid block: %d", nBlockMin));
}

address = params[4].get_str();
if (!address.IsValid())
Expand Down Expand Up @@ -112,6 +107,10 @@ UniValue preparebudget(const UniValue& params, bool fHelp)
HelpExampleCli("preparebudget", "\"test-proposal\" \"https://forum.pivx.org/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500") +
HelpExampleRpc("preparebudget", "\"test-proposal\" \"https://forum.pivx.org/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500"));

if (!pwalletMain) {
throw JSONRPCError(RPC_IN_WARMUP, "Try again after active chain is loaded");
}

LOCK2(cs_main, pwalletMain->cs_wallet);

EnsureWalletIsUnlocked();
Expand Down