I'm writing a small script that will dump the utxo database to a text file. As far as I'm aware, these are the most common script patterns indicated by the type
field inside each value
:
e.g. value: b98276a2ec7700cbc2986ff9aed6825920aece14aa6f5382ca5580
<----><----><><-------------------------------------->
/ / \ \
height/coinbase value type script data
0x00 = P2PKH (hash160 public key)
0x01 = P2SH (hash160 script)
0x02 = P2PK
0x03 = P2PK
0x04 = P2PK (uncompressed)
0x05 = P2PK (uncompressed)
It seems as though the script type is there so that you only need to store the minimal amount of script data inside the database (e.g. the unique public keys and script hashes inside P2PK, P2PKH, and P2SH).
Anyway, would I be correct in assuming that you could only get an address from script types 0
and 1
(by base58 encoding the script data)?
In other words, the chainstate leveldb does not include any witness data to allow you get addresses for utxos using P2WPKH and P2WSH scripts?
EDIT: Here's the finished tool: https://github.com/in3rsha/bitcoin-utxo-dump