0
Recently, I wrote a c++ code to extract some information from some messages in BITCOIN protocol. for example, I extracted bitcoin value and output address corresponded to it from tx messages of this protocol.
Extraction algorithm for output addresses is based on type of scripts such as P2PK, P2PKH, P2SH, P2WPKH and etc. but it is not clear how to extract input addresses.
can anyone explain what is the extraction method for input addresses in tx messages?
Inputs don't have addresses. Outputs do. Inputs spend previous outputs. You'll need to find the output being spent to figure out the address (which is not explicit in the protocol), but generally this is not interesting information for anything but debug purposes. – Pieter Wuille – 2019-06-15T06:07:51.430
@PieterWuille You mean that every address which is shown in bitcoin explorers are previous outputs? I know that UTXO's are same previous outputs, but what about other transactions? – Saeed – 2019-06-15T06:50:00.303
Yes, that's exactly what UTXO means: unspent transaction output. An input simply spends a UTXO and gets to create new ones with the redeemed value. Bitcoin transaction inputs do not contains addresses or amounts; simply the identifier of a UTXO being spent, and the signature data necessary to authorize the spend. – Pieter Wuille – 2019-06-15T06:52:09.033
@PieterWuille So how I can access the transactions which their output addresses spent as input address for current transaction? – Saeed – 2019-06-15T07:33:35.603
No, you must have seen them when they were broadcast or included in a block, and remember them. Note that in order to be able to spend them, you need this information anyway. – Pieter Wuille – 2019-06-15T07:58:56.037
2As a personal comment judging by the questions you're asking: trying to learn Bitcoin by trying to decipher pcap dumps is not going to teach you much. The Bitcoin protocol is designed for interaction between Bitcoin nodes, which maintain state, and interact in various ways. Looking at the operation of those nodes directly will explain a lot more than trying to infer it from the trail of TCP messages you can observe. – Pieter Wuille – 2019-06-15T08:06:29.690