From 5b15937d8f4d652f5cbfe1bb7a1a460e9e91cace Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 18 Nov 2014 15:51:43 -0800 Subject: [PATCH] check pindex - fix segfault. --- src/bitcoindjs.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 1b81ba79..dc911f15 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -5688,18 +5688,30 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { if (block_hash != 0) { jstx->Set(NanNew("blockhash"), NanNew(block_hash.GetHex())); - jstx->Set(NanNew("confirmations"), NanNew(0)); if (ctx.IsCoinBase()) { jstx->Set(NanNew("generated"), NanNew(true)); } - jstx->Set(NanNew("blockindex"), NanNew(mapBlockIndex[block_hash]->nHeight)); - jstx->Set(NanNew("blocktime"), NanNew(mapBlockIndex[block_hash]->GetBlockTime())); + CBlockIndex* pindex = mapBlockIndex[block_hash]; + if (pindex) { + jstx->Set(NanNew("confirmations"), + NanNew(pindex->nHeight)); + jstx->Set(NanNew("blockindex"), + NanNew(pindex->nHeight)); + jstx->Set(NanNew("blocktime"), + NanNew(pindex->GetBlockTime())); + jstx->Set(NanNew("time"), + NanNew((uint32_t)pindex->GetBlockTime())->ToUint32()); + jstx->Set(NanNew("timereceived"), + NanNew((uint32_t)pindex->GetBlockTime())->ToUint32()); + } else { + jstx->Set(NanNew("confirmations"), NanNew(0)); + jstx->Set(NanNew("blockindex"), NanNew(-1)); + jstx->Set(NanNew("blocktime"), NanNew(0)); + jstx->Set(NanNew("time"), NanNew(0)); + jstx->Set(NanNew("timereceived"), NanNew(0)); + } Local conflicts = NanNew(); jstx->Set(NanNew("walletconflicts"), conflicts); - jstx->Set(NanNew("time"), - NanNew((uint32_t)mapBlockIndex[block_hash]->GetBlockTime())->ToUint32()); - jstx->Set(NanNew("timereceived"), - NanNew((uint32_t)mapBlockIndex[block_hash]->GetBlockTime())->ToUint32()); #if 0 if (is_mine) { jstx->Set(NanNew("blockhash"), NanNew(block_hash.GetHex()));