mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2025-06-08 16:36:32 +00:00
Update 7_3_Scripting_a_P2PKH.md
This commit is contained in:
parent
25e703b6dd
commit
65aa6b2546
@ -6,7 +6,7 @@ With a basic understanding of Bitcoin Scripting in hand, you can now easily anal
|
|||||||
|
|
||||||
## Understand the Unlocking Script
|
## Understand the Unlocking Script
|
||||||
|
|
||||||
We've long said that when funds are sent to a Bitcoin address, they're locked to the private key associated with that address. This is managed through the `scriptPubKey` of a P2PKH transaction, which is designed such that it requires the redeemer to have the private key associated with the the P2PKH Bitcoin address. To be precise, the redeemer must supply both the actual public key and a signature generated by the private key.
|
We've long said that when funds are sent to a Bitcoin address, they're locked to the private key associated with that address. This is managed through the `scriptPubKey` of a P2PKH transaction, which is designed such that it requires the recipient to have the private key associated with the the P2PKH Bitcoin address. To be precise, the recipient must supply both the actual public key and a signature generated by the private key.
|
||||||
|
|
||||||
That's what the `scriptSig` unlocking script seen in the previous section showed, a `<signature> <pubKey>`:
|
That's what the `scriptSig` unlocking script seen in the previous section showed, a `<signature> <pubKey>`:
|
||||||
`3045022100c4ef5b531061a184404e84ab46beee94e51e8ae15ce98d2f3e10ae7774772ffd02203c546c399c4dc1d6eea692f73bb3fff490ea2e98fe300ac6a11840c7d52b6166[ALL] 0319cd3f2485e3d47552617b03c693b7f92916ac374644e22b07420c8812501cfb`.
|
`3045022100c4ef5b531061a184404e84ab46beee94e51e8ae15ce98d2f3e10ae7774772ffd02203c546c399c4dc1d6eea692f73bb3fff490ea2e98fe300ac6a11840c7d52b6166[ALL] 0319cd3f2485e3d47552617b03c693b7f92916ac374644e22b07420c8812501cfb`.
|
||||||
@ -23,7 +23,7 @@ Script: <signature> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CH
|
|||||||
```
|
```
|
||||||
Now, you can evaluate how the P2PKH UTXO is unlocked.
|
Now, you can evaluate how the P2PKH UTXO is unlocked.
|
||||||
|
|
||||||
First, you put the initial constants on the stack and make a duplicate of the pubKey:
|
First, you put the initial constants on the stack, then make a duplicate of the pubKey with `OP_DUP`:
|
||||||
```
|
```
|
||||||
Script: <signature> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
|
Script: <signature> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
|
||||||
Stack: [ ]
|
Stack: [ ]
|
||||||
@ -39,7 +39,7 @@ Stack: [ <signature> <pubKey> <pubKey> ]
|
|||||||
```
|
```
|
||||||
Why the duplicate? Because that's what's required by the script!
|
Why the duplicate? Because that's what's required by the script!
|
||||||
|
|
||||||
Next, your `OP_HASH160` pops the `<pubKey>` off the stack, hashes it, and puts the result back on the stack.
|
Next, `OP_HASH160` pops the `<pubKey>` off the stack, hashes it, and puts the result back on the stack.
|
||||||
```
|
```
|
||||||
Script: <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
|
Script: <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
|
||||||
Stack: [ <signature> <pubKey> <pubKeyHash> ]
|
Stack: [ <signature> <pubKey> <pubKeyHash> ]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user