I'm making a simple demonstrator program, pretty much a simplified bitcoin clone based mostly on the original whitepaper.
Please bear with me, because I haven't found a way to describe the problem more concisely.
My blockchain is based on this tutorial.
However, it completely ignores the transaction part, so I've based the transactions on this part of the original documentation:
As specified here, my transactions consist of the next owner's public key and the signature of last transaction signed by the previous owner. I also added the amount being transferred (I'm not using the in/out system for the sake of simplicity).
Since each transaction needs a hash of a previous one, I also created a coinbase transaction. It only contains the mined amount and the miner's public key (to know whom to give the mined amount). This allows for the first regular transaction in a block to have a previous transaction to hash and sign.
However, that also means that the miner key has to be specified before the first transaction is made (since all future transactions require that the coinbase's hash stays the same). At the same time, it does not make sense to specify the miner before they have mined a block. In other words, this would require the transaction user to know a priori who will mine the block with their transaction.
My assumption so far was that a coinbase transaction is added to the unconfirmed transaction list after the previous block is mined, and new transactions refer to it. Then the whole list is put into a block which is then mined. However that assumption led to the aforementioned problems.
The only possible solution which I could come up with is using the last transaction hash from the previous block to sign a new transaction, effectively bypassing the coinbase transaction. But that doesn't seem right to me.
Please, tell me if I'm missing something, or got the wrong idea somewhere.
Where and when should the coinbase transaction(including the miner key) be added?
Or should I scrap that idea completely and use the "bypass" method?
PS. I've already tried searching various wikis and questions, but nothing realy gave me a clear solution to this. Especially, this answer is too vague