10

Let's say I have a service that requires that a user send some XLM to another account in order to activate their account, what's the best way to actually verify when it's been paid?

I can think of a few options:

  1. Query the account directly and look for payment operations to it — poll this on a semi-regular basis and keep of the cursor.

  2. Use the EventSource streaming API and look for payment messages that come in. You'd have to be careful that you don't miss a message for whatever reason (service goes down, network partition)

Any others? What do services use for this in practice?

8

The streaming API is good for that job, you could get the last token from the network just when the user sends the payment and open the stream channel using that token so it looks only for transactions after that particular point in time. You won't miss a payment, and in case the user doesn't get the confirmation due to internet problems just reopen the stream using that token or query the last n transactions (depending on volume) and check for the Id in the memo field or account sender depending on your use case. I use the memo field all the time with a refid to identify transactions.

The Stellar user guide explains the process in detail.

5

Here's the process in action: https://github.com/shredding/stellar-bot/blob/master/src/stellar/index.js

  • I missed the part where I could use a cursor with the streaming API -- so it's really no different than paging through it yourself except you have to control the throttling. I did get bit in testing where I was recording the transactions in parallel via this mechanism and summing up payments to see it met some threshold and it did not reach the threshold because of a race condition. A work queue solved that though. Thanks! – Paul Jan 23 '18 at 19:58
1

I made StellarNotifier to simplify standard pub-sub tasks of tracking multiple update streams. It's a standalone service that tracks all operations for the unlimited number of accounts/assets/operations using a single Horizon event stream. The notifications are sent as JSON-encoded HTTP POST requests.

Features:

  • Highly configurable.
  • Supports operations filtering by account, asset, transaction memo, and operation type.
  • Guaranteed delivery, even if the notification recipient or the Notifier itself is down for some time.
  • Supports public and private Stellar networks.
  • Can be used as a shared microservice that streams events to multiple endpoints.
  • High performance (tested with thousands of subscriptions).
  • Reliable tracking and consistency (tracking is resumed from the same transaction after restart).
  • Does not require Stellar Core or Horizon node deployment.
  • Notifications are signed with an ED25519 secret key to protect the recipient from spoofing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.