Skip to content

Commit

Permalink
Update omni_getseedblocks following @dexX7's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
zathras-crypto committed Jan 4, 2016
1 parent 4b472fd commit 55fa47a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/omnicore/omnicore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2903,7 +2903,7 @@ std::set<int> CMPTxList::GetSeedBlocks(int startHeight, int endHeight)
for (it->SeekToFirst(); it->Valid(); it->Next()) {
std::string itData = it->value().ToString();
std::vector<std::string> vstr;
boost::split(vstr, itData, boost::is_any_of(":"), token_compress_on);
boost::split(vstr, itData, boost::is_any_of(":"), boost::token_compress_on);
if (4 != vstr.size()) continue; // unexpected number of tokens
int block = atoi(vstr[1]);
if (block >= startHeight && block <= endHeight) {
Expand Down
31 changes: 7 additions & 24 deletions src/omnicore/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,14 @@ bool BalanceToJSON(const std::string& address, uint32_t property, Object& balanc
// generate a list of seed blocks based on the data in LevelDB
Value omni_getseedblocks(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 2 || params.size() > 3)
if (fHelp || params.size() != 2)
throw runtime_error(
"omni_getseedblocks startblock endblock\n"
"\nReturns a list of blocks containing Omni transactions for use in seed block filtering.\n"
"\nWARNING: The Exodus crowdsale is not stored in LevelDB, thus this is currently only safe to use to generate seed blocks after block 255365"
"\nArguments:\n"
"1. startblock (number, required) the first block to look for Omni transactions (inclusive)\n"
"2. endblock (number, required) the last block to look for Omni transactions (inclusive)\n"
"3. stringify (bool, optional) whether to output one continuous string of seed blocks for easier inclusion in seedblocks.cpp\n"
"\nResult:\n"
"[ (array of JSON objects)\n"
" {\n"
Expand All @@ -170,37 +169,21 @@ Value omni_getseedblocks(const Array& params, bool fHelp)

int startHeight = params[0].get_int();
int endHeight = params[1].get_int();
bool overrideOutput = false;
if (params.size() > 2) overrideOutput = params[2].get_bool();

RequireHeightInChain(startHeight);
RequireHeightInChain(endHeight);

std::set<int> setSeedBlocks = p_txlistdb->GetSeedBlocks(startHeight, endHeight);

Array response;
std::string stringifiedOutput;

for (std::set<int>::const_iterator it = setSeedBlocks.begin(); it != setSeedBlocks.end(); ++it) {
if (!overrideOutput) {
Object seedBlockObj;
seedBlockObj.push_back(Pair("seedblock", *it));
response.push_back(seedBlockObj);
} else {
stringifiedOutput += strprintf("%d, ", *it);
{
LOCK(cs_tally);
std::set<int> setSeedBlocks = p_txlistdb->GetSeedBlocks(startHeight, endHeight);
for (std::set<int>::const_iterator it = setSeedBlocks.begin(); it != setSeedBlocks.end(); ++it) {
response.push_back(*it);
}
}

if (!overrideOutput) {
return response;
} else {
Object stringifiedResponse;
if (stringifiedOutput.size()>2) { // remove trailing ", "
stringifiedOutput.erase(stringifiedOutput.size()-2);
}
stringifiedResponse.push_back(Pair("seedblocks", stringifiedOutput));
return stringifiedResponse;
}
return response;
}

// obtain the payload for a transaction
Expand Down

0 comments on commit 55fa47a

Please sign in to comment.