diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 08cd27d8..74d3d045 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -3585,10 +3585,34 @@ NAN_METHOD(HookPackets) { o->Set(NanNew("peerId"), NanNew(pfrom->id)); o->Set(NanNew("fromHeight"), NanNew(pindex ? pindex->nHeight : -1); - o->Set(NanNew("toHash"), NanNew(hashStop == uint256(0) ? "end" : hashStop.ToString())); + o->Set(NanNew("toHash"), NanNew( + hashStop == uint256(0) ? "end" : hashStop.GetHex().c_str())); o->Set(NanNew("limit"), NanNew(nLimit)); } else if (strCommand == "getheaders") { - ; + CBlockLocator locator; + uint256 hashStop; + cur->vRecv >> locator >> hashStop; + + LOCK(cs_main); + + CBlockIndex* pindex = NULL; + if (locator.IsNull()) { + // If locator is null, return the hashStop block + BlockMap::iterator mi = mapBlockIndex.find(hashStop); + if (mi == mapBlockIndex.end()) { + return true; + } + pindex = (*mi).second; + } else { + // Find the last block the caller has in the main chain + pindex = FindForkInGlobalIndex(chainActive, locator); + if (pindex) { + pindex = chainActive.Next(pindex); + } + } + + o->Set(NanNew("fromHeight"), pindex ? pindex->nHeight : -1); + o->Set(NanNew("toHash"), NanNew(hashStop.GetHex().c_str())); } else if (strCommand == "tx") { ; // } else if (strCommand == "block" && !fImporting && !fReindex) {