I'm studying Bitcoin protocol, and I'm able to create address by my bash script.
The addresses "P2PKH" and "P2PK" have the same procedure.
Compressed or uncompressed public key – SHA256 – RIPEMD160.
When I create a transaction using createrawtransaction
I can see that the protocol use P2PKH validation by default, and in listunspent
I can find its scriptPubKey.
My question is: How the protocol (and where in the code) recognize the validation? I'd like to understand when the protocol add
OP_PUSHBYTES[33] PBKEY OP_CHECKSIG
instead of OP_DUP OP_HASH160 OP_PUSHBYTES[20] HASH160(PB) OP_EQUALVERIFY OP_CHECKSIG
and How can I use P2PK
instead of P2PKH
?
UPDATE
For istance, my address is: (testnet)
mwqCgoJBcyciRUawXerkvom8sbg3zkjrvV
Import my address (I don't have it in my wallet, I created this address from outside of bitcoin-core)
bitcoin-cli importaddress mwqCgoJBcyciRUawXerkvom8sbg3zkjrvV
then I mined 101 blocks
bitcoin-cli generatetoaddress 101 mwqCgoJBcyciRUawXerkvom8sbg3zkjrvV >> /dev/null
After that I check my UTXO:
bitcoin-cli listunspent 1 101 '["'mwqCgoJBcyciRUawXerkvom8sbg3zkjrvV'"]'
[
{
"txid": "531dcfeea3f87feb4101bfea6fe91ffb0262072cb27acc56f885677ccca089cd",
"vout": 0,
"address": "mwqCgoJBcyciRUawXerkvom8sbg3zkjrvV",
"label": "",
"scriptPubKey": "76a914b2f58389a224c2fac62b51e78aad7ed058b50f5f88ac",
"amount": 50.00000000,
"confirmations": 101,
"spendable": false,
"solvable": false,
"safe": true
}
]
retrieve the UTXO
bitcoin-cli getrawtransaction 531dcfeea3f87feb4101bfea6fe91ffb0262072cb27acc56f885677ccca089cd 2 | jq
...
{
"value": 50,
"n": 0,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 b2f58389a224c2fac62b51e78aad7ed058b50f5f OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914b2f58389a224c2fac62b51e78aad7ed058b50f5f88ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"mwqCgoJBcyciRUawXerkvom8sbg3zkjrvV"
]
}
},
...
Why I have P2PKH instead of P2PK? And how can have the hash of my Public key if I imported just address (HASH160(PB))? And the last question, I understand that if the wallet find the 1
as the first char it apply P2PKH by default. How Can I use P2PK instead (study purpose).