Author

Topic: API: keeping account balance positive (+knowing in advance the transaction fee) (Read 1089 times)

legendary
Activity: 1372
Merit: 1008
1davout
Maybe it doesnt scale too well for sites as big as davout`s sites
It was what made Instawallet absolutely unusably slow in the beginning of 2012.

I used to use it for Bitcoin-Central as a second layer of accounting, but at some point I realized discrepancies, which were due to the silent rounding.

Anyway, I don't mind this feature, but I think it's going to be really great when bitcoind uses a relational database that you can query directly.
newbie
Activity: 28
Merit: 0
Nobody except me and Lohoris working with the accounts feature?

Maybe it doesnt scale too well for sites as big as davout`s sites, but wouldnt that just be a problem of the current 0.7 implementation?
I mean the feature itself is great and if it gets some attention from developers it could scale well in the future, or am i missing something which totally sucks about accounts anyway?

Because installing a database myself and implementing exactly the same on my own would really look like reinventing the weel for me...

Why doesnt some bigger site instead of writing their own code contrubute better code to the bitcoin client?
(that question goes a bit to people like you davout)

hero member
Activity: 630
Merit: 500
Bitgoblin
If I was you I would simply not use the accounting feature.
Yeah, but that feature is exactly what I need to build a website... I mean, I would have to re-implement it from scratch anyway, so I'd rather not re-invent the wheel...
legendary
Activity: 1372
Merit: 1008
1davout
sendfrom() makes balances go negative by the fee amount if someone withdraws all coins.

yeah that is exactly my "problem 2", thanks for understanding that.
I've reported it as a bug, hoping they do consider it a bug.

@davout: yeah, I'm doing a move there. It is "problem 1", listed in the opening post.
I've fixed it hacking bitcoind code, though.
If it's as you say it is indeed a bug that needs to be fixed.
If I was you I would simply not use the accounting feature.
It just doesn't scale well.
hero member
Activity: 630
Merit: 500
Bitgoblin
sendfrom() makes balances go negative by the fee amount if someone withdraws all coins.

yeah that is exactly my "problem 2", thanks for understanding that.
I've reported it as a bug, hoping they do consider it a bug.

@davout: yeah, I'm doing a move there. It is "problem 1", listed in the opening post.
I've fixed it hacking bitcoind code, though.
newbie
Activity: 28
Merit: 0
sendfrom() makes balances go negative by the fee amount if someone withdraws all coins.
legendary
Activity: 1372
Merit: 1008
1davout
Last time I tried it did not work that way, but maybe you're trying with the default account, which is allowed to go negatvie.
no:

Code:
looris@Palace-of-the-Nine-Moons:~/ext-Sviluppo/bitcoin $ bitcoind listaccounts
{
    "" : 0.00000000,
    "bj_1" : 0.06900000,
    "bj_2" : 0.03550000,
    "bj_3" : 0.01550000,
    "bj_7" : 0.00000000
}
looris@Palace-of-the-Nine-Moons:~/ext-Sviluppo/bitcoin $ bitcoind move bj_3 bj_1 0.02
true
looris@Palace-of-the-Nine-Moons:~/ext-Sviluppo/bitcoin $ bitcoind listaccounts
{
    "" : 0.00000000,
    "bj_1" : 0.08900000,
    "bj_2" : 0.03550000,
    "bj_3" : -0.00450000,
    "bj_7" : 0.00000000
}

You're doing a "move" which is not the same thing as a "sendtoaddress".

Again, last time I checked transaction fees could not lead a non-default account into negative.

I'm not saying it has not changed, I am giving you the result of my experience.

Last time I checked "move"s between accounts would silently round the amounts to two decimal places, but it has been fixed since then.

The only way to know for sure is to test on the latest versions Smiley
hero member
Activity: 630
Merit: 500
Bitgoblin
Last time I tried it did not work that way, but maybe you're trying with the default account, which is allowed to go negatvie.
no:

Code:
looris@Palace-of-the-Nine-Moons:~/ext-Sviluppo/bitcoin $ bitcoind listaccounts
{
    "" : 0.00000000,
    "bj_1" : 0.06900000,
    "bj_2" : 0.03550000,
    "bj_3" : 0.01550000,
    "bj_7" : 0.00000000
}
looris@Palace-of-the-Nine-Moons:~/ext-Sviluppo/bitcoin $ bitcoind move bj_3 bj_1 0.02
true
looris@Palace-of-the-Nine-Moons:~/ext-Sviluppo/bitcoin $ bitcoind listaccounts
{
    "" : 0.00000000,
    "bj_1" : 0.08900000,
    "bj_2" : 0.03550000,
    "bj_3" : -0.00450000,
    "bj_7" : 0.00000000
}
legendary
Activity: 1372
Merit: 1008
1davout
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.
No, the transaction will fail if a tx fee causes the account to go negative
No, the account balance will go negative, I just tried.
We're talking about accounts here.
They do go negative.

Last time I tried it did not work that way, but maybe you're trying with the default account, which is allowed to go negatvie.
hero member
Activity: 630
Merit: 500
Bitgoblin
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.
No, the transaction will fail if a tx fee causes the account to go negative
No, the account balance will go negative, I just tried.
We're talking about accounts here.
They do go negative.
newbie
Activity: 7
Merit: 0
I'm sure it is impossible to get a negative ballance
legendary
Activity: 1372
Merit: 1008
1davout
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.
No, the transaction will fail if a tx fee causes the account to go negative
hero member
Activity: 630
Merit: 500
Bitgoblin
(as posted on SE)

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?
Jump to: