Questions:
After mining, i do listtransactions command, i can see the address has amount of 50 coins in each transaction. Why getbalance command returns 0 ?
<pre>
$ src/bitcoin-cli -datadir=../datadir listtransactions
[
{
"account": "",
"address": "15454L2G44NuZoZrE2HdBwMmCchQVcGvKm",
"category": "immature",
"amount": 50.00000000,
"label": "",
"vout": 0,
"confirmations": 2,
"generated": true,
"blockhash": "00000000df3ae70ae6c5f3eb24b0dca0c37ef55b76fad5396f1386aaab2b0027",
"blockindex": 0,
"blocktime": 1527831787,
"txid": "24db59cbb12a8ffd3f1421931f2a6a2293b1b6437021af88119da95937c8f737",
"walletconflicts": [
],
"time": 1527831787,
"timereceived": 1527831828,
"bip125-replaceable": "no"
},
{
"account": "",
"address": "15454L2G44NuZoZrE2HdBwMmCchQVcGvKm",
"category": "immature",
"amount": 50.00000000,
"label": "",
"vout": 0,
"confirmations": 1,
"generated": true,
"blockhash": "00000000eb85f984adc2905671aaa8663d505c0ee71fb5a0d47996f76a12f336",
"blockindex": 0,
"blocktime": 1527831949,
"txid": "d47efd3725fb3be3072131ea6612b2e6581a876f11760e844e91ecd8b414f22e",
"walletconflicts": [
],
"time": 1527831949,
"timereceived": 1527831973,
"bip125-replaceable": "no"
}
]
$ src/bitcoin-cli -datadir=../datadir getbalance ""
0.00000000
</pre>
Generated coins cannot be spent until the generation transaction has gone through 101 confirmations. Transactions that try to spend generated coins before this will be rejected. The 101 confirmations is the maturity time.
The reason for this is that sometimes the block chain forks, blocks that were valid become invalid, and the mining reward in those blocks is lost. That is an unavoidable part of how Bitcoin works. If there was no maturation time, then whenever a fork happened, everyone who received coins that were generated on an unlucky fork (possibly through many intermediaries) would have their coins disappear, even without any sort of double-spend or other attack. On long forks, people could find coins disappearing from their wallets, even though there is no one actually attacking them and they had no reason to be suspicious of the money they were receiving.
For example, without a maturation time, a miner might deposit 50 BTC into an EWallet, and if the user withdraws money from a completely unrelated account on the same EWallet, the withdrawn money might just disappear if there is a fork and he/she is unlucky enough to withdraw coins that have been "tainted" by the miner's now-invalid coins.
Due to the way this sort of taint tends to "infect" transactions, far more than 50 BTC per block would be affected. Each invalidated block could cause transactions collectively worth hundreds of bitcoins to be reversed. The maturation time makes it impossible for anyone to lose coins by accident like this as long as a fork doesn't last longer than 100 blocks.
If a fork does last longer than 100 blocks, then the damage caused by invalidated transactions would likely be a huge disaster. This is unlike to happen, as something would have to be seriously wrong with Bitcoin or the Internet for a fork to last this long.
If a fork does last longer than 100 blocks, then the damage caused by invalidated transactions would likely be a huge disaster. This is unlike to happen, as something would have to be seriously wrong with Bitcoin or the Internet for a fork to last this long.