IMHO it isn’t secure to provide the tackle to a consumer instantly however, from my place, your proposed answer appears possible with adjustment.
I might advocate ammending as follows:
-
Examine the hole by API. If **hole>x* goto #3 else #2.
-
Generate the tackle and retailer it inside
unpaid_address
desk primarily based on the “index quantity” that blockchain returns with tackle. set expiration time for 60 minutes, retailer additionally the quantity requested and go to the #4. -
Get the primary expired unpaid tackle from
unpaid_address
desk. Duplicate it whether it is nonetheless marked as pending and retailer the quantity additionally. If there is not something, present sorry server is busy, else goto #4. -
Present the tackle to the consumer and say you have got quarter-hour to pay to this tackle. (quarter-hour is lower than expire time to keep away from issues).
-
I word that you just appear to be utilizing blockchin pockets however, you are able to do this as well as: If utilizing Bitcoin Core (bitcoin-qt|bitcoind) set
-walletnotify
on the command line to execute a script, calling your callback URL with a standing of pending if a transaction to any your tackle enters mempool (caveat: I solely imagine thatwalletnotify
executes when a transaction to your pockets enters mempool – you’ll have to check this). Your script might want to extract the payto tackle and BTC quantity to check with theunpaid_address
desk. Additional,walletnotify
ought to run once more when the transaction has its first affirmation, you’ll be able to name your callback URL with a standing of inexperienced after checking the transaction particulars. See How do I exploit walletnotify?. -
If blockchain callback my URL then I take away the tackle from
unpaid_address
else the tackle has been there for the following request by different consumer **if not even pending*. I’ll give that tackle to the following consumer for paying.
Notice that on many wallets you’ll be able to improve the hole restrict to, say, 100 or 1000 as you have got understood. I will surely think about a niche restrict of 1000 for the implementation that you just suggest.
Notice additionally that you will want to rigorously think about the way to consider a transaction that exists that’s not but confirmed. Until the charge is ridiculously low it ought to affirm ultimately, whilst a lot as greater than 30 days isn’t inconceivable as I’ve skilled this with a reasonable, however not notably low charge focusing on 3 day affirmation time.
I might additionally advocate storing the tackle together with the BTC quantity requested and by no means take away it as soon as it’s marked as pending, though, in doing so there is no such thing as a cause that you just can not re-use the tackle at some future time anyway (with out eradicating it because you retailer the tackle and quantity) offered, after all, that folks pay the total quantity precisely and with out deducting the charges from the paid quantity.
If you’re promoting excessive worth good you may think about ready till the cost is marked inexperienced earlier than transport as I beleive that that is what you have got meant.