dont bother with timestamp on caching.
This commit is contained in:
parent
09ed50b7ad
commit
04036146cb
@ -432,66 +432,43 @@ Bitcoin.prototype.getAddrTransactions = function(address, callback) {
|
|||||||
}
|
}
|
||||||
return bitcoin.db.get(address, function(err, records) {
|
return bitcoin.db.get(address, function(err, records) {
|
||||||
var found = !err && records && records.length;
|
var found = !err && records && records.length;
|
||||||
var last = found && records[records.length - 1];
|
var options = {
|
||||||
var limit = 15 * 60 * 1000;
|
address: address,
|
||||||
if (!found || last.timestamp + limit < Date.now()) {
|
blockindex: (records || []).reduce(function(out, record) {
|
||||||
var options = {
|
return record.blockindex > out
|
||||||
address: address,
|
? record.blockindex
|
||||||
blockindex: (records || []).reduce(function(out, record) {
|
: out;
|
||||||
return record.blockindex > out
|
}, -1)
|
||||||
? record.blockindex
|
};
|
||||||
: out;
|
return bitcoindjs.getAddrTransactions(options, function(err, addr) {
|
||||||
}, -1)
|
if (err) return callback(err);
|
||||||
};
|
addr = bitcoin.addr(addr);
|
||||||
return bitcoindjs.getAddrTransactions(options, function(err, addr) {
|
if (addr.tx[0] && !addr.tx[0].vout[0]) {
|
||||||
if (err) return callback(err);
|
return bitcoin.db.set(address, [{
|
||||||
addr = bitcoin.addr(addr);
|
txid: null,
|
||||||
if (addr.tx[0] && !addr.tx[0].vout[0]) {
|
blockhash: null,
|
||||||
return bitcoin.db.set(address, [{
|
blockindex: null
|
||||||
txid: null,
|
}], function() {
|
||||||
blockhash: null,
|
return callback(null, bitcoin.addr({
|
||||||
blockindex: null,
|
address: addr.address,
|
||||||
timestamp: Date.now()
|
tx: []
|
||||||
}], function() {
|
}));
|
||||||
return callback(null, bitcoin.addr({
|
|
||||||
address: addr.address,
|
|
||||||
tx: []
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
var set = [];
|
|
||||||
if (records && records.length) {
|
|
||||||
set = records;
|
|
||||||
}
|
|
||||||
addr.tx.forEach(function(tx) {
|
|
||||||
set.push({
|
|
||||||
txid: tx.txid,
|
|
||||||
blockhash: tx.blockhash,
|
|
||||||
blockindex: tx.blockindex,
|
|
||||||
timestamp: Date.now()
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return bitcoin.db.set(address, set, function() {
|
}
|
||||||
return callback(null, addr);
|
var set = [];
|
||||||
|
if (records && records.length) {
|
||||||
|
set = records;
|
||||||
|
}
|
||||||
|
addr.tx.forEach(function(tx) {
|
||||||
|
set.push({
|
||||||
|
txid: tx.txid,
|
||||||
|
blockhash: tx.blockhash,
|
||||||
|
blockindex: tx.blockindex
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
return bitcoin.db.set(address, set, function() {
|
||||||
var txs = [];
|
return callback(null, addr);
|
||||||
return utils.forEach(records, function(record, next) {
|
|
||||||
var block = record.blockhash;
|
|
||||||
var txid = record.txid;
|
|
||||||
var index = record.blockindex;
|
|
||||||
if (txid == null) return next();
|
|
||||||
return bitcoin.getTransaction(txid, block, function(err, tx) {
|
|
||||||
if (err) return next();
|
|
||||||
txs.push(tx);
|
|
||||||
return next();
|
|
||||||
});
|
});
|
||||||
}, function() {
|
|
||||||
return callback(null, bitcoin.addr({
|
|
||||||
address: address,
|
|
||||||
tx: txs
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user