Skip to content

Commit eb637d3

Browse files
author
Micah Riggan
committed
Adding rpc for broadcastRawTransaction
1 parent e65689a commit eb637d3

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

lib/services/p2p/index.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var BaseService = require('../../service');
99
var assert = require('assert');
1010
var Bcoin = require('./bcoin');
1111
var BcoinTx = require('bcoin').tx;
12+
var BitcoreRPC = require('bitcoind-rpc');
1213
var Networks = require('bitcore-lib').Networks;
1314
var LRU = require('lru-cache');
1415

@@ -21,6 +22,7 @@ var P2P = function(options) {
2122
BaseService.call(this, options);
2223
this._options = options;
2324

25+
this._initRPC(options);
2426
this._initP2P();
2527
this._initPubSub();
2628
this._bcoin = null;
@@ -128,26 +130,7 @@ P2P.prototype.getPublishEvents = function() {
128130

129131

130132
P2P.prototype.sendTransaction = function(tx, callback) {
131-
var peer = this._getPeer();
132-
133-
var bcoinTx;
134-
try {
135-
bcoinTx = BcoinTx.fromRaw(tx, 'hex');
136-
} catch(e) {
137-
return callback(e);
138-
}
139-
140-
log.info('P2P Service: sending transaction: ' + bcoinTx.txid());
141-
142-
this._outgoingTxs.set(bcoinTx.txid(), bcoinTx);
143-
var inv = p2p.Inventory.forTransaction(bcoinTx.txid());
144-
var txMessage = this.messages.Inventory([inv]);
145-
146-
peer.sendMessage(txMessage);
147-
148-
this._onPeerTx(peer, { transaction: bcoinTx });
149-
150-
return callback(null, bcoinTx.txid());
133+
return this._client.sendRawTransaction(tx, callback);
151134
};
152135

153136

@@ -269,6 +252,17 @@ P2P.prototype._initCache = function() {
269252
this._inv = LRU(1000);
270253
};
271254

255+
P2P.prototype._initRPC = function (options) {
256+
this._config = options.rpc || {
257+
user: 'bitcoin',
258+
pass: 'local321',
259+
host: 'localhost',
260+
protocol: 'http',
261+
port: 8332
262+
};
263+
this._client = new BitcoreRPC(this._config);
264+
}
265+
272266
P2P.prototype._initP2P = function() {
273267
this._maxPeers = this._options.maxPeers || 60;
274268
this._minPeers = this._options.minPeers || 0;

0 commit comments

Comments
 (0)