So I have a getBlockByHeight method which is as follows.
getBlockByHeight(height) {
let self = this;
return new Promise((resolve, reject) => {
try{
let block = self.chain.filter(p => p.height === height)[0];
if(block){
resolve(block);
} else {
resolve(null);
}
} catch (err) {
reject(new Error(err));
}
});
}
I then want to validate my blocks in another method and am trying to do the following.
let previousBlock = self.getBlockByHeight(block.height -1);
That line returns a promise with my block object in it correctly. If I console.log previousBlock it prints as follows.
Promise {
Block {
hash: '5535a9bf09a3667a533df8f8a90a6ae8e8dfe1ca9f3d5305df5a1d593d2afcf6',
height: 1,
body: 'longHexString',
time: '1633881202',
previousBlockHash: '1f018de4cb50fe2fc57b43c1a4972fde53d7e4ab9ca5809784d49e5a57497312'
}
}
My question is how do I access the hash in this previousBlock object. if I try
let preBlockHash = previousBlock.hash
I get undefined. I'm not really sure why this is happening so any help would be appreciated thanks.