<p>I am writing a system that uses the Bitcoin Core JSON-RPC API.</p>

<p>Use case: user wants to withdraw some BTC to his BTC address.</p>

<p>My application handles this request by the following logic:</p>

<ol>
<li>Check if user balance is OK. </li>
<li>Call Bitcoin API method 'sendfrom'. In
return I get the transaction ID.</li>
<li>Store the 'Wihdraw' informations
with the transaction ID in the database.</li>
</ol>

<p>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.</p>

<p>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.</p>

<p>Is there any better way to make the Bitcoin-Transaction transaction-safe?</p>

<p>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?</p>

CC BY-SA 3.0
2015-11-09T16:30:15.343Z
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.
Claris
CC BY-SA 3.0
2015-11-09T20:10:33.887Z
Wow, haven't heard of such thing that TXID can change... Now I have to read something about it. Thanks!
Darxis
CC BY-SA 3.0
2015-11-09T20:34:56.070Z
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
CC BY-SA 3.0
2015-11-09T21:40:57.047Z
It's not authoritative, but the [bitcoin.org developer docs](https://bitcoin.org/en/developer-documentation) are generally alright.
Claris
<transactions><bitcoind><bitcoin-core>
Include Bitcoin-Transaction within database-Transaction
Darxis
# Include Bitcoin-Transaction within database-Transaction

(Asked by: username_0 on 2015-11-09)

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?

**Tags:** transactions, bitcoind, bitcoin-core

> **Comments:**
> **username_1**: 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.  
> **username_0**: Wow, haven't heard of such thing that TXID can change... Now I have to read something about it. Thanks!  
> **username_0**: 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?  
> **username_1**: It's not authoritative, but the [bitcoin.org developer docs](https://bitcoin.org/en/developer-documentation) are generally alright.  

---

## 0 answers

