I’m making an attempt to arrange bsock in my bcoin utility, with the intention of listening to some transactions which are broadcasted within the Bitcoin community. This could allow customers of my app to have actual time data on (unconfirmed) funds to addresses that are related for them, with out having to actively question my node at common intervals.

BCoin.io documentation is moderately good and I managed to ascertain a socket connection utilizing bsock. I handle to subsibe to the mempool channel to take heed to ‘tx’. I ve additionally arrange the bloom filter with the suitable guidelines.

The appliance correctly logs transactions within the mempool that match the filter. Up to now so good.

Anyway, I can’t get the addresses of inputs and outputs of the transaction object being logged.

Every deal with property within the TX appears to be like like this:

deal with: <Tackle: sort=witness model=Zero str=bc1qsgjma9uamep8k6eln4j9xeq6aqhrljmnwhtjdj>

Evidently, this format does not enable me to do a lot with addresses…

What ought to I do to get the deal with string (on this case: ‘bc1qsgjma9uamep8k6eln4j9xeq6aqhrljmnwhtjdj’) in JS utilizing the BCOIN library?

Thanks loads


Sorry however this doesnt work.

Right here is the response I get:

Node -- TX Occasion:

    {
        top: -1,
          block: null,
          time: 0,
          date: null,
          index: -1,
          model: 1,
          inputs: [
            {
              type: 'witnesspubkeyhash',
              subtype: null,
              address: <Address: type=witness version=0 str=bc1q4vvn4qcnssuz4cye6p5zs7yycndzep4ey80jtl>,
              script: <Script: >,
              witness: <Witness: 3044022043bc6f67b4bab6f0c38c3334d81d3e1d5ea746df70bd74fd14d687e900790f730220778e21beed3068e3a17b7b533585bf11525c25ffaa40cc8ae47d286dd3fc6cd901 02f84d8111044774051c7bd35ca9f4e975b1b3
        4bc70f5c2ec96d734b9407818cf0>,
              redeem: null,
              sequence: 4294967295,
              prevout: <Outpoint: 6477d78f01945d1c8f0c44735dc02703871b9f7f61dd5c759a8aae69f133506e/1>,
              coin: null
            }
          ],
          outputs: [
            {
              type: 'scripthash',
              value: '0.00011244',
              script: <Script: OP_HASH160 0x14 0x4aa79fc5cf098ab5911134e0ba16c9e5466c307c OP_EQUAL>,
              address: <Address: type=scripthash version=-1 str=38VkjU2CxU77zhbq95iFr47njnGJVjpEpG>
            },
            {
              type: 'witnesspubkeyhash',
              value: '0.00002918',
              script: <Script: OP_0 0x14 0xcd83248f8bcd6093e14e7794bd22f6dc3edbbcb9>,
              address: <Address: type=witness version=0 str=bc1qekpjfrute4sf8c2ww72t6ghkmsldh09ewyr35p>
            }
          ],
          locktime: 0
        }
        Outputs
        OUT worth:  11244
        OUT:  undefined
        (node:8138) UnhandledPromiseRejectionWarning: TypeError: Can't learn property 'toString' of undefined
            at EventEmitter.<nameless> (/residence/mmmilione/api/index.js:64:66)
            at EventEmitter.emit (occasions.js:210:5)
            at Socket.handleEvent (/residence/mmmilione/api/node_modules/bsock/lib/socket.js:685:19)
            at Socket.handlePacket (/residence/mmmilione/api/node_modules/bsock/lib/socket.js:620:21)
            at Socket.handleMessage (/residence/mmmilione/api/node_modules/bsock/lib/socket.js:526:21)
            at Socket.handleFrame (/residence/mmmilione/api/node_modules/bsock/lib/socket.js:448:21)
            at Parser.<nameless> (/residence/mmmilione/api/node_modules/bsock/lib/socket.js:150:20)
            at Parser.emit (occasions.js:210:5)
            at Parser.feedBinary (/residence/mmmilione/api/node_modules/bsock/lib/parser.js:40:10)
            at Socket.onMessage (/residence/mmmilione/api/node_modules/bsock/lib/socket.js:238:17)
        (node:8138) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated both by throwing inside an async operate with no catch block, or by rejecting a promise which was not
         dealt with with .catch(). (rejection id: 2)
        (node:8138) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. Sooner or later, promise rejections that aren't dealt with will terminate the Node.js course of with a non-zero exit code.

My Code:

nodeSocket.bind('tx', (uncooked) => {
  const newTX = TX.fromRaw(uncooked);
  console.log('Node -- TX Occasion:n', newTX);
  console.log("Outputs");
  //newTX.outputs.forEach(output =>{
  for(set free = 0; out < newTX.outputs.size; out++){
    console.log('OUT worth: ', newTX.outputs[out].worth);
    console.log('OUT: ', newTX.outputs[out].deal with);
    console.log('OUT Tackle String', newTX.outputs[out].deal with.toString('primary'));
  }
});

As you possibly can see, after I log the TX I can see the deal with propert of the enter within the wierd format I discussed earlier than.

However, when I attempt to log it individually (solely the deal with), it returns undefined.

Consequently, as I attempt to name the toString technique the app throws an error, saying tht it can’t learn the property toString of undefined.

Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here