I am currently working on a tool parsing every transaction of the bitcoin blockchain, using the getrawtransaction
RPC call in verbose mode.
My goal is to store them all in a database, while keeping some useful information about them (i.e., not everything that is given by the RPC call).
Something I am having trouble to understand though is how to precisely "tag" an input with a type? The outputs all have a "type" string that allows me to tag them as P2SH, P2PK, P2WSH, etc, but the inputs don't.
What I tried up to now is to parse the content of the scriptSig attribute of the inputs. For example, to know if an input is P2PK, I read somewhere that the ASM code of the scriptSig of the input should start with 30. When I compare with some online tools that have already tagged every transaction inputs/outputs, it looks like it's accurate, but I don't have any proof that what I am doing is right.
Is there some kind of online resources with precise specifications allowing me to identify an input? I cannot manage to find any.
Another idea I had is that each output is, obviously, linked to an output. Could I suppose that the type of input is the same as the one of the output it is linked to?
It would make sense to me, but I would rather not jump to conclusions; I still have a lot to learn about Bitcoin.
Thank you very much!
type
, and after testing with a few transactions, using the table you provided me, this field seems accurate (e.g., a P2WSH output will have the typewitness_v0_scripthash
and the format is the one from the table). Do you know how thistype
field is generated? Would the other fields be parsed to deduce the type? – Lev Sep 28 '23 at 09:02type
field is not an actual part of the transaction, Bitcoin RPC determined this field based on the content of the output script (scriptPubKey
). For example, if it sees the contentOP_HASH160
OP_PUSHBYTES_20
32-bytes
OP_EQUAL
in the output script (scriptPubKey
), it knows that the type isP2SH
, etc. No, it is only necessary to read the content of the output script, ie. the content ofscriptPubKey
inside the output, to determine its type. – dassd Sep 28 '23 at 09:19