Skip to content

Adding rpc for broadcastRawTransaction #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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