small fixes to mempool.
This commit is contained in:
parent
c73d5bde2e
commit
9a9f43bc7f
@ -1,8 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var BaseService = require('../Service');
|
var BaseService = require('../service');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var bitcore = require('bitcore-lib');
|
var bitcore = require('bitcore-lib');
|
||||||
|
var Encoding = require('../encoding');
|
||||||
|
var index = require('../index');
|
||||||
|
var log = index.log;
|
||||||
|
var async = require('async');
|
||||||
var MempoolService = function(options) {
|
var MempoolService = function(options) {
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
|
|
||||||
@ -10,7 +14,7 @@ var MempoolService = function(options) {
|
|||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
this._txIndex = {};
|
this._txIndex = {};
|
||||||
this._addressIndex = {};
|
this._addressIndex = {};
|
||||||
this.store = this.nodes.services.db.store;
|
this.store = this.node.services.db.store;
|
||||||
this._handleBlocks = false;
|
this._handleBlocks = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -35,7 +39,6 @@ MempoolService.prototype.blockHandler = function(block, connectBlock, callback)
|
|||||||
action = 'put';
|
action = 'put';
|
||||||
}
|
}
|
||||||
|
|
||||||
var transactionLength = txs.length;
|
|
||||||
for(var i = 0; i < txs.length; i++) {
|
for(var i = 0; i < txs.length; i++) {
|
||||||
|
|
||||||
var tx = txs[i];
|
var tx = txs[i];
|
||||||
@ -95,6 +98,10 @@ MempoolService.prototype.getRoutePrefix = function() {
|
|||||||
|
|
||||||
MempoolService.prototype._getTransactionAddressDetailOperations = function(tx, action) {
|
MempoolService.prototype._getTransactionAddressDetailOperations = function(tx, action) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
if(tx.isCoinbase()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
var operations = [];
|
var operations = [];
|
||||||
|
|
||||||
var txid = tx.id;
|
var txid = tx.id;
|
||||||
@ -112,7 +119,7 @@ MempoolService.prototype._getTransactionAddressDetailOperations = function(tx, a
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var address = self..getAddressString(script);
|
var address = self.getAddressString(script);
|
||||||
|
|
||||||
if(!address) {
|
if(!address) {
|
||||||
continue;
|
continue;
|
||||||
@ -126,22 +133,19 @@ MempoolService.prototype._getTransactionAddressDetailOperations = function(tx, a
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tx.isCoinbase()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO deal with P2PK
|
//TODO deal with P2PK
|
||||||
async.eachLimit(inputs, 10, function(input, next) {
|
for(var i = 0; i < inputs.length; i++) {
|
||||||
|
var input = inputs[i];
|
||||||
if(!input.script) {
|
if(!input.script) {
|
||||||
log.debug('Invalid script');
|
log.debug('Invalid script');
|
||||||
return next();
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var inputAddress = self.getAddressString(input.script);
|
var inputAddress = self.getAddressString(input.script);
|
||||||
|
|
||||||
if(!inputAddress) {
|
if(!inputAddress) {
|
||||||
return next();
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var inputKey = self.encodeMempoolAddressIndexKey(inputAddress, txid);
|
var inputKey = self.encodeMempoolAddressIndexKey(inputAddress, txid);
|
||||||
@ -150,7 +154,6 @@ MempoolService.prototype._getTransactionAddressDetailOperations = function(tx, a
|
|||||||
type: action,
|
type: action,
|
||||||
key: inputKey
|
key: inputKey
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
return operations;
|
return operations;
|
||||||
};
|
};
|
||||||
@ -289,6 +292,7 @@ MempoolService.prototype.getTransactionsByAddress = function(address, callback)
|
|||||||
};
|
};
|
||||||
|
|
||||||
MempoolService.prototype.getTransactionsByAddresses = function(addresses, callback) {
|
MempoolService.prototype.getTransactionsByAddresses = function(addresses, callback) {
|
||||||
|
var self = this;
|
||||||
var transactions = {};
|
var transactions = {};
|
||||||
async.eachLimit(addresses, 10, function(address, next) {
|
async.eachLimit(addresses, 10, function(address, next) {
|
||||||
self.getTransactionsByAddress(address, function(err, txs) {
|
self.getTransactionsByAddress(address, function(err, txs) {
|
||||||
|
|||||||
@ -75,7 +75,6 @@ TransactionService.prototype.blockHandler = function(block, connectBlock, callba
|
|||||||
});
|
});
|
||||||
}, function(next) {
|
}, function(next) {
|
||||||
async.eachSeries(block.transactions, function(tx, next) {
|
async.eachSeries(block.transactions, function(tx, next) {
|
||||||
self._updateMempool(tx, reverseAction);
|
|
||||||
tx.__timestamp = block.__timestamp;
|
tx.__timestamp = block.__timestamp;
|
||||||
tx.__height = block.__height;
|
tx.__height = block.__height;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user