Bitcore Bus?


(Sexual) #1

Hi,

So i’ve been working on building a IPN system for Bitcoin using Bitcore’s Bus, but have had issues with attempting to include it. If i try run a node programmatically, it just closes immediantly, no errors/messages: https://github.com/bitpay/bitcore-node/blob/master/docs/node.md#example-usage

So how can I include Bus whilst running a service in a node that has been built using https://bitcore.io/guides/service-development & bitcore.io/guides/full-node (can only put 2 links)

And does anyone have any tips on how to efficiently create an api. I was thinking of using Bus to subscribe to transactions from a dynamic array of all the addresses that are defined and dealing with confirmations/callbacks from there.

Thanks


(Sexual) #2

I’ve fixed that issue https://github.com/Sexual/bitcore-node/commit/7c841e2cdc631225f723623f5cec43b83be4a9cb

But now my issue is that when subscribed to something, i don’t get any actual results.

bus.subscribe('address/transaction', ['mmzJfdHMnUm56qq15VfuuMaMyEKy6EEriD']);
bus.subscribe('address/balance', ['mmzJfdHMnUm56qq15VfuuMaMyEKy6EEriD']);

bus.on('address/transaction', function(transaction) {
    console.log(transaction);
});

bus.on('address/balance', function(balance) {
    console.log(balance);
});

This returns no errors, but sending btc to those addresses don’t log anything.


(Sexual) #3

Any update to this?


(Sexual) #4

Anyone?


(Braydon Fuller) #5

This should be working, I’ve been able to subscribe: https://github.com/braydonf/bitcore-workshop-service I believe there are a few tutorials that also use the functionality (e.g. https://bitcore.io/guides/lemonade-stand/).


(Sexual) #6

From what I can see, that runs as a service. Your colleague showed me how to do it via a node. But, that led to the bus not working.

var configuration = {
  datadir: '/root/slut/btc/.data',
  network: 'testnet',
  "services": [{
    name: "address",
    module: Address,
    config: {}
  }, {
    name: 'bitcoind',
    module: Bitcoin,
    config: {}
  }, {
    name: 'db',
    module: DB,
    config: {}
  }]
};

var node = new Node(configuration);
var bus = node.openBus();

node.on('ready', function() {
  bus.subscribe('address/transaction', ['mmzJfdHMnUm56qq15VfuuMaMyEKy6EEriD']);
  bus.subscribe('address/balance', ['mmzJfdHMnUm56qq15VfuuMaMyEKy6EEriD']);
});

node.on('error', function(err) {
  log.error(err);
});

node.start(function() {
  log.info('node started up');
});

Would just doing this https://github.com/braydonf/bitcore-workshop-service/blob/master/views/index.ejs#L37-L78 but server side work to achieve an IPN functionality?


(Sexual) #7

Any update?


(Michael John B Quieta) #8

I have also the same problem


(FedFranz) #9

It seems to me that you are misusing the subscription function.
You should register to the event of the service like
subscribe('servicename/event').

In case of bitcoind, it would be something like this:
bus.subscribe('bitcoind/addresstxid', ['13FMwCYz3hUhwPcaWuD2M1U2KzfTtvLM89']);

See here:
https://github.com/bitpay/bitcore-node/blob/master/docs/services/bitcoind.md

I’ve just published a new service for message exchanging.
You can check it to see how I managed events

Hope this helps