From 82bdd73f05c46bdcabbce2c4303f2fbb5e6c516d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 3 Jul 2017 17:39:06 -0700 Subject: [PATCH] chaindb: fix getCoin. --- lib/blockchain/chaindb.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/blockchain/chaindb.js b/lib/blockchain/chaindb.js index 59b6691e..8b5828b7 100644 --- a/lib/blockchain/chaindb.js +++ b/lib/blockchain/chaindb.js @@ -844,15 +844,14 @@ ChainDB.prototype.getTips = function getTips() { * Get a coin (unspents only). * @method * @private - * @param {Outpoint} outpoint + * @param {Outpoint} prevout * @returns {Promise} - Returns {@link CoinEntry}. */ -ChainDB.prototype.readCoin = async function readCoin(outpoint) { +ChainDB.prototype.readCoin = async function readCoin(prevout) { + let {hash, index} = prevout; + let key = prevout.toKey(); let state = this.state; - let key = outpoint.toKey(); - let hash = outpoint.hash; - let index = outpoint.index; let raw; if (this.options.spv) @@ -885,6 +884,10 @@ ChainDB.prototype.readCoin = async function readCoin(outpoint) { ChainDB.prototype.getCoin = async function getCoin(hash, index) { let prevout = new Outpoint(hash, index); let coin = await this.readCoin(prevout); + + if (!coin) + return; + return coin.toCoin(prevout); };