You can assign destination tags to users however you wish. You can even do it randomly, which is the recommended method. Just keep track of which destination tags you've assigned to which users so you know who to credit when you receive a payment.
For UTXO-based systems, you give every user their own address and you credit the user whose address received a payment. For XRP, you give each user their own destination tag and you credit the destination tag that received the payment. This method is much simpler because you only have to watch one address on the network.
Note that you should set the "destination tag required" bit in your receiving address to ensure that you don't receive erroneous payments with no destination tag. If you need to send funds to your own account for some reason, just use any unassigned destination tag -- zero is commonly used for this purpose.
thanks for the answer. I thought of same as you said for assigning destination tag and giving the ripple to user according to received tag. But I'm stuck with the question that how can i know that the received payment is for the corresponding user. Do i receive a transaction hash whenever a user sends payment to my address?? so that i can fetch the destination tag from that hash. – veeresh kumbar – 2018-03-12T09:37:56.213
How do i know that the received transaction is for the particular user and how can i credit them with the payment. – veeresh kumbar – 2018-03-12T09:41:01.767
If i get the information whenever a receiving transaction is happened at that time how i can fetch the destination tag from that. Because the sender adds a destination tag but at the time of receiving that tag should be known to us, only in this condition i can credit the amount to particular user or else not. – veeresh kumbar – 2018-03-12T09:52:58.023
@veereshkumbar There will be a "DestinationTag" field in the transaction. You can't credit someone for a transaction unless you see the transaction. You will have to follow all transactions to your account. – David Schwartz – 2018-03-12T16:28:24.260
Do ripple-lib gives the info of Received transaction or the recently received transaction so that i can fetch the destination tag from it??? if yes please show the method to do it. Thanks – veeresh kumbar – 2018-03-13T04:58:17.380
There are several ways to do it, but the simplest is probably to subscribe to the account. You should probably also keep track of the last ledger you checked so that you can resume where you left off in the event your monitoring of the network is disrupted.
– David Schwartz – 2018-03-13T05:09:15.057Ok bro thanks for your time. I read that subscribing to transaction streams but i cannot find how to use it. do u have an example code ? – veeresh kumbar – 2018-03-13T05:33:31.753
You can start here.
– David Schwartz – 2018-03-13T05:37:17.013Let us continue this discussion in chat.
– veeresh kumbar – 2018-03-13T05:38:25.867