本文整理汇总了C++中CAlert::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ CAlert::ToString方法的具体用法?C++ CAlert::ToString怎么用?C++ CAlert::ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAlert
的用法示例。
在下文中一共展示了CAlert::ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SignAndSave
//
// Sign a CAlert and serialize it
//
bool SignAndSave(CAlert &alert)
{
// Sign
if(!alert.Sign())
{
printf("SignAndSave() : could not sign alert:\n%s", alert.ToString().c_str());
return false;
}
std::string strFilePath = "src/test/data/alertTests.raw";
// open output file and associate it with CAutoFile
FILE *file = fopen(strFilePath.c_str(), "ab+");
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
if (fileout.IsNull())
return error("%s: Failed to open file %s", __func__, strFilePath);
try {
fileout << alert;
}
catch (std::exception &e) {
return error("%s: Serialize or I/O error - %s", __func__, e.what());
}
fileout.fclose();
return true;
}
示例2: sendalert2
UniValue sendalert2(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 7)
throw runtime_error(
// 0 1 2 3 4 5 6
"sendalert2 <privatekey> <id> <subverlist> <cancellist> <expire> <priority> <message>\n"
"\n"
"<privatekey> -> is hex string of alert master private key\n"
"<id> ---------> is the unique alert number\n"
"<subverlist> -> comma separated list of versions warning applies to\n"
"<cancellist> -> comma separated ids of alerts to cancel\n"
"<expire> -----> alert expiration in days\n"
"<priority> ---> integer, >1000->visible\n"
"<message> ---->is the alert text message\n"
"\n"
"Returns summary of what was done.");
CAlert alert;
CKey key;
alert.strStatusBar = params[6].get_str();
alert.nMinVer = PROTOCOL_VERSION;
alert.nMaxVer = PROTOCOL_VERSION;
alert.nPriority = params[5].get_int();
alert.nID = params[1].get_int();
alert.nVersion = PROTOCOL_VERSION;
alert.nRelayUntil = alert.nExpiration = GetAdjustedTime() + 24*60*60*params[4].get_int();
if(params[2].get_str().length())
{
std::vector<std::string> split_subver = split(params[2].get_str(), ",");
alert.setSubVer.insert(split_subver.begin(),split_subver.end());
}
if(params[3].get_str().length())
{
for(std::string &s : split(params[3].get_str(), ","))
{
int aver = RoundFromString(s, 0);
alert.setCancel.insert(aver);
}
}
CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION);
sMsg << (CUnsignedAlert)alert;
alert.vchMsg = vector<unsigned char>(sMsg.begin(), sMsg.end());
vector<unsigned char> vchPrivKey = ParseHex(params[0].get_str());
key.SetPrivKey(CPrivKey(vchPrivKey.begin(), vchPrivKey.end())); // if key is not correct openssl may crash
if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig))
throw runtime_error(
"Unable to sign alert, check private key?\n");
if(!alert.ProcessAlert())
throw runtime_error(
"Failed to process alert.\n");
// Relay alert
{
LOCK(cs_vNodes);
for (auto const& pnode : vNodes)
alert.RelayTo(pnode);
}
UniValue result(UniValue::VOBJ);
result.pushKV("Content", alert.ToString());
result.pushKV("Success", true);
return result;
}