tfchain icon indicating copy to clipboard operation
tfchain copied to clipboard

Use streaming mode for watching bridge account

Open sameh-farouk opened this issue 1 year ago • 0 comments

https://github.com/threefoldtech/tfchain/blob/9d56a805ead04d7f5d49cd7387443535a66e4032/bridge/tfchain_bridge/pkg/stellar/stellar.go#L351-L386

Instead of using a for loop to send requests and wait for 10 seconds when no new transactions are found, we can use the Stellar SDK stream mode to subscribe to an event-stream that gives us the latest payment information for the bridge account. When no more transactions are found, the stream stays open and new payments are sent as they are made.

Some benefits of this approach are:

  • We can get real-time updates on the status of payments.
  • We can avoid sending too many requests to the stellar network.
  • We can save resources (cpu time, network traffic) by not sending unnecessary requests.

See the client stream methods that can be used: https://github.com/stellar/go/blob/master/clients/horizonclient/client.go#L603

sameh-farouk avatar Oct 22 '23 13:10 sameh-farouk