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); };