Ok one more decoding mystery
Example tx:
http://webbtc.com/tx/14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3E:\Repos\UxtoParser\UxtoParser.Demo\bin\Debug>UxtoParser.Demo.exe tx 14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3
Key:
63C3FE09272EE1B97760CD17BE97FC3BF24144114B29CA7989A2C7C086D55B0114
Value:
010C013600946CB2E08075BCBAF157E47BCB67EB2B2339D24268800F514104E6DA9C60084B43D28266243C636BCDAF4D8F17B5954E078D2DECE7D4659E0DEE34
19A40B939C24AC813C692A323CA5207A6FB387FFE28E48F706C95DBF46648F210226CB0561011D9045F6371CB09086BA7148D9942328BCF1DD78CB6EDB35CCDD
A921022EAC137AB02D826DF0AF54E92A352945C9892DF6CD77F1A7C390FC82C8B0EDEA53AE8F9D01
So I start decoding like this.
010C013600946CB2E08075BCBAF157E47BCB67EB2B2339D24268800F514104E6DA9C60084B43D28266243C636BCDAF4D8F17B5954E078D2DECE7D4659E0DEE341 9A40B939C24AC813C692A323CA5207A6FB387FFE28E48F706C95DBF46648F210226CB0561011D90 45F6371CB09086BA7148D9942328BCF1DD78CB6EDB35CCDDA921022EAC137AB02D826DF0AF54E92 A352945C9892DF6CD77F1A7C390FC82C8B0EDEA53AE8F9D01
Version: 0x01 = Ver 1
Code: 0x0C01 = First byte (bit 1 = 0 = not coinbase, bit 2 = 0 = vout[0] is already spent, bit 3= 1 = vout[1] is unspent, bit 4-8 = 0x0001 = one byte follows. Second byte = 0x000000001. This is a bitmap of the rest of the unspent outputs (from vout[2]+). Bit 1 is set. 1+1 = 2 so vout[2] is unspent. Summary: 2 unspent outputs (vout[1] & vout[2], neither are a coinbase output).
Vout[1] |36|00|946CB2E08075BCBAF157E47BCB67EB2B2339D242|
Value: MSB-128: 0x36 -> VarInt: 54 -> 6000
Code: 0x00 = P2PH
PkHash: 946cb2e08075bcbaf157e47bcb67eb2b2339d242
Vout[2] |68|800F|514104E6DA9C60084B43D28266243C636BCDAF4D8F17B5954E078D2DECE7D4659E0DEE3419A40B939C24AC813C692A323CA5207A6FB387FFE28E48F706C95DBF46648F210226CB0561011D9045F6371CB09086BA7148D9942328BCF1DD78CB6EDB35CCDDA921022EAC137AB02D826DF0AF54E92A352945C9892DF6CD77F1A7C390FC82C8B0EDEA53AE|
Value: MSB-128: 0x68 -> VarInt: 104 -> 12000
Code: 0x800f. First byte is not 0x01 to 0x05 so the code represents the length of an arbitrary script. How to decode length? Script: 514104e6da9c60084b43d28266243c636bcdaf4d8f17b5954e078d2dece7d4659e0dee3419a40b9
39c24ac813c692a323ca5207a6fb387ffe28e48f706c95dbf46648f2102
26cb0561011d9045f6371cb09086ba7148d9942328bcf1dd78cb6edb35ccdda921022eac137ab02
d826df0af54e92a352945c9892df6cd77f1a7c390fc82c8b0edea53ae
Block: MSB-128: 0x8f9d01 -> 265985
Of I am able to decode the entire UXTO record except the "code" element on the second vout[0]. Everything else matches the data from the blockchain. For standard tx types the code will be one byte and in the range 0x01-0x05 otherwise it somehow? represents the length of the script and can be one or two bytes. The source code isn't particularly descriptive (script.h).
* Other scripts up to 121 bytes require 1 byte + script length. Above
* that, scripts up to 16505 bytes require 2 bytes + script length.
Decoding 0x800f using MSB-128 results in 143 but the actual script is 137 bytes.
Any ideas?