1

I'm building a web application that uses bitcoind's accounts to track user balances. My dev env is currently in regtest mode. I am working on calculating the network transaction fee prior to creating a raw transaction.

When I listunspent to bitcoind over JSON-RPC, I get a multidim array that includes txid, address, and scriptPubKey (amongst other things). How can I use this information to determine which account these utxo's are tied to? I thought I'd be able to use getaccount with the returned corresponding addresses, but I'm returned an empty string. Is that because the transaction originated from the wallet 'global' account? Is that something to do with regression testing mode?

I also tried listtransactions for the specific account to match txid, but didn't have txid's because they were moves. Even if I could do this for network transactions, how would I handle utxo's that were resulting from a move?

I can getbalance for different accounts and see the correct resulting balances from using the move command. I'm beginning to question a few things so I'm not sure where I have an problem or if I'm going about this the wrong way. Ultimately, my goal is to be able to calculate tx fee so the user can approve them before sending...keeping in mind single wallet with each user having their own account.

Thanks for the help! ...it's late and my head hurts lol

1 Answer 1

1

The long and short of it is that you can't associate UTXOs with accounts, you can only associate addresses. From the bitcoin wiki accounts page:

When you receive bitcoins, they are always assigned to one of your accounts, and you can change which account is credited based on which bitcoin address receives the coins, just like you tell a bank teller which account to credit when you deposit cash in your bank. However, sending bitcoins is like withdrawing cash from the bank; the coins that are sent out and debited from an account are almost always not the same coins that were deposited into that account.

If you haven't already, you should see this post about why the accounts portion of the tab isn't really scalable.

I thought I'd be able to use getaccount with the returned corresponding addresses, but I'm returned an empty string. Is that because the transaction originated from the wallet 'global' account?

Yes, that is exactly, why. The default account is named "".

So, you can associate UTXOs with accounts through associating addresses with accounts, but when spending, there's no guarantee about where you're spending from.

As a possible work around, you might look at using this rpc call:

listreceivedbyaddress ( minconf includeempty )
2
  • thanks! really useful! so how does sendfrom choose its utxo's to ensure spending from the right account? i see from your links that performance would likely wain the more and more accounts you have, but could you predict the utxo's the wallet will choose for a sendfrom knowing that it will always attempt to pull from the default account? i've seen other posts mentioning the routine but not in regards to accounts
    – Jon B
    Oct 26, 2014 at 22:19
  • I'm not exactly sure how it prioritizes them, I've asked that question here. As a side note, if you need to tell it exactly which UTXOs to spend, you can do that with createrawtransaction and signrawtransaction.
    – morsecoder
    Oct 27, 2014 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.