Post
Topic
Board Development & Technical Discussion
Merits 1 from 1 user
Re: ScriptHash to CKeyID
by
NotATether
on 24/05/2021, 16:09:07 UTC
⭐ Merited by ETFbitcoin (1)
According to DecodeBase58Check signature it's returns bool and not hash160:

Code:
bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret)

Did you meant to vchRet?

Yes that's what I meant, I had already read the Doxygen classes on doxygen.bitcoincore.org.

So what you can do is reuse code from your DecodeAddressDestination to generate the CKeyID that is made from the base58-to-uint160 process like so:

Code:
        string sKey = "my_address";
        std::vector<unsigned char> data;
        uint160 hash;
        if (DecodeBase58Check(sKey, data, 256)) {
               // For your example the checks can be skipped since you have already
               // verified it returns a ScriptHash()
               std::copy(data.begin() + pubkey_prefix.size(), data.end(), hash.begin());
               CKeyID key = CKeyID(hash);
        }