<p>So I would like to check if <code>coin.out.scriptPubKey</code> is part of <code>GetScriptForDestination(mypubkey.GetID())</code>  </p>

<p>A simple comparison isn't possible as the <code>scriptPubKey</code> (when I decode it) contains only the native SegWit address while the output <code>GetScriptForDestination()</code> will return all associated addresses.  </p>

<p>Is there a nice and clean way to do this or do I need to work my way through?</p>

CC BY-SA 4.0
2019-02-06T18:51:56.567Z
GetScriptForDestination in the current Bitcoin Core source code returns a single script. There are no witnesses in scriptPubKey. I don't understand your question.
Pieter Wuille
CC BY-SA 4.0
2019-02-06T23:01:18.630Z
yes, my abilities to describe problems are pretty poor. if I decode the output of GetScriptForDestination, it contains all from legacy to native segwit. so I can't compare it directly to the scriptPubKey if I want to check if the Coin matches the provided key
Michael Polzer
CC BY-SA 4.0
2019-02-07T15:46:44.837Z
I still don't get it. `GetScriptForDestination` only returns a single script, not all associated addresses (unless you're not talking about Bitcoin Core's current codebase).
Pieter Wuille
CC BY-SA 4.0
2019-02-08T17:09:29.343Z
Well, if you don’t get it, I may be up to something here. The codebase I am talking about is the current Core’s master branch. Actually the same thing I am doing now was working perfectly before, so I (maybe wrongfully) assumed that this comparison is now failing because on the old test and on live environment there was always at least one legacy prevout involved, now I am doing things on a plain SegWit environment, starting from coinbase. Definitely the scriptPubKey and the output from GetSctiptForDestination(mykey.GetID()) aren’t equal. The latter contains the first one though if I decode it
Michael Polzer
CC BY-SA 4.0
2019-02-08T18:10:36.927Z
`GetScriptForDestination(mykey.GetID())` will give you the script corresponding to the P2PKH address for that key. If you want the P2WPKH address, use `GetScriptForDestination(WitnessV0KeyHash(mykey.GetID()))`. GetScriptForDestination always returns just a single script, though.
Pieter Wuille
<script>
Check an outpoint's scriptPubKey against known scripts
Michael Polzer
# Check an outpoint's scriptPubKey against known scripts

(Asked by: username_0 on 2019-02-06)

So I would like to check if `coin.out.scriptPubKey` is part of `GetScriptForDestination(mypubkey.GetID())`

A simple comparison isn't possible as the `scriptPubKey` (when I decode it) contains only the native SegWit address while the output `GetScriptForDestination()` will return all associated addresses.

Is there a nice and clean way to do this or do I need to work my way through?

**Tags:** script

> **Comments:**
> **username_1**: GetScriptForDestination in the current Bitcoin Core source code returns a single script. There are no witnesses in scriptPubKey. I don't understand your question.  
> **username_0**: yes, my abilities to describe problems are pretty poor. if I decode the output of GetScriptForDestination, it contains all from legacy to native segwit. so I can't compare it directly to the scriptPubKey if I want to check if the Coin matches the provided key  
> **username_1**: I still don't get it. `GetScriptForDestination` only returns a single script, not all associated addresses (unless you're not talking about Bitcoin Core's current codebase).  
> **username_0**: Well, if you don’t get it, I may be up to something here. The codebase I am talking about is the current Core’s master branch. Actually the same thing I am doing now was working perfectly before, so I (maybe wrongfully) assumed that this comparison is now failing because on the old test and on live environment there was always at least one legacy prevout involved, now I am doing things on a plain SegWit environment, starting from coinbase. Definitely the scriptPubKey and the output from GetSctiptForDestination(mykey.GetID()) aren’t equal. The latter contains the first one though if I decode it  
> **username_1**: `GetScriptForDestination(mykey.GetID())` will give you the script corresponding to the P2PKH address for that key. If you want the P2WPKH address, use `GetScriptForDestination(WitnessV0KeyHash(mykey.GetID()))`. GetScriptForDestination always returns just a single script, though.  

---

## 0 answers

