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

<p><strong>Unspent outputs are not associated with accounts.</strong></p>

<p>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 <code>move</code> command, without changing the coins.</p>

<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2014-12-04T15:56:57.260Z
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
CC BY-SA 3.0
2014-12-04T16:44:52.210Z
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
CC BY-SA 3.0
2014-12-04T16:46:00.377Z
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
CC BY-SA 3.0
2014-12-01T19:23:15.117Z
2014-12-02T10:07:56.050Z
2014-12-02T10:07:56.050Z
Pieter Wuille
<p>Are you looking to be able to do this with the bitcoin daemon? You might check out the <pre>getaccount</pre> RPC call. The help for this method is:</p>

<p>getaccount "bitcoinaddress"</p>

<p>Returns the account associated with the given address.</p>

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

<p>Result: "accountname" (string) the account address</p>

<pre>
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/</pre>

CC BY-SA 3.0
2014-10-02T16:20:28.907Z
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
CC BY-SA 3.0
2014-10-02T17:54:03.790Z
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
CC BY-SA 3.0
2014-10-02T16:19:39.600Z
2014-10-02T16:19:39.600Z
morsecoder
<p>When I go to send coins, I want the transaction to ignore the unspent coins in a certain account.</p>

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

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

<pre><code>bool isInAccount(string strAccountName, CWalletTx *wtx)
</code></pre>

<p>How can I go about doing this?</p>

<transactions><wallet><development>
How to tell which account an unspent output is in?
Matthew Darnell
# How to tell which account an unspent output is in?

(Asked by: username_0 on 2014-10-02)

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?

**Tags:** transactions, wallet, development


---

## 2 answers

### Answer by username_1 on 2014-12-01. Score: 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.

> **Comments:**
> **username_2**: username_1, 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?  
> **username_1**: 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.  
> **username_1**: 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.  

---

### Answer by username_2 on 2014-10-02. Score: 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/
```

> **Comments:**
> **username_2**: 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?  
> **username_0**: 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.  

---

