How to tell which account an unspent output is in?

0

When I go to send coins, I want the transaction to ignore the unspent coins in a certain account.

I think I can do this in wallet.cpp, but I'm not sure how.

Maybe in the AvailableCoins() function? Make it continue if the coins are in this account? I guess I need to create a function like:

bool isInAccount(string strAccountName, CWalletTx *wtx)

How can I go about doing this?

Matthew Darnell

Posted 2014-10-02T15:14:16.507

Reputation: 508

Answers

2

Your question is based on a misunderstanding of the account system. It's a very common misunderstanding, though.

Unspent outputs are not associated with accounts.

Incoming transactions credit the balance of the account associated with the address the transaction is received with. But accounts only have a balance - they don't 'own' the coins sent to them. Account balances can go negative, and can be modified through the move command, without changing the coins.

The unspent outputs belong to the wallet as a whole, and accounts just keep track of who/what owns which amount of them - not which ones specifically. It is like keeping a wallet around with money that both belongs to you and to a friend. You keep track of how much you owe your friend, but you don't keep track of which specific notes or coins in the wallet belong to them.

To do what you want, you either need to use separate wallets (which keep the coins separately entirely), or use coin control or the raw transaction API, which allow you to specify manually which coins to use.

Pieter Wuille

Posted 2014-10-02T15:14:16.507

Reputation: 54 032

Pieter, wouldn't it be better if the accounts feature did function this way, associating UTXOs with specific accounts, and then only spending from an account's UTXOs? If no account is specified, then the software could take that to mean spend from any/all accounts' UTXOs. It seems that's how most people expect/want it to work. Maybe the issue with doing this is with backwards compatibility?morsecoder 2014-12-04T15:56:57.260

That's a completely different model, and no, that won't happen. The accounts feature will likely just be deprecated and removed somewhere in the future.Pieter Wuille 2014-12-04T16:44:52.210

What you're describing just sounds like having support for multiple wallets. Nobody disagrees with that, but without people actively developing the Bitcoin Core wallet implementation, that will take a while.Pieter Wuille 2014-12-04T16:46:00.377

0

Are you looking to be able to do this with the bitcoin daemon? You might check out the

getaccount
RPC call. The help for this method is:

getaccount "bitcoinaddress"

Returns the account associated with the given address.

Arguments: 1. "bitcoinaddress" (string, required) The bitcoin address for account lookup.

Result: "accountname" (string) the account address

Examples:
> bitcoin-cli getaccount "1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getaccount", "params": ["1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ"] }' -H 'content-type: text/plain;' http://localhost:8332/

morsecoder

Posted 2014-10-02T15:14:16.507

Reputation: 12 624

I know this is for a given address and you are looking for a particular vout, but the two probably correspond in your case I'm guessing?morsecoder 2014-10-02T16:20:28.907

No, I want to do this from within the Bitcoin core itself. Let's say I have an account called 'reserved'. Whenever I send coins, I don't want coins from the 'reserved' account to be used. I might have 1 or 100 addresses in 'reserved', but I never want any unspent received coins in that account to be used when I send coins.Matthew Darnell 2014-10-02T17:54:03.790