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

expand tab indent and typo fixes and add blocknotify command #187

Open
wants to merge 1 commit into
base: namecoinq
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 10 additions & 11 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ Value BlockToValue(const CBlock &block, const CBlockIndex* blockindex)

Array mrkl;
for (int i = 0; i < block.vMerkleTree.size(); i++)
mrkl.push_back(block.vMerkleTree[i].ToString().c_str());
mrkl.push_back(block.vMerkleTree[i].ToString().c_str());

obj.push_back(Pair("mrkl_tree", mrkl));

Expand All @@ -372,14 +372,13 @@ Value getblockbycount(const Array& params, bool fHelp)
CBlockIndex* pindex;
bool found = false;

for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin();
mi != mapBlockIndex.end(); ++mi)
for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
{
pindex = (*mi).second;
if ((pindex->nHeight == height) && (pindex->IsInMainChain())) {
found = true;
break;
}
pindex = (*mi).second;
if ((pindex->nHeight == height) && (pindex->IsInMainChain())) {
found = true;
break;
}
}

if (!found)
Expand Down Expand Up @@ -2379,7 +2378,7 @@ Value getauxblock(const Array& params, bool fHelp)
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();

Object result;
result.push_back(Pair("target", HexStr(BEGIN(hashTarget), END(hashTarget))));
result.push_back(Pair("target", HexStr(BEGIN(hashTarget), END(hashTarget))));
result.push_back(Pair("hash", pblock->GetHash().GetHex()));
result.push_back(Pair("chainid", pblock->GetChainID()));
return result;
Expand Down Expand Up @@ -2494,7 +2493,7 @@ Value importprivkey(const Array& params, bool fHelp)
return Value::null;
}

// Based on Codeshark's pull reqeust: https://github.com/bitcoin/bitcoin/pull/2121/files
// Based on Codeshark's pull request: https://github.com/bitcoin/bitcoin/pull/2121/files
Value importaddress(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 3)
Expand Down Expand Up @@ -2927,7 +2926,7 @@ Value listunspent(const Array& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Namecoin address: ")+input.get_str());
if (setAddress.count(address))
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+input.get_str());
setAddress.insert(address);
setAddress.insert(address);
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "cryptopp/sha.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/format.hpp>

using namespace std;
using namespace boost;
Expand Down Expand Up @@ -1517,6 +1518,23 @@ CBlock::SetBestChain (DatabaseSet& dbset, CBlockIndex* pindexNew)
currently best chain. */
cv_newBlock.notify_all ();

std::string strCmd = GetArg("-blocknotify", "");

if (!IsInitialBlockDownload() && !strCmd.empty())
{
boost::replace_all(strCmd, "%s", hashBestChain.GetHex());
unsigned int nBits = pindexBest->nBits;
auto_ptr<CBlock> pblock(new CBlock());
if (pblock.get())
{
pblock->nTime = max(pindexBest->GetMedianTimePast()+1, GetAdjustedTime());
nBits = GetNextWorkRequired(pindexBest, pblock.get());
}
boost::replace_all(strCmd, "%height", str(boost::format("%d") % (nBestHeight + 1)));
boost::replace_all(strCmd, "%bits", str(boost::format("%08x") % nBits));
boost::thread t(runCommand, strCmd); // thread runs free
}

return true;
}

Expand Down
7 changes: 7 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,3 +1131,10 @@ void SetupEnvironment()
}
#endif
}

void runCommand(std::string strCommand)
{
int nErr = ::system(strCommand.c_str());
if (nErr)
printf("runCommand error: system(%s) returned %d\n", strCommand.c_str(), nErr);
}
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ int64 GetAdjustedTime();
void AddTimeData(unsigned int ip, int64 nTime);
int64 GetTimeOffset();
std::string FormatFullVersion();
void runCommand(std::string strCommand)



Expand Down