2
1
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 – 2014-07-23T23:21:54.797
@Jori as I said, it's not an atomic operation. – o0'. – 2014-07-24T08:36:15.140
How does that matter then?
bitcoindwill 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 – 2014-07-24T08:40:49.047The solution to problem 2 is just set the transaction fee yourself or go along with the default (which is best IMHO). See https://en.bitcoin.it/wiki/Transaction_fees.
– Jori – 2014-07-24T08:43:44.440