I need help parsing blockchain.info transactions.
Right now I have this code here:
Google DocI have it taking the second ["out"] but, that does not always work because
every transaction does not have two inputs, and the second ["out"] is not always
actual input address.
Long story short, I need to know how to select the actual values of the received amounts, along with the true sending address.
There won't always be a "sending address" and there might be multiple "sending addresses". You can't count on the "sending address" belonging to the sender, and if there are multiple addresses, you can't even count on them all belonging to the same person.
Unless you are the sender or the receiver it is impossible to tell with certainty which of the outputs is the "spent" output, and which is the "change". It is possible for all the outputs in a transaction to effectively be "change" without any "spent" outputs at all. It is also possible for all the outputs in a transaction to be "spent" outputs without any "change" at all. For that matter, it is even possible that some outputs are neither "spent" nor "change" (when the script is OP_RETURN).
Perhaps you should describe what you are trying to accomplish, instead of how you are trying to do it. It sounds like you are starting from a flawed understanding of how bitcoin works, and are therefore not implementing your end goal in the best possible way.
Okay, here is what I'm wanting to accomplish.
I want to display the address that sent the btc to the address that I am receiving the json from, along with the amount received.
It's as simple as that... and if there are multiple addresses, I don't want that transaction to be displayed.
I'm still having a difficult time understanding what you're trying to do.
You say, "the address that I am receiving the json from", but addresses don't send json. Addresses receive bitcoins. Therefore, you can't receive json from an address.
I prefer not to click links to external sites, so I haven't been able to look at your code yet. Assuming that you are requesting json data from blockchain.info for a specific transactionID...
Are you saying that you want to do nothing at all if there isn't exactly one "sending address", and that you want to do nothing at all if there isn't exactly one "receiving address", and that if there is exactly one of each then you want to display the single "sending" address?
You are aware that MOST transactions will have more than one "receiving" address, right? (one for the bitcoins "spent" and one for the "change") Therefore most of the time you will display "nothing".