Best practice: obtaining, filtering and subscribing to historic/new chain data

Hey guys,

there was already a thread started that discusses Event subscription and I think it is generally an important topic to define the best way for developers to obtain, filter and subscribe to historic/new chain-data.

Today I thought about providing an oracle and how I should implement the backend. The backend should subscribe to all OracleQueryTx that are calling my oracle.

Currently I am only aware of two different approaches:

  • use the middleware-application (which is actively developed and provides WebSocket support)
  • poll the chain to obtain new transactions

Is there any other way to get the data? As far as I know the WebSocket implementation on the node is only available to handle off-chain communication between state channel participants.

Which approach does the team recommend?

Best regards,
Marco

The elixir-sdk will include such functionality. It takes part in gossip happening in the aeternity network and can listen for any kind of transactions. Maybe @d-velev can explain further.

Hi Marco,

As @piwo mentioned the Elixir SDK does support event subscription. It works by connecting to peers in a network (could be mainnet, testnet or any other custom/private network) and listening to any messages that are being gossiped. Here’s an example on how it can be used: https://github.com/aeternity/aepp-sdk-elixir/blob/master/examples/listener.md.

Listener.subscribe(
      :spend_transactions,
      self(),
      "ak_Y2Hueaa44EMAgfDy9zWePFpVToikqDFq5M4pkKe2zuYsk6wau"
    )

This fragment subscribes the handler process to spend transactions that have the passed address as the recipient, it can be replaced with

Listener.subscribe(
      :oracle_queries,
      self(),
      "ok_..."
    )

for your case.

I will gladly help if you decide to set it up and are having any trouble.

3 Likes

That sounds really great! At least we already have an option to subscribe to events at this point of time :slight_smile:

My question was more targeting a general approach to implement this. I would like to provide subscriptions in our Java SDK and wondering about the best way to achieve this.

The way Elixir SDK is doing can probably not be adapted for other SDKs, right?

Not sure, maybe you could manage to communicate with nodes with some noise protocol Java library and work from there?

2 Likes