Can anyone tell me the specified source code to make "checksum bits appended", before doing Base58 conversion? Thanks very much!!!!
1 Answer
std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn)
{
// add 4-byte hash check to the end
std::vector<unsigned char> vch(vchIn);
uint256 hash = Hash(vch.begin(), vch.end());
vch.insert(vch.end(), (unsigned char*)&hash, (unsigned char*)&hash + 4);
return EncodeBase58(vch);
}
As you can see, the data vch
is hashed, then the first 4 bytes of the hash are appended to the end of vch
before base58 encoding.
-
Thank you so much for your answer. Stupid me, I ask the wrong question, what I want ask is the source code to attach the prefix not checksum. would you please tell me which source to attach the prefix before do Base58?– yrm23Sep 6, 2018 at 15:33
-
I think you may be looking for these lines: github.com/bitcoin/bitcoin/blob/v0.16.2/src/base58.cpp#L226. Note this has changed in the latest 0.17 release candidate to github.com/bitcoin/bitcoin/blob/v0.17.0rc3/src/key_io.cpp#L29– JBaczukSep 6, 2018 at 15:43