2

I am writing a system that uses the Bitcoin Core JSON-RPC API.

Use case: user wants to withdraw some BTC to his BTC address.

My application handles this request by the following logic:

  1. Check if user balance is OK.
  2. Call Bitcoin API method 'sendfrom'. In return I get the transaction ID.
  3. Store the 'Wihdraw' informations with the transaction ID in the database.

Now I want to make this error-safe, for example let's suppose that between points 2. and 3. the server crashes. Th 'Withdraw' info hasn't been saved to the DB. Next time user wants to withdraw some BTC it will allow they.

How do I make this error-safe? I have read that you can store a 'comment' in the Bitcoin Core, so an idea was to first create a unique comment, and store it in database with the withdraw address and amount, and set it status to UNDONE. Then submit this transaction to the Bitcoin Network and then set the status to DONE. In this way I can check if there are any UNDONE transactions in the DB and if so, verify if in my Bitcoin Core wallet there are no transactions with given comment. If there are not such transaction try to resubmit them. The problem with this approach is, that to get a transaction with a given message is to loop through all transactions.

Is there any better way to make the Bitcoin-Transaction transaction-safe?

EDIT: Best would be not to store any transaction info in database, but use the Bitcoin Core database itself. Maybe this way? But only way is to store transaction details in comment. Maybe use it to store deserialized objects?

  • 3
    TXID can change so doing something like that would be an easy way to lose a lot of Bitcoin. You really need to have a better grip on how transactions operate before trying to handle money, StackExchange isn't suited to the level of explanation necessary here to operate safely. – Anonymous Nov 9 '15 at 16:30
  • Wow, haven't heard of such thing that TXID can change... Now I have to read something about it. Thanks! – Darxis Nov 9 '15 at 20:10
  • Do you know any good reading for people like me, who are begining their adventure with Bitcoin Core API development? Also, I haven't found any article that says that TXID can change. Is it the Transaction Malleability problem? – Darxis Nov 9 '15 at 20:34
  • It's not authoritative, but the bitcoin.org developer docs are generally alright. – Anonymous Nov 9 '15 at 21:40

Your Answer

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

Browse other questions tagged or ask your own question.