I was reading a popular answer which explains how to find the address of the person who sent a transaction and the pseudocode in that answer does not make much sense to me.
txid = <relevant transaction id>
addresses = []
raw_tx = decoderawtransaction(getrawtransaction(txid))
for(input in raw_tx['vin']) {
input_raw_tx = decoderawtransaction(getrawtransaction(input['txid']))
addresses.push(input_raw_tx['vout'][input['vout']]['scriptPubKey']['addresses'][0])
}
Here is the part which I understood. A wallet which created txid
can use many inputs from different addresses to send that amount of money. This is why we iterate over input in raw_tx['vin']
and create a list of addresses addresses = []
.
Here is a part which is unclear for me:
input_raw_tx['vout'][input['vout']]['scriptPubKey']['addresses'][0]
input_raw_tx['vout']
returns the list. So input['vout']
should return the index of that list. But it also returns a list. Can anyone explain what is going on?
Also that answer was written in old 2013. Has anything changed in these 4 years and is there an easier way to find the returning address as of the beginning of 2918?