Sunday, February 5, 2023
HomeBitcoinBCoin bsock: hearken to transactions and make sense of them

BCoin bsock: hearken to transactions and make sense of them

I’m attempting to arrange bsock in my bcoin utility, with the intention of listening to some transactions which might be broadcasted within the Bitcoin community. This may allow customers of my app to have actual time info on (unconfirmed) funds to addresses that are related for them, with out having to actively question my node at common intervals. documentation is somewhat good and I managed to determine a socket connection utilizing bsock. I handle to subsibe to the mempool channel to hearken to ‘tx’. I ve additionally arrange the bloom filter with the suitable guidelines.

The applying correctly logs transactions within the mempool that match the filter. To date so good.

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

Every handle property within the TX seems to be like this:

handle: <Handle: sort=witness model=0 str=bc1qsgjma9uamep8k6eln4j9xeq6aqhrljmnwhtjdj>

Evidently, this format would not permit me to do a lot with addresses…

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

Thanks quite a bit

Sorry however this doesnt work.

Right here is the response I get:

Node -- TX Occasion:

        peak: -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
              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
        OUT worth:  11244
        OUT:  undefined
        (node:8138) UnhandledPromiseRejectionWarning: TypeError: Can't learn property 'toString' of undefined
            at EventEmitter.<nameless> (/house/mmmilione/api/index.js:64:66)
            at EventEmitter.emit (occasions.js:210:5)
            at Socket.handleEvent (/house/mmmilione/api/node_modules/bsock/lib/socket.js:685:19)
            at Socket.handlePacket (/house/mmmilione/api/node_modules/bsock/lib/socket.js:620:21)
            at Socket.handleMessage (/house/mmmilione/api/node_modules/bsock/lib/socket.js:526:21)
            at Socket.handleFrame (/house/mmmilione/api/node_modules/bsock/lib/socket.js:448:21)
            at Parser.<nameless> (/house/mmmilione/api/node_modules/bsock/lib/socket.js:150:20)
            at Parser.emit (occasions.js:210:5)
            at Parser.feedBinary (/house/mmmilione/api/node_modules/bsock/lib/parser.js:40:10)
            at Socket.onMessage (/house/mmmilione/api/node_modules/bsock/lib/socket.js:238:17)
        (node:8138) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated both by throwing within an async perform with out a 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);
  //newTX.outputs.forEach(output =>{
  for(let loose = 0; out < newTX.outputs.size; out++){
    console.log('OUT worth: ', newTX.outputs[out].worth);
    console.log('OUT: ', newTX.outputs[out].handle);
    console.log('OUT Handle String', newTX.outputs[out].handle.toString('primary'));

As you may see, once I log the TX I can see the handle propert of the enter within the wierd format I discussed earlier than.

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

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



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments