This commit is contained in:
Chris Kleeschulte 2017-07-12 10:07:46 -04:00
parent 5e0b2b1f11
commit 9c943cc959
8 changed files with 288 additions and 1250 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,71 +0,0 @@
'use strict';
var BaseService = require('../../service');
var inherits = require('util').inherits;
var index = require('../../');
var log = index.log;
var bcoin = require('bcoin');
var BcoinService = function(options) {
BaseService.call(this, options);
this._config = options.config || this._getDefaultConfig();
};
inherits(BcoinService, BaseService);
BcoinService.dependencies = [];
BcoinService.prototype._getDefaultConfig = function() {
return {
checkpoints: true,
logLevel: 'info',
network: this.node.getNetworkName()
};
};
BcoinService.prototype.start = function(callback) {
this._startBcoin(callback);
};
BcoinService.prototype._startBcoin = function(callback) {
var self = this;
self._bcoin = bcoin.fullnode(self._config);
self._initBcoinListeners();
log.info('Starting Bcoin full node...');
self._bcoin.open().then(function() {
self._bcoin.connect().then(function() {
self._bcoin.startSync();
callback();
});
});
};
BcoinService.prototype.stop = function(callback) {
this._bcoin.stopSync();
this._bcoin.disconnect();
this._bcoin.close();
callback();
};
BcoinService.prototype._initBcoinListeners = function() {
var self = this;
self._bcoin.on('error', function(err) {
log.debug(err);
});
self._bcoin.chain.on('block', function(block) {
log.debug(block);
});
self._bcoin.mempool.on('tx', function(tx) {
log.debug(tx);
});
self._bcoin.chain.on('full', function() {
});
};
module.exports = BcoinService;

View File

@ -71,7 +71,14 @@ BlockService.prototype.stop = function(callback) {
};
BlockService.prototype.getAPIMethods = function() {
var methods = [];
var methods = [
['getBlock', this, this.getBlock, 1],
['getRawBlock', this, this.getRawBlock, 1],
['getBlockHeader', this, this.getBlockHeader, 1],
['getBlockOverview', this, this.getBlockOverview, 1],
['getBlockHashesByTimestamp', this, this.getBlockHashesByTimestamp, 2],
['getBestBlockHash', this, this.getBestBlockHash, 0]
];
return methods;
};

View File

@ -34,7 +34,8 @@ FeeService.prototype.stop = function(callback) {
FeeService.prototype.getAPIMethods = function() {
return [
['estimateFee', this, this.estimateFee, 1]
['estimateFee', this, this.estimateFee, 1],
['syncPercentage', this, this.syncPercentage, 0]
];
};

View File

@ -35,6 +35,7 @@ P2P.prototype.clearInventoryCache = function() {
P2P.prototype.getAPIMethods = function() {
var methods = [
['getInfo', this, this.getInfo, 0],
['getHeaders', this, this.getHeaders, 1],
['getMempool', this, this.getMempool, 0],
['getBlocks', this, this.getBlocks, 1],

View File

@ -18,6 +18,11 @@ inherits(TimestampService, BaseService);
TimestampService.dependencies = [ 'db', 'block' ];
TimestampService.prototype.getAPIMethods = function() {
return [
['syncPercentage', this, this.syncPercentage, 0]
];
};
TimestampService.prototype.start = function(callback) {
var self = this;

View File

@ -29,6 +29,17 @@ TransactionService.dependencies = [
'mempool'
];
TransactionService.prototype.getAPIMethods = function() {
return [
['getRawTransaction', this, this.getRawTransaction, 1],
['getTransaction', this, this.getTransaction, 1],
['getDetailedTransaction', this, this.getDetailedTransaction, 1],
['sendTransaction', this, this.sendTransaction, 1],
['getSpentInfo', this, this.getSpentInfo, 1],
['syncPercentage', this, this.syncPercentage, 0]
];
};
TransactionService.prototype.start = function(callback) {
var self = this;

View File

@ -58,15 +58,25 @@ utils.reverseBufferToString = function(buf) {
return BufferUtil.reverse(buf).toString('hex');
};
utils.getAddressStringFromScript = function(script, network) {
var address = script.toAddress(network);
utils.getAddressString = function(opts) {
if (!opts.item || !opts.item.script) {
return;
}
if (opts.tx && opts.tx.isCoinbase()) {
return;
}
var address = opts.item.script.toAddress(opts.network || 'livenet');
if(address) {
return address.toString();
}
try {
var pubkey = script.getPublicKey();
var pubkey = opts.item.script.getPublicKey();
if(pubkey) {
return pubkey.toString('hex');
}