@@ -9,6 +9,7 @@ var BaseService = require('../../service');
9
9
var assert = require ( 'assert' ) ;
10
10
var Bcoin = require ( './bcoin' ) ;
11
11
var BcoinTx = require ( 'bcoin' ) . tx ;
12
+ var BitcoreRPC = require ( 'bitcoind-rpc' ) ;
12
13
var Networks = require ( 'bitcore-lib' ) . Networks ;
13
14
var LRU = require ( 'lru-cache' ) ;
14
15
@@ -21,6 +22,7 @@ var P2P = function(options) {
21
22
BaseService . call ( this , options ) ;
22
23
this . _options = options ;
23
24
25
+ this . _initRPC ( options ) ;
24
26
this . _initP2P ( ) ;
25
27
this . _initPubSub ( ) ;
26
28
this . _bcoin = null ;
@@ -128,26 +130,7 @@ P2P.prototype.getPublishEvents = function() {
128
130
129
131
130
132
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 ) ;
151
134
} ;
152
135
153
136
@@ -269,6 +252,17 @@ P2P.prototype._initCache = function() {
269
252
this . _inv = LRU ( 1000 ) ;
270
253
} ;
271
254
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
+
272
266
P2P . prototype . _initP2P = function ( ) {
273
267
this . _maxPeers = this . _options . maxPeers || 60 ;
274
268
this . _minPeers = this . _options . minPeers || 0 ;
0 commit comments