chaindb: fix getCoin.

This commit is contained in:
Christopher Jeffrey 2017-07-03 17:39:06 -07:00
parent aa71ae690a
commit 82bdd73f05
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

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