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 Feb 6 at 18:51
  • 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 Feb 6 at 23:01
  • 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 Feb 7 at 15:46
  • 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 Feb 8 at 17:09
  • 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 Feb 8 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.