Merge branch 'feature/rpc-broadcast-transaction'
This commit is contained in:
commit
8e9ecff905
@ -9,6 +9,7 @@ var BaseService = require('../../service');
|
||||
var assert = require('assert');
|
||||
var Bcoin = require('./bcoin');
|
||||
var BcoinTx = require('bcoin').tx;
|
||||
var BitcoreRPC = require('bitcoind-rpc');
|
||||
var Networks = require('bitcore-lib').Networks;
|
||||
var LRU = require('lru-cache');
|
||||
|
||||
@ -21,6 +22,7 @@ var P2P = function(options) {
|
||||
BaseService.call(this, options);
|
||||
this._options = options;
|
||||
|
||||
this._initRPC(options);
|
||||
this._initP2P();
|
||||
this._initPubSub();
|
||||
this._bcoin = null;
|
||||
@ -128,26 +130,7 @@ P2P.prototype.getPublishEvents = function() {
|
||||
|
||||
|
||||
P2P.prototype.sendTransaction = function(tx, callback) {
|
||||
var peer = this._getPeer();
|
||||
|
||||
var bcoinTx;
|
||||
try {
|
||||
bcoinTx = BcoinTx.fromRaw(tx, 'hex');
|
||||
} catch(e) {
|
||||
return callback(e);
|
||||
}
|
||||
|
||||
log.info('P2P Service: sending transaction: ' + bcoinTx.txid());
|
||||
|
||||
this._outgoingTxs.set(bcoinTx.txid(), bcoinTx);
|
||||
var inv = p2p.Inventory.forTransaction(bcoinTx.txid());
|
||||
var txMessage = this.messages.Inventory([inv]);
|
||||
|
||||
peer.sendMessage(txMessage);
|
||||
|
||||
this._onPeerTx(peer, { transaction: bcoinTx });
|
||||
|
||||
return callback(null, bcoinTx.txid());
|
||||
return this._client.sendRawTransaction(tx, callback);
|
||||
};
|
||||
|
||||
|
||||
@ -269,6 +252,17 @@ P2P.prototype._initCache = function() {
|
||||
this._inv = LRU(1000);
|
||||
};
|
||||
|
||||
P2P.prototype._initRPC = function (options) {
|
||||
this._config = options.rpc || {
|
||||
user: 'bitcoin',
|
||||
pass: 'local321',
|
||||
host: 'localhost',
|
||||
protocol: 'http',
|
||||
port: 8332
|
||||
};
|
||||
this._client = new BitcoreRPC(this._config);
|
||||
}
|
||||
|
||||
P2P.prototype._initP2P = function() {
|
||||
this._maxPeers = this._options.maxPeers || 60;
|
||||
this._minPeers = this._options.minPeers || 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user