<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div>Is there special code somewhere that keeps track of all the btc not spent in all the transactions of a block and allows the miner&#39;s address (ie the address in the first tx of that block) to spend that? </div>
</div></blockquote><div><br></div><div>Something like that:</div><div>Every block has a coinbase transaction at the beginning.</div><div>The coinbase transaction is special, in that it can pay coins to its outputs without having to specify an input.</div>
<div><br></div><div>The total value of the outputs of the coinbase transaction can be at most the block value (the fixed amount per block) + the fees (summed over all transactions in the block).</div><div><br></div><div>This is checked in ConnectBlock inĀ </div>
<div><a href="https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1711">https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1711</a><br></div><div>The value of the coinbase transaction is being checked on line 1731.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>But if so, how would that work then? I should be finding transactions then where the sum of the ouputs is higher than the sum of the inputs and one of the inputs should have the miner&#39;s address attached to it or what?</div>
</div></blockquote><div><br></div><div>The only transactions in which the sum of the outputs can be larger than the sum of the inputs are the aforementioned coinbase transactions (which cannot have inputs).</div><div><br>
</div><div>The outputs from the coinbase transaction can be spent as any other output.</div><div><br></div><div>Wladimir</div><div><br></div></div></div></div>