Skip to content
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

Peer's tx event isn't emitted #84

Open
luisflma opened this issue Nov 27, 2015 · 3 comments
Open

Peer's tx event isn't emitted #84

luisflma opened this issue Nov 27, 2015 · 3 comments

Comments

@luisflma
Copy link

Hi,
I can't get transaction's information. In this code, the tx event is never emitted. Connected, ready and inv events are emitted but not tx.

var bitcore = require('bitcore-p2p');
var Peer = bitcore.Peer;

var peer = new Peer({host: '127.0.0.1', port: 8333});

peer.on('disconnect', function () {
  console.log('connection closed');
});

peer.on('connect', function () {
    console.log('connected');
});

peer.on('inv', function (msg) {
  console.log('inv');
});

peer.on('ready', function() {
  console.log('ready');
});

peer.on('tx', function(message) {
  // message.transaction 
  console.log(message);
});

peer.connect();

In this file:
https://github.com/bitpay/bitcore-p2p/blob/master/lib/peer.js#L218
I have edited the _readMessage function to debug it:

Peer.prototype._readMessage = function() {
  var message = this.messages.parseBuffer(this.dataBuffer);
  if(message == undefined) console.log(message);
  else console.log(message.command);
  if (message) {
    this.emit(message.command, message);
    this._readMessage();
  }
};

output:

inv
undefined
inv
undefined
inv
undefined
@luisflma luisflma changed the title Peer's tx event isn't called Peer's tx event isn't emitted Nov 27, 2015
@stefanhuber
Copy link

the tx message is only sent by the peer, if a getdata request is made. See the bitcoin wiki: https://en.bitcoin.it/wiki/Protocol_documentation#inv

so after you received the inv message, you need to create an getdata response and only then you'll get the tx or block messages...

@braydonf
Copy link
Contributor

braydonf commented Dec 1, 2015

Related: #82

@luisflma
Copy link
Author

luisflma commented Dec 2, 2015

Thank you for your answer, I'll try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants