So, I'm working on adding code to bitcoin that allows users to send from specific addresses. I have it flushed out but running into some issues. It has takin me a while to properly form the question for the problem I'm running into which relates to understanding how bitcoin handles the below situation:
In the un-modified bitcoin, I'm not sure how the below is handled
*** transaction 1 ***
Say you have 50 BTC in your account from 1 generation
you use "sendfrom" to send 1 BTC to another account you own
this creates a transaction with 1 input and two outputs
50 btc as the input, call this address A
49 btc as change (from a somewhat random address or group of addresses you own to a hidden address) call this address U
1 btc to the address you specified, call this address B
When transaction 1 is commited, I believe the input transaction is marked as spent, in this case, it's fine because 50btc was the only output of a previous transaction that is connected to the input of my "Transaction 1"
*** transaction 2 ***
So now I want to spend say 0.5 BTC.
The software only has two addresses it can possibly select 0.5BTC from, "U" and "B".
So it selects one of these outputs from Transaction 1 as the input for Transaction 2
creates a change output for transaction 2 called U2
sends 0.5BTC to my desired address C
This is where I think I'm missing something, because it seems to me that when transaction 2 is commited, it would mark transaction 1 as spent, but transaction 1 still has an unused output that is ours and is not spent. I've looked thru the code I don't know how many times and I can't figure out how this case is handled. Can someone point out my flaw?