Get error block-message through litecoin-p2p


#1

Hi all,
I try to use litecoin-p2p to get the latest transaction or block. The problem is that I can’t get transactions in the block message. however, The transaction message is corrent.
How can I get the correct block message?
Thanks.

This is my code:
var Pool = require(‘litecore-p2p’).Pool;
var Networks = require(‘litecore-lib’).Networks;
var Messages = require(‘litecore-p2p’).Messages;
var BufferUtil = require(‘litecore-lib’).util.buffer;
var pool = new Pool({network: Networks.livenet});

// connect to the network
pool.connect();

pool.on('peerinv', function(peer, message_inv) {
  var invs = message_inv.inventory;
  var len = invs.length;
  var i = 0;
  for(; i< len; ++i){
    var inv = invs[i];
    if(inv['type'] == 1){
      //var messages = new Messages();
      //var get = messages.GetData(invs);
      //pool.sendMessage(get);
    } 
    else if(inv['type'] == 2){
      var messages = new Messages();
      var get = messages.GetData(invs);
      pool.sendMessage(get);
      }
    }
  }
});

pool.on('peertx',function(peer, message_tx) {
  console.log(message_tx);
});

pool.on('peerblock',function(peer, message_block) {
  console.log(message_block);
});

This is a transaction message
TransactionMessage {
command: ‘tx’,
network:
Network {
name: ‘livenet’,
alias: ‘mainnet’,
pubkeyhash: 48,
privatekey: 176,
scripthash: 5,
xpubkey: 27108450,
xprivkey: 27106558,
networkMagic: ,
port: 9333,
dnsSeeds:
[ ‘dnsseed.litecointools.com’,
dnsseed.litecoinpool.org’,
dnsseed.ltc.xurious.com’,
dnsseed.koin-project.com’,
dnsseed.weminemnc.com’ ] },
Transaction:
{ [Function: Transaction]
DUST_AMOUNT: 546,
FEE_SECURITY_MARGIN: 15,
MAX_MONEY: 8400000000000000,
NLOCKTIME_BLOCKHEIGHT_LIMIT: 500000000,
NLOCKTIME_MAX_VALUE: 4294967295,
FEE_PER_KB: 100000,
CHANGE_OUTPUT_MAX_SIZE: 62,
MAXIMUM_EXTRA_SIZE: 26,
shallowCopy: [Function],
estimateFee: [Function],
Input:
{ [Function: Input]
MAXINT: 4294967295,
DEFAULT_SEQNUMBER: 4294967295,
DEFAULT_LOCKTIME_SEQNUMBER: 4294967294,
DEFAULT_RBF_SEQNUMBER: 4294967293,
fromObject: [Function],
fromBufferReader: [Function],
PublicKey: [Object],
PublicKeyHash: [Object],
MultiSig: [Object],
MultiSigScriptHash: [Object] },
Output: { [Function: Output] fromObject: [Function], fromBufferReader: [Function] },
UnspentOutput: { [Function: UnspentOutput] fromObject: [Function] },
Signature: { [Function: TransactionSignature] super
: [Object], fromObject: [Function] },
Sighash:
{ sighash: [Function: sighash],
sign: [Function: sign],
verify: [Function: verify] },
sighash:
{ sighash: [Function: sighash],
sign: [Function: sign],
verify: [Function: verify] } },
transaction: <Transaction: 0100000002af7970bee52dd4d164d8c43ae9afaa0a79d23aa2d5dad24d4cdd491b11e2b1d7000000006b483045022100ef2c01d8b7d60f70671bc73c5ae7ef4bc58b1d3aa699247a00b2e3a0bdb8506102206a808a5b86f7cc5724cc130f7cb81b32e3f70e1453b18680340002a7408e84f0012103c7ff3c2c0720667fd459d361c531ad23a08997dc0c6bdfbe2bd4cba7344678dffefffffff5a4df100b0d2ead71d2a5dc99567ecb41ed17faf0ce2264a5ee0da3523f7bee010000006a4730440220588040c96d0e5a0dc324ba3b9222fcbce96b18728a200298e5107633b47c6a0202203911720b6cfca54c46baf6bf2ab35aa7e9fad3f83c5aee3c4282cd276f4662ff012102ac731fdc7c92b093f118fd818f35b4127dd0927ec9af1658b96571488787366afeffffff026d0be505000000001976a9145ef55534a24519c27e049c6dcea39bafc5b4643d88ac8595cafc010000001976a9147e7a941db603b7f9a8fc4c93ac22851fda17232688acb7251200> }

This is a block message:
BlockMessage {
command: ‘block’,
network:
Network {
name: ‘livenet’,
alias: ‘mainnet’,
pubkeyhash: 48,
privatekey: 176,
scripthash: 5,
xpubkey: 27108450,
xprivkey: 27106558,
networkMagic: ,
port: 9333,
dnsSeeds:
[ ‘dnsseed.litecointools.com’,
dnsseed.litecoinpool.org’,
dnsseed.ltc.xurious.com’,
dnsseed.koin-project.com’,
dnsseed.weminemnc.com’ ] },
Block:
{ [Function: Block]
MAX_BLOCK_SIZE: 1000000,
_from: [Function: _from],
_fromObject: [Function: _fromObject],
fromObject: [Function: fromObject],
_fromBufferReader: [Function: _fromBufferReader],
fromBufferReader: [Function: fromBufferReader],
fromBuffer: [Function: fromBuffer],
fromString: [Function: fromString],
fromRawBlock: [Function: fromRawBlock],
Values:
{ START_OF_BLOCK: 8,
NULL_HASH: <Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00> },
BlockHeader:
{ [Function: BlockHeader]
_from: [Function: _from],
_fromObject: [Function: _fromObject],
fromObject: [Function: fromObject],
fromRawBlock: [Function: fromRawBlock],
fromBuffer: [Function: fromBuffer],
fromString: [Function: fromString],
_fromBufferReader: [Function: _fromBufferReader],
fromBufferReader: [Function: fromBufferReader],
Constants: [Object] },
MerkleBlock:
{ [Function: MerkleBlock]
fromBuffer: [Function: fromBuffer],
fromBufferReader: [Function: fromBufferReader],
_fromBufferReader: [Function: _fromBufferReader],
fromObject: [Function: fromObject] } },
block: }