How to parse transaction script to address the correct way? i am currently parsing blockchain transaction data from the raw hex blk00000.dat files downloaded by Bitcoin core. In order to validate, i compare my results with blockchain.info from time to time. 

While the major part of my parsing is already correct, i came accross a problem with the conversion of the output script to the corresponding address. 

Many of the addresses are already correctly parsed, as well, however there are some exceptions where the results are not the same as listed on blockchain.info. In my mind, it seems to be a problem with the transaction type. Apparently, for a transaction different from P2PKH, the output script will look differently, such that i cannot run the script through the same function that converts to the address all the time. 

I think to have figured out that the public keys in P2PKH-transactions scripts begin with 76 all the time, is that enough to determine the type as P2PKH?

Furthermore, i came across some few transactions that begin with 4104 and end with ac. For those ones, I have to use a different function to convert to the address, then it works. 

Lastly, i wanted to ask, what other transaction types i could come across? I need to parse every transaction script to an address 100% correctly, thus i need to cover all possible cases. 

When searching on the web for pre-written code, i found many partly useful, but also false or maybe old snippets. 
What i am searching for is a general function that i can parse the output script (or the complete raw transaction string) to and that delivers the output addresses and values of BTC / Satoshi sent to these.

Of course, if you can recommend an overall python parser for the rawtx hex strings from the .dat-files, i would be also glad :)
The main info i need for each transaction: 
- the hash of the corresponding block
- transaction time (block time) 
- number of inputs and outputs
- inputs [(block index (vout), txid), (...)]
- outputs [(value, address), (...)]
- the overall transaction hash

Thank you.
I think to have figured out that the public keys in P2PKH-transactions scripts begin with 76 all the time, is that enough to determine the type as P2PKH?


No. The 0x76 is the number of the first opcode, OP_DUP. A full P2PKH transaction has the template OP_DUP OP_HASH160 0x14 &lt;pkh&gt; OP_EQUALVERIFY OP_CHECKSIG.


  Lastly, i wanted to ask, what other transaction types i could come across? I need to parse every transaction script to an address 100% correctly, thus i need to cover all possible cases. 


Scripts can contain anything and there's not necessarily an address for them. Addresses represent specific data in standard transactions, of which there are only a few different types.


P2PKH (as above)
P2SH (OP_HASH160, 0x14 followed by the 20-byte hash of the redeem script and OP_EQUAL)
P2WPKH (witness version 0x00 followed by PKH)
P2WSH (witness version 0x00 followed by script hash)
P2MultiSig (OP_N, &lt;pubKey1&gt;..&lt;pubKeyN&gt; OP_M OP_CHECKMULTISIG where N &lt;= 3)
OP_RETURN &lt;data&gt;


The first two, P2PKH and P2SH use base58 addresses beginning with 1 and 3 respectively on mainnet.

P2WPKH and P2WSH use bech32 addresses beginning with bc1 on mainnet. You can determine the difference based on their length. Witness versions > 0 are also standard, but have no known meaning - this is intended for future extensibility.

OP_RETURN and P2MS don't have standard addresses. Nor do any non-standard transactions which do not fit any of the above conventions. Addresses are intended for human readability and parsing, so that software can simply recognize what kind of output is used, and how to create the relevant scriptSig to spend them.

Standard transactions are only a policy in software used to determine which kinds of unconfirmed transactions can be accepted into the mempool. Transactions confirmed in blocks can ignore these standardness rules and contain arbitrary scripts, as long as they evaluate to true.

The full details for parsing the standard script types are defined in standard.cpp in Bitcoin Core.