wip
This commit is contained in:
parent
5e0b2b1f11
commit
9c943cc959
File diff suppressed because it is too large
Load Diff
@ -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;
|
|
||||||
@ -71,7 +71,14 @@ BlockService.prototype.stop = function(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
BlockService.prototype.getAPIMethods = function() {
|
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;
|
return methods;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,8 @@ FeeService.prototype.stop = function(callback) {
|
|||||||
|
|
||||||
FeeService.prototype.getAPIMethods = function() {
|
FeeService.prototype.getAPIMethods = function() {
|
||||||
return [
|
return [
|
||||||
['estimateFee', this, this.estimateFee, 1]
|
['estimateFee', this, this.estimateFee, 1],
|
||||||
|
['syncPercentage', this, this.syncPercentage, 0]
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,7 @@ P2P.prototype.clearInventoryCache = function() {
|
|||||||
|
|
||||||
P2P.prototype.getAPIMethods = function() {
|
P2P.prototype.getAPIMethods = function() {
|
||||||
var methods = [
|
var methods = [
|
||||||
|
['getInfo', this, this.getInfo, 0],
|
||||||
['getHeaders', this, this.getHeaders, 1],
|
['getHeaders', this, this.getHeaders, 1],
|
||||||
['getMempool', this, this.getMempool, 0],
|
['getMempool', this, this.getMempool, 0],
|
||||||
['getBlocks', this, this.getBlocks, 1],
|
['getBlocks', this, this.getBlocks, 1],
|
||||||
|
|||||||
@ -18,6 +18,11 @@ inherits(TimestampService, BaseService);
|
|||||||
|
|
||||||
TimestampService.dependencies = [ 'db', 'block' ];
|
TimestampService.dependencies = [ 'db', 'block' ];
|
||||||
|
|
||||||
|
TimestampService.prototype.getAPIMethods = function() {
|
||||||
|
return [
|
||||||
|
['syncPercentage', this, this.syncPercentage, 0]
|
||||||
|
];
|
||||||
|
};
|
||||||
TimestampService.prototype.start = function(callback) {
|
TimestampService.prototype.start = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,17 @@ TransactionService.dependencies = [
|
|||||||
'mempool'
|
'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) {
|
TransactionService.prototype.start = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|||||||
16
lib/utils.js
16
lib/utils.js
@ -58,15 +58,25 @@ utils.reverseBufferToString = function(buf) {
|
|||||||
return BufferUtil.reverse(buf).toString('hex');
|
return BufferUtil.reverse(buf).toString('hex');
|
||||||
};
|
};
|
||||||
|
|
||||||
utils.getAddressStringFromScript = function(script, network) {
|
utils.getAddressString = function(opts) {
|
||||||
var address = script.toAddress(network);
|
|
||||||
|
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) {
|
if(address) {
|
||||||
return address.toString();
|
return address.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var pubkey = script.getPublicKey();
|
var pubkey = opts.item.script.getPublicKey();
|
||||||
if(pubkey) {
|
if(pubkey) {
|
||||||
return pubkey.toString('hex');
|
return pubkey.toString('hex');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user