<p>The wallet is to a large extent separate from the rest of the node software. One of the reasons for this is because of the (slow) progress towards a working SPV mode. This means the wallet cannot depend on access to the UTXO set, as it won't be available in non-validating nodes.</p>

<p>However, it isn't needed. The wallet maintains an index of all input prevouts inside the wallet. Every output that is seen in a block, is to a wallet address, and which is not in this index as the input for another wallet transaction, is spendable.</p>

CC BY-SA 3.0
2017-02-16T21:33:33.733Z
Thanks. Does this mean that most transaction operations only happen within the wallet DB?
Yangrui
CC BY-SA 3.0
2017-02-16T23:37:45.337Z
What are 'transaction operations' ?
Pieter Wuille
CC BY-SA 3.0
2017-02-17T09:46:11.550Z
Such as spending some coins, calculating the balance. I'm a bit confused by the IsMine method of a transaction. It returns Solver(scriptPubKey, scriptSig) result. Does this mean that before spending a transaction, it must be checked against all keys in the wallet?
Yangrui
CC BY-SA 3.0
2017-02-17T17:28:04.887Z
Wallet operations like spending coins and calculating the balance only look at the list of wallet transactions and keys. As said, that's independent from the validation part. The UTXO set is only used for checking whether blocks and transactions are valid. Yes, IsMine checks against all wallet keys, but there are very fast indexes for that.
Pieter Wuille
CC BY-SA 3.0
2017-02-16T16:24:17.520Z
2017-02-16T16:47:08.887Z
2017-02-16T16:47:08.887Z
Pieter Wuille
<p>So, I found that in the original Bitcoin client there was a member variable vSpent in the class CWalletTX, however it appears that this is no longer the case in the new version. I know that the new Bitcoin client uses UTXO DB to store the unspent transactions. My question is that since LevelDB is a key-value database, and the UTXO key is derived from transaction outpoint, how does the client find the Txs that belongs to the wallet owner? Does it iterate over all unspent transactions and find those containing the public key of the receiver?</p>

<transactions><blockchain><leveldb>
How does the wallet know which outputs are available with LevelDB
Yangrui
# How does the wallet know which outputs are available with LevelDB

(Asked by: username_0 on 2017-02-16)

So, I found that in the original Bitcoin client there was a member variable vSpent in the class CWalletTX, however it appears that this is no longer the case in the new version. I know that the new Bitcoin client uses UTXO DB to store the unspent transactions. My question is that since LevelDB is a key-value database, and the UTXO key is derived from transaction outpoint, how does the client find the Txs that belongs to the wallet owner? Does it iterate over all unspent transactions and find those containing the public key of the receiver?

**Tags:** transactions, blockchain, leveldb


---

## 1 answers

### Answer by username_1 on 2017-02-16. Score: 4 | Accepted answer

The wallet is to a large extent separate from the rest of the node software. One of the reasons for this is because of the (slow) progress towards a working SPV mode. This means the wallet cannot depend on access to the UTXO set, as it won't be available in non-validating nodes.

However, it isn't needed. The wallet maintains an index of all input prevouts inside the wallet. Every output that is seen in a block, is to a wallet address, and which is not in this index as the input for another wallet transaction, is spendable.

> **Comments:**
> **username_0**: Thanks. Does this mean that most transaction operations only happen within the wallet DB?  
> **username_1**: What are 'transaction operations' ?  
> **username_0**: Such as spending some coins, calculating the balance. I'm a bit confused by the IsMine method of a transaction. It returns Solver(scriptPubKey, scriptSig) result. Does this mean that before spending a transaction, it must be checked against all keys in the wallet?  
> **username_1**: Wallet operations like spending coins and calculating the balance only look at the list of wallet transactions and keys. As said, that's independent from the validation part. The UTXO set is only used for checking whether blocks and transactions are valid. Yes, IsMine checks against all wallet keys, but there are very fast indexes for that.  

---

