Merge pull request #235 from braydonf/bug/nullprevhash
GetBlockIndex segmentation fault with genesis block
This commit is contained in:
commit
a0d164661a
|
@ -231,6 +231,11 @@ describe('Daemon Binding Functionality', function() {
|
|||
blockIndex.height.should.equal(i + 1);
|
||||
});
|
||||
});
|
||||
it('will get null prevHash for the genesis block', function() {
|
||||
var blockIndex = bitcoind.getBlockIndex(0);
|
||||
should.exist(blockIndex);
|
||||
should.equal(blockIndex.prevHash, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get block index by height', function() {
|
||||
|
|
|
@ -1337,14 +1337,20 @@ NAN_METHOD(GetBlockIndex) {
|
|||
}
|
||||
}
|
||||
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
|
||||
arith_uint256 cw = blockIndex->nChainWork;
|
||||
CBlockIndex* prevBlockIndex = blockIndex->pprev;
|
||||
if (&prevBlockIndex->phashBlock != 0) {
|
||||
const uint256* prevHash = prevBlockIndex->phashBlock;
|
||||
obj->Set(NanNew<String>("prevHash"), NanNew<String>(prevHash->GetHex()));
|
||||
} else {
|
||||
obj->Set(NanNew<String>("prevHash"), NanNull());
|
||||
}
|
||||
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
obj->Set(NanNew<String>("hash"), NanNew<String>(blockIndex->phashBlock->GetHex()));
|
||||
obj->Set(NanNew<String>("chainWork"), NanNew<String>(cw.GetHex()));
|
||||
obj->Set(NanNew<String>("prevHash"), NanNew<String>(prevHash->GetHex()));
|
||||
|
||||
obj->Set(NanNew<String>("height"), NanNew<Number>(blockIndex->nHeight));
|
||||
|
||||
NanReturnValue(obj);
|
||||
|
|
Loading…
Reference in New Issue