remove old by-address methods.
This commit is contained in:
parent
8a3b0161c0
commit
f9577cdc04
@ -487,32 +487,6 @@ BlockDB.prototype.fillTX = function fillTX(tx, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
BlockDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, callback) {
|
||||
var self = this;
|
||||
var coins = [];
|
||||
|
||||
if (typeof addresses === 'string')
|
||||
addresses = [addresses];
|
||||
|
||||
addresses = utils.uniqs(addresses);
|
||||
|
||||
utils.forEach(addresses, function(address, next) {
|
||||
self._getCoinsByAddress(address, function(err, coin) {
|
||||
if (err)
|
||||
return next(err);
|
||||
|
||||
if (coin)
|
||||
coins = coins.concat(coin);
|
||||
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
return callback(null, coins);
|
||||
});
|
||||
};
|
||||
|
||||
BlockDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, options, callback) {
|
||||
var self = this;
|
||||
var coins = [];
|
||||
@ -603,114 +577,6 @@ BlockDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, opti
|
||||
});
|
||||
};
|
||||
|
||||
BlockDB.prototype._getCoinsByAddress = function _getCoinsByAddress(address, callback) {
|
||||
var self = this;
|
||||
var pending = 0;
|
||||
var coins = [];
|
||||
var done = false;
|
||||
var stream;
|
||||
|
||||
callback = utils.asyncify(callback);
|
||||
callback = utils.once(callback);
|
||||
|
||||
/*
|
||||
stream = this.index.createKeyStream({
|
||||
start: 'u/a/' + address,
|
||||
end: 'u/a/' + address + '~'
|
||||
});
|
||||
|
||||
stream.on('data', function(key) {
|
||||
var parts = key.split('/').slice(3);
|
||||
var hash = parts[0];
|
||||
var index = +parts[1];
|
||||
pending++;
|
||||
self.index.get('u/t/' + hash + '/' + index, function(err, data) {
|
||||
if (err && err.type !== 'NotFoundError')
|
||||
return callback(err);
|
||||
if (data)
|
||||
coins.push(data);
|
||||
pending--;
|
||||
if (done) {
|
||||
if (!pending)
|
||||
return callback(null, coins);
|
||||
}
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
stream = this.index.createReadStream({
|
||||
start: 'u/a/' + address,
|
||||
end: 'u/a/' + address + '~'
|
||||
});
|
||||
|
||||
stream.on('data', function(data) {
|
||||
var parts = data.key.split('/').slice(3);
|
||||
var hash = parts[0];
|
||||
var index = +parts[1];
|
||||
var id = hash + '/' + index;
|
||||
var record = self.parseOffset(data.value);
|
||||
|
||||
pending++;
|
||||
|
||||
if (self.options.cache && self.cache.unspent.has(id)) {
|
||||
coins.push(self.cache.unspent.get(id));
|
||||
pending--;
|
||||
if (done) {
|
||||
if (!pending)
|
||||
return callback(null, coins);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
self.data.getAsync(record.size, record.offset, function(err, data) {
|
||||
var coin;
|
||||
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (data) {
|
||||
try {
|
||||
data = self.parser.parseOutput(data);
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
|
||||
coin = bcoin.coin({
|
||||
version: 1,
|
||||
hash: hash,
|
||||
index: index,
|
||||
height: record.height,
|
||||
script: data.script,
|
||||
value: data.value,
|
||||
spent: false
|
||||
});
|
||||
|
||||
if (self.options.cache)
|
||||
self.cache.unspent.set(id, coin);
|
||||
|
||||
coins.push(coin);
|
||||
}
|
||||
|
||||
pending--;
|
||||
|
||||
if (done) {
|
||||
if (!pending)
|
||||
return callback(null, coins);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
stream.on('error', function(err) {
|
||||
return callback(err);
|
||||
});
|
||||
|
||||
stream.on('end', function() {
|
||||
done = true;
|
||||
if (!pending)
|
||||
return callback(null, coins);
|
||||
});
|
||||
};
|
||||
|
||||
BlockDB.prototype.getCoin = function getCoin(hash, index, callback) {
|
||||
var self = this;
|
||||
var id = 'u/t/' + hash + '/' + index;
|
||||
@ -754,32 +620,6 @@ BlockDB.prototype.getCoin = function getCoin(hash, index, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
BlockDB.prototype.getTXByAddress = function getTXByAddress(addresses, callback) {
|
||||
var self = this;
|
||||
var txs = [];
|
||||
|
||||
if (typeof addresses === 'string')
|
||||
addresses = [addresses];
|
||||
|
||||
addresses = utils.uniqs(addresses);
|
||||
|
||||
utils.forEach(addresses, function(address, next) {
|
||||
self._getTXByAddress(address, function(err, tx) {
|
||||
if (err)
|
||||
return next(err);
|
||||
|
||||
if (tx)
|
||||
txs = txs.concat(tx);
|
||||
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
return callback(null, txs);
|
||||
});
|
||||
};
|
||||
|
||||
BlockDB.prototype.getTXByAddress = function getTXByAddress(addresses, options, callback) {
|
||||
var self = this;
|
||||
var txs = [];
|
||||
@ -892,102 +732,6 @@ BlockDB.prototype.getTXByAddress = function getTXByAddress(addresses, options, c
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
BlockDB.prototype._getTXByAddress = function _getTXByAddress(address, callback) {
|
||||
var self = this;
|
||||
var pending = 0;
|
||||
var txs = [];
|
||||
var done = false;
|
||||
var stream;
|
||||
|
||||
callback = utils.asyncify(callback);
|
||||
callback = utils.once(callback);
|
||||
|
||||
stream = this.index.createReadStream({
|
||||
start: 't/a/' + address,
|
||||
end: 't/a/' + address + '~'
|
||||
});
|
||||
|
||||
stream.on('data', function(data) {
|
||||
var parts = data.key.split('/').slice(3);
|
||||
var hash = parts[0];
|
||||
var record = self.parseOffset(data.value);
|
||||
|
||||
pending++;
|
||||
|
||||
if (self.options.cache && self.cache.tx.has(hash)) {
|
||||
txs.push(self.cache.tx.get(hash));
|
||||
pending--;
|
||||
if (done) {
|
||||
if (!pending)
|
||||
return callback(null, txs);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
self.data.getAsync(record.size, record.offset, function(err, data) {
|
||||
var tx;
|
||||
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (data) {
|
||||
try {
|
||||
tx = self.parser.parseTX(data);
|
||||
tx = new bcoin.tx(tx);
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
|
||||
return self._getEntry(record.height, function(err, entry) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
tx.network = true;
|
||||
tx.height = record.height;
|
||||
|
||||
if (entry) {
|
||||
tx.ts = entry.ts;
|
||||
tx.block = entry.hash;
|
||||
}
|
||||
|
||||
txs.push(tx);
|
||||
|
||||
if (self.options.cache)
|
||||
self.cache.tx.set(hash, tx);
|
||||
|
||||
if (self.options.paranoid && tx.hash('hex') !== hash)
|
||||
return callback(new Error('BlockDB is corrupt. All is lost.'));
|
||||
|
||||
pending--;
|
||||
|
||||
if (done) {
|
||||
if (!pending)
|
||||
return callback(null, txs);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pending--;
|
||||
|
||||
if (done) {
|
||||
if (!pending)
|
||||
return callback(null, txs);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
stream.on('error', function(err) {
|
||||
return callback(err);
|
||||
});
|
||||
|
||||
stream.on('end', function() {
|
||||
done = true;
|
||||
if (!pending)
|
||||
return callback(null, txs);
|
||||
});
|
||||
};
|
||||
|
||||
BlockDB.prototype.getTX = function getTX(hash, callback) {
|
||||
var self = this;
|
||||
var id = 't/t/' + hash;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user