Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: CIYAM on February 25, 2012, 10:18:21 AM



Title: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 25, 2012, 10:18:21 AM
I have just started playing with bitcoind (under Windoze using the 0.4.0 and running the GUI as the server) and noticed that when I did a "listtransactions" an entry like this:

...
{
    "account" : "",
    "address" : "1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX6",
    "category" : "send",
    "amount" : -0.50000000,
    "fee" : 0.00000000,
    "confirmations" : 1234,
    "txid" : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "time" : 1213411747
},
...

I wanted to put an account on the 1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX6 address so I initially did this via the GUI (which shows up in the Address book fine) but it just stayed blank in the listtransactions output when I re-ran the command.

So I then ran the following:

bitcoind setaccount 1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX6 name

and it created a new address (documented behavior if the account name is the same as it already has I read) so why can't I see the account when I do listtransactions?

Strangely enough if I run this:

bitcoind getaccount 1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX6

then it returns "name" is one would expect.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: deepceleron on February 25, 2012, 11:53:14 AM
The accounting system exposed by bitcoind is completely whacked. The last time I used it I had several negative account balances and no others added up to anything resembling what was in the addresses. The GUI ignores it for the most part, leaving wild balances, and it should be thrown away and just addresses and labels used.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 25, 2012, 12:42:06 PM
Ouch - was thinking that I must have done something wrong rather than finding bugs in the very first RPC command I tested. :(

Interestingly the problem only seems to occur for the "sent" tx's as I do see all the account names for the "receive" tx's fine (so perhaps a fix for at least this part may not be to hard).



Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: Nefario on February 25, 2012, 12:50:06 PM
Yeah I tried to use the bitcoind accounting system with the first version of GLBSE and it was a nightmare. Now I keep the system separate, In my system I record bitcoin deposits over 6 confirmations, and withdrawals immediately. After that I don't touch bitcoind.

Nefario.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: Pieter Wuille on February 25, 2012, 09:29:30 PM
Accounts are only affected by:
* incoming transactions to their bound addresses
* sendfrom
* move

Changing what account an address belongs to, does not change former transactions' to-account field.

The account system may be very unintuitive, but I wouldn't consider it buggy.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 26, 2012, 04:03:30 AM
Well if not buggy then why does "getaccount" give me a different result than "listtransactions" (are there more than one type of account in Bitcoin)?


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: Pieter Wuille on February 26, 2012, 04:12:13 AM
Well if not buggy then why does "getaccount" give me a different result than "listtransactions"?

Can you show me exactly which output you get, and why it is inconsistent? If it's really wrong, you stumbled upon a bug we'll gladly fix.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 26, 2012, 04:15:45 AM
As stated if I do a "listtransactions" the account field is always "" for every send even though (either through the GUI or bitcoind) I later set an account on the send addresses.

If I do a "getaccount" it *does* return the (to my way of thinking) correct string but never does it appear in "listtransactions".

To repeat just do something like the following:

bitcoind -rpcpassword=xxx listtransactions "*" 1000

and look at the account field for every "send" tx. In the version that I am using (0.4.0) for any "send" tx that address will always be "" no matter what you do.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: Pieter Wuille on February 26, 2012, 04:23:17 AM
As stated if I do a "listtransactions" the account field is always "" for every send even though (either through the GUI or bitcoind) I later set an account on the send addresses.

If I do a "getaccount" it *does* return the (to my way of thinking) correct string but never does it appear in "listtransactions".

EDIT: reformulated

Accounts are groups of addresses which automatically credit a named balance when transactions are received using them. If you use "setaccount" for an address that is not your own, there is no effect, nothing will ever be received using them.

The "account" field for sent transactions refers to the account a transaction was sent from, not to (that wouldn't make sense, as you can send to addresses that are not your own). The only way to influence that is using the RPC command "sendfrom", which allows changing the "from account" information.

There is somewhat more information here (https://en.bitcoin.it/wiki/Accounts_explained)


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 26, 2012, 04:28:46 AM
I guess the fix is a documentation one then - sorry for the misunderstanding.

I do think it is rather unintuitive but thanks for the explanation and the link (just read it).

Perhaps it could make sense that a "setaccount" to an external address instead sets the account on the internal address(es) that the funds came from?

Also after reading the link am not 100% sure about it but would I be correct in saying that I'd have to do a "move" to get the "account" to change for a "send"?


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: Pieter Wuille on February 26, 2012, 04:47:11 AM
I updated my post above again.

I'm not sure I see what you mean with "two types of accounts". An account is group of receiving addresses for which a balance of what is received using them is kept. The confusing probably comes from the fact that a) setaccount doesn't complain when adding an address that is not your own and b) labels in the GUI are mapped to accounts.
Still, accounts for sending addresses don't really make sense: if your address is in my "ciyam" account, and I send money to you, would that debit or credit "ciyam"?

I'll try to explain it in another way:
* each receive transaction will credit one account, namely the account associated with the address it was received on.
* each send transaction will debit one account, namely the one specified using "sendfrom", or the default account ("") if the transaction was done using the GUI or sendtoaddress.
* move actions debit one account and credit another account.

Also note that accounts have nothing to do with the actual coins used in the bitcoin transactions involved.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 26, 2012, 04:50:19 AM
I updated mine too (several times) - guess we are starting to confuse each other. ;)

I do understand the point that an account has to belong to yourself so will just repeat what I think might be more intuitive.

If I do a "setaccount" to an address that is not my own why couldn't it just put this account on the address(es) that the send had come from?


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: Pieter Wuille on February 26, 2012, 04:55:29 AM
If I do a "setaccount" to an address that is not my own why couldn't it just put this account on the address(es) that the send had come from?

You mean: if a send address A is associated with an account X, then transactions to A will by default debit X, and this behaviour can be changed retroactively using setaccount?

That sounds possible, but to be honest, I fear it will confuse even more people.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 26, 2012, 05:02:57 AM
Well for certain I found the output of listtransactions confusing after playing with getaccount and setaccount (but as originally stated this was my first play with bitcoind).

If doing a "move" would fix the problem I was seeing (simply that I wanted to change the associated account for the unseen from address) then no need to change anything.

Another helpful idea might be to perhaps have the listtransactions output contain both to/from addresses (so you would do a setaccount on the from address of a "send" in order to make the change I was trying to make).



Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: Pieter Wuille on February 26, 2012, 05:06:36 AM
Well for certain I found the output of listtransactions confusing after playing with getaccount and setaccount (but as originally stated this was my first play with bitcoind).

I understand.

Quote
If doing a "move" would fix the problem I was seeing (simply that I wanted to change the associated account for the unseen from address) then no need to change anything.

A move allows you to virtually move funds from one account to another. It will not change which account a particular send debits. That is something you choose when doing the transaction.

Quote
Another helpful idea might be to perhaps have the listtransactions output contain both to/from addresses (so you would do a setaccount on the from address of a "send" in order to make the change I was trying to make).

Bitcoin transactions do not have a from address (they can have multiple, or none at all, as they combine previously received funds), and accounts have nothing to do with the addresses in actual transactions. They are only for internal bookkeeping.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 26, 2012, 05:11:36 AM
Okay - think I need to do some more thinking about this (and it's starting to hurt).

From what I gather now it seems impossible to make the change I was wanting to see without resorting to have an external DB (which is what I gather the other posters did).


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: Pieter Wuille on February 26, 2012, 05:20:41 AM
May I ask what you are trying to do (the big picture, not "put send addresses in an account")?

The account feature is for keeping separate balances, for example for an e-wallet website that wishes to keep a balance for each customer (an "account"), and receive and send funds for them.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 26, 2012, 05:34:28 AM
Sure the "big picture" is exactly as you describe (having accounts for a general ledger) and I think if "sendfrom" was used (rather than the GUI) then the output I would see from listtransactions would be exactly as I am wanting it to be (with the account showing as the one for each customer).

My mistake was in not understanding what I was seeing (basically the word "account" confusing me and the fact I peeked at the code and just assumed from what I saw there that it was just a simple map).

I was simply wanting to change the output of listtransactions to see a name appear (as I can do in the GUI) but I now gather that is not possible using bitcoind and instead I should use "sendfrom" to have things appear as I wanted them to.

Perhaps there might be an option to be able to specify an account in the send dialog in the GUI down the track?

I am going to write a GL system (for my own business and which will end up as a package in my open source project) which I want to integrate with Bitcoin (other modules would follow the GL such as Payroll). Currently my own tx's were performed via the GUI so the problem I have is that I cannot (using bitcoind) get the "account labels" to match the GUI without doing this externally.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 26, 2012, 07:20:20 AM
Perhaps another possibility might be to add an option for listtransactions that would change the "account" being displayed (and filtered) for "send" categories to actually be the one attached to the external address (as perhaps is how the GUI is working at the moment) ?


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 26, 2012, 08:20:23 AM
If I get some spare time I wouldn't mind working on adding such an option to listtransactions provided that the core developers don't think it would be a bad idea.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: Pieter Wuille on February 26, 2012, 11:53:17 PM
Perhaps another possibility might be to add an option for listtransactions that would change the "account" being displayed (and filtered) for "send" categories to actually be the one attached to the external address (as perhaps is how the GUI is working at the moment) ?

I finally understand what you're asking. You do not want accounts at all, you just want labels attached to addresses, and the ability to search for them.

I suppose that isn't too hard, and sounds useful indeed.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 27, 2012, 05:15:11 AM
Yes - that is the idea and thanks for your help - I will look into implementing this as soon as I have some free time (or if anyone else is interested 1 BTC bounty available).

I think it might be useful especially for people who have started using the GUI and then decide they want to put all their tx's into a general ledger.


Title: Re: Why is account showing as empty even after doing a setaccount?
Post by: CIYAM on February 28, 2012, 08:46:13 AM
Not sure if any dev is watching this thread but I have made suggested source code changes to bitcoinrpc.cpp from this forked repo branch:

https://github.com/ciyam/bitcoin/tree/opt_use_sent_to_addr_for_acc

As I don't have boost or the time to get it and other libs installed at the moment this has not even been compiled (so I have not submitted a pull request).

If any dev (or anyone else) has enough spare time to at least compile and show any errors in my changes then I'd appreciate it.

The change is to the bitcoinrpc command listtransactions whose usage would become as follows:

listtransactions [account] [count=10] [from=0] [usesenttoaddresses=false]

When usesenttoaddresses is set true then the account mapping for "send" category tx's is to the sent to addr (rather than the current behaviour).

EDIT: Link for  commit changes:
https://github.com/ciyam/bitcoin/commits/opt_use_sent_to_addr_for_acc

I do hope to find more spare time to actually compile and test this myself but unfortunately I don't see that happening for quite a while so once again if anyone else has any spare time to check this I would appreciate it so I can then create a pull request.

EDIT: I will start a new thread in the Development board about this and will put a BTC bounty in that.


Cheers,

Ian.