Extract lightning network funding transactions with python bitcoin blockchain parser lib My ultimate goal is to parse funding transactions (as well as channel closes in a later step) from the blockchain. In order to do so I wanted to start with a funding transaction and disect it. Unfortunately I am kind of stuck and hope you can help out. 

via #recksplorer I clicked on an edge and found this transaction to be the funding transaction of a payment channel.  I found this transaction in my local copy of the blockchain using bitcoin-blockchain-parser (in python) lib

using this code

for i,h in enumerate(tx.hex):
    print('{:02x}'.format(h),end=" ")
    if i%8==7:
        print(" ",end="")
    if i%16==15:
       print()
print()


I get the following hex representation of my transaction (the two asterix ** where included to emphasize the output script of interest):

02 00 00 00 00 01 01 e3  3d f6 39 1a 02 5c 79 b3  
1a 2a ab 94 9f b5 6d f8  f9 2d 9f 3a bb ab 7d d3  
92 47 7f 31 9f b6 69 01  00 00 00 00 ff ff ff ff  
02 21 4e 00 00 00 00 00  00 22 **00 20 98 2b 53 22  
31 08 07 d3 68 d1 dc 26  11 43 09 5d c7 d0 2f ba  
6d 67 08 bb 76 21 51 9f  31 29 08 b2** e1 99 0d 00  
00 00 00 00 16 00 14 8c  35 c6 98 4d f9 d6 a2 9e  
4e 7d 76 21 19 3c fe 53  82 ce 60 02 48 30 45 02  
21 00 ba 9e 6e 56 a6 4f  a2 53 4a 02 e9 30 20 8e  
80 38 f6 f0 7c a8 d2 0e  b3 e4 03 59 99 20 8f 9d  
a1 15 02 20 3a 12 73 72  c4 bc ee 6f 76 9e 07 fd  
05 0e f0 62 9b 4d e8 e6  43 84 26 46 53 56 03 46  
07 f3 9a eb 01 21 03 0c  fa b1 4c d0 4a 01 5a 58  
40 2a 5e a6 84 e4 d9 b3  4b 33 23 73 04 0c 57 5e  
83 b1 0a d3 90 79 66 00  00 00 00 


I also found the two output scripts in particular the first one (after byte 58!) which sends 20001 satoshi to a payment channel: 

output = tx.outputs[0]
for x in output.script.hex:
    print('{:02x}'.format(h),end=" ")


00 20 98 2b 53 22 31 08 07 d3 68 d1 dc 26 11 43 09 5d c7 d0 2f ba 6d 67 08 bb 76 21 51 9f 31 29 08 b2

I have not been able to understand the format of the funding transaction itself. according to BOLT3 it should look like this: 


  2 &lt; pubkey1 > &lt; pubkey2 > 2 OP_CHECKMULTISIG


I asusme that 2 means OP_2. However with the help of bitcoin wiki I cannot find the hex values of OP_2 and OP_CHECKMULTISIG.

I guess (but can't verify this at the moment) that I am running into problems similar to this question here on this site. Or I am messing up with the endian notations? As mentioned my future goal would be to automatically extract all funding transactions therefor I need to be able to pursue my endeavor and would appreciate your help a lot! Thanks!
Firstly, you are off by two bytes. The output script is 0020982b5322310807d368d1dc261143095dc7d02fba6d6708bb7621519f312908b2, but you have selected 00220020982b5322310807d368d1dc261143095dc7d02fba6d6708bb7621519f312908b2.

Secondly, complex output scripts are never just put in the output. They are always wrapped in some form of Pay to Script Hash. In this case, because it is segwit, it's Pay to Witness Script Hash (P2WSH). So you can't know the actual script used without the output being spent from. Everything in LN is P2WSH, no scripts are just put in the outputs.

To break down this script, first you have 00. This is the witness version number, version 0. Then you have 20 which is a length indicator for the next chunk of data. In this case, that is 32 bytes. Lastly 982b5322310807d368d1dc261143095dc7d02fba6d6708bb7621519f312908b2 is the SHA256 hash of the script itself. That script will be a 2-of-2 multisig, but you won't be able to know what it actually is until this output is spent from.