0
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?
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 – 2019-02-06T18:51:56.567
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 – 2019-02-06T23:01:18.630
I still don't get it.
GetScriptForDestinationonly returns a single script, not all associated addresses (unless you're not talking about Bitcoin Core's current codebase). – Pieter Wuille – 2019-02-07T15:46:44.837Well, 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 – 2019-02-08T17:09:29.343
GetScriptForDestination(mykey.GetID())will give you the script corresponding to the P2PKH address for that key. If you want the P2WPKH address, useGetScriptForDestination(WitnessV0KeyHash(mykey.GetID())). GetScriptForDestination always returns just a single script, though. – Pieter Wuille – 2019-02-08T18:10:36.927