feat(onBlockFound): add parameter to call file when a block is found

pull/173/head
James Willhoite 2 years ago
parent b40db0a562
commit e2381f8a6a

@ -49,6 +49,7 @@ void p2pool_usage()
"--no-autodiff Disable automatic difficulty adjustment for miners connected to stratum\n"
"--rpc-login Specify username[:password] required for Monero RPC server\n"
"--on-share-found Path of file to run when share is found\n"
"--on-block-found Path of file to run when block is found\n"
"--help Show this help message\n\n"
"Example command line:\n\n"
"%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum 0.0.0.0:%d --p2p 0.0.0.0:%d\n\n",

@ -391,6 +391,37 @@ void p2pool::handle_chain_main(ChainMain& data, const char* extra)
LOGINFO(0, log::LightCyan() << "You received a payout of " << log::LightGreen() << log::XMRAmount(payout) << log::LightCyan() << " in block " << log::LightGreen() << data.height);
}
api_update_block_found(&data);
if(!params().m_onBlockFound.empty())
{
std::stringstream cmd;
cmd << params().m_onBlockFound << " BLOCK " << data.id << " " << data.timestamp << " " << data.reward << " " << payout;
//Show it as a block
// cmd << " BLOCK";
//Pass the block ID
// cmd << " " << data.id;
//Timestamp
// cmd << " " << data.timestamp;
//Reward
// cmd << " " << data.reward;
//Payout
// cmd << " " << log::XMRAmount(payout);
//system() requires char and not string, convert to char
std::string ss(cmd.str());
char sys[ss.length() + 1];
strcpy(sys, ss.c_str());
//If there is an error, then log it
if(!system(sys))
{
LOGINFO(4, "ERROR Calling onBlockFound");
}
}
}
else {
side_chain().watch_mainchain_block(data, sidechain_id);

@ -140,6 +140,11 @@ Params::Params(int argc, char* argv[])
ok = true;
}
if ((strcmp(argv[i], "--on-block-found") == 0) && (i + 1 < argc)) {
m_onBlockFound = argv[++i];
ok = true;
}
if (!ok) {
fprintf(stderr, "Unknown command line parameter %s\n\n", argv[i]);
p2pool_usage();

@ -51,6 +51,7 @@ struct Params
bool m_autoDiff = true;
std::string m_rpcLogin;
std::string m_onShareFound;
std::string m_onBlockFound;
};
} // namespace p2pool

Loading…
Cancel
Save