At the moment I'm trying to get a look inside Bitcoin and the Blockchain, but I'm having some general unanswered questions.
- How does a wallet know how much Bitcoins belongs to a specific address?
I guess there are many possible ways to do that like parsing the complete blockchain and look for some transaction the address made and just sum up the transaction amounts. But that seems to be like the worst possible method. Is there another way to access the blockchain, for example like SQL for relational databases?
- In which block will the transaction for creating a block hash listed?
When you find a correct hash of a block you'll receive Bitcoins. But the transaction will be listed in the following block, correct? If the transaction would be listed in the block for which the miner found the hash, the hash would be instantly incorrect after adding this transaction to the block?!
- Who hashes the merkle root?
I already know that the merkle tree is "final" hash from all pairwise hashed transactions. But who hashes all the transactions? Is that also part of the miners themselves? If so, the miners have to hash all transactions and afterwards find the correct nonce?
- How do miners know that there is a new block?
I know that news blocks are generated every 10 minutes. Is this regulated by time? Let's say the last blocks hash was found at 9:30 and it's now 9:40, would the miner just look in the blockchain and get all transactions from 9:30 to 9:40 and that's the block that needs to be hashed?
- Is the difficulty only regulated by the leading zeroes in a hash?
When finding the correct hash it seems like getting the correct amount of leading zeroes is elementary. But is this the only way to regulate the difficulty?
- What if no nounce is found for a block?
Is it possible that the network can't find a nonce to generate the needed hash?
Thank you very much