2

I'm using the json API. I need to keep all the account balances positive: I call getbalance first, check if it has enough bitcoins to proceed, and then move or sendfrom.

This approach causes two problems.

Problem 1 is that this is not an atomic operation, so after the first getbalance the balance could actually be changed.

Problem 2 only happens with sendfrom: there might be a transaction fee, hence if the user sends his entire balance, he'll have a negative balance due to that.

Solution to Problem 2 would be to know in advance the transaction fee: I noticed (though I didn't try) I can set it with settxfee, but I found no call to get it, is there?

While I could implement some external lock mechanism to solve Problem 1, I'd rather use a bitcoind native method, though I get it does not exist, does it? Hacking the sendfrom function to have it check the balance before sending would be enough, I guess?

  • Are you making a bitcoin web application? How can the balance be lowered without you knowing? All money out goes through your API (code), doesn't it? – Jori Jul 23 '14 at 23:21
  • @Jori as I said, it's not an atomic operation. – o0'. Jul 24 '14 at 8:36
  • How does that matter then? bitcoind will not send any coins out of an account if there are no coins in it. What is the purpose of checking the balance first? – Jori Jul 24 '14 at 8:40
  • The solution to problem 2 is just set the transaction fee yourself or go along with the default (which is best IMHO). See en.bitcoin.it/wiki/Transaction_fees. – Jori Jul 24 '14 at 8:43

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.