Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability to generate seed blocks over RPC #325

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/omnicore/omnicore.cpp
Expand Up @@ -2892,6 +2892,30 @@ int mastercore::ClassAgnosticWalletTXBuilder(const std::string& senderAddress, c
#endif
}

std::set<int> CMPTxList::GetSeedBlocks(int startHeight, int endHeight)
{
std::set<int> setSeedBlocks;

if (!pdb) return setSeedBlocks;

Iterator* it = NewIterator();

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be boost::token_compress_on.

if (4 != vstr.size()) continue; // unexpected number of tokens
int block = atoi(vstr[1]);
if (block >= startHeight && block <= endHeight) {
setSeedBlocks.insert(block);
}
}

delete it;

return setSeedBlocks;
}

void CMPTxList::LoadActivations(int blockHeight)
{
if (!pdb) return;
Expand Down
1 change: 1 addition & 0 deletions src/omnicore/omnicore.h
Expand Up @@ -244,6 +244,7 @@ class CMPTxList : public CDBBase
bool exists(const uint256 &txid);
bool getTX(const uint256 &txid, string &value);

std::set<int> GetSeedBlocks(int startHeight, int endHeight);
void LoadAlerts(int blockHeight);
void LoadActivations(int blockHeight);

Expand Down
59 changes: 59 additions & 0 deletions src/omnicore/rpc.cpp
Expand Up @@ -144,6 +144,65 @@ 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)
throw runtime_error(
"omni_getseedblocks startblock endblock\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be: omni_getseedblocks startblock endblock ( stringify )

"\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"
" \"seedblock\" : blockheight, (number) the blockheight of the seed block\n"
" },\n"
" ...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("omni_getseedblocks", "290000 300000")
+ HelpExampleRpc("omni_getseedblocks", "290000, 300000")
);

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p_txlistdb->GetSeedBlocks() should be surrounded with LOCK(cs_tally);.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do it here, or in the function itself (GetSeedBlocks)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it here, to guard the pointer p_txlistdb too. Not sure, if this is the best way, but it's similar to other places and it might come handy in case of a shutdown (where the pointer is cleared).


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);
}
}

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;
}
}

// obtain the payload for a transaction
Value omni_getpayload(const Array& params, bool fHelp)
{
Expand Down
3 changes: 3 additions & 0 deletions src/rpcclient.cpp
Expand Up @@ -129,6 +129,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "omni_listblocktransactions", 0 },
{ "omni_getorderbook", 0 },
{ "omni_getorderbook", 1 },
{ "omni_getseedblocks", 0 },
{ "omni_getseedblocks", 1 },
{ "omni_getseedblocks", 2 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is no longer needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks dude, just testing without these and then will push the change :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, think I misread your comment - thought you meant all three weren't required (which I wanted to test because I didn't think it would work).

Now rereading I realize you meant just the last line hehe - all sorted.


/* Omni Core - transaction calls */
{ "omni_send", 2 },
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.cpp
Expand Up @@ -378,6 +378,7 @@ static const CRPCCommand vRPCCommands[] =
{ "omni layer (data retrieval)", "omni_gettradehistoryforpair", &omni_gettradehistoryforpair, false, true, false },
{ "omni layer (data retrieval)", "omni_getcurrentconsensushash", &omni_getcurrentconsensushash, false, true, false },
{ "omni layer (data retrieval)", "omni_getpayload", &omni_getpayload, false, true, false },
{ "omni layer (data retrieval)", "omni_getseedblocks", &omni_getseedblocks, false, true, false },
#ifdef ENABLE_WALLET
{ "omni layer (data retrieval)", "omni_listtransactions", &omni_listtransactions, false, true, true },

Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Expand Up @@ -249,6 +249,7 @@ extern json_spirit::Value omni_gettradehistoryforaddress(const json_spirit::Arra
extern json_spirit::Value omni_gettradehistoryforpair(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value omni_getcurrentconsensushash(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value omni_getpayload(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value omni_getseedblocks(const json_spirit::Array& params, bool fHelp);

/* Omni Core configuration calls */
extern json_spirit::Value omni_setautocommit(const json_spirit::Array& params, bool fHelp);
Expand Down