Skip to content

Commit

Permalink
Adding rpc for broadcastRawTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Micah Riggan committed May 10, 2018
1 parent e65689a commit eb637d3
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions lib/services/p2p/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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;
Expand Down Expand Up @@ -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);
};


Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eb637d3

Please sign in to comment.