mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-06 18:53:21 +01:00
Make WitnessUnknown members private
Make sure that nothing else can change WitnessUnknown's data members by making them private. Also change the program to use a vector rather than C-style array.
This commit is contained in:
@@ -66,12 +66,13 @@ public:
|
||||
|
||||
std::string operator()(const WitnessUnknown& id) const
|
||||
{
|
||||
if (id.version < 1 || id.version > 16 || id.length < 2 || id.length > 40) {
|
||||
const std::vector<unsigned char>& program = id.GetWitnessProgram();
|
||||
if (id.GetWitnessVersion() < 1 || id.GetWitnessVersion() > 16 || program.size() < 2 || program.size() > 40) {
|
||||
return {};
|
||||
}
|
||||
std::vector<unsigned char> data = {(unsigned char)id.version};
|
||||
data.reserve(1 + (id.length * 8 + 4) / 5);
|
||||
ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, id.program, id.program + id.length);
|
||||
std::vector<unsigned char> data = {(unsigned char)id.GetWitnessVersion()};
|
||||
data.reserve(1 + (program.size() * 8 + 4) / 5);
|
||||
ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, program.begin(), program.end());
|
||||
return bech32::Encode(bech32::Encoding::BECH32M, m_params.Bech32HRP(), data);
|
||||
}
|
||||
|
||||
@@ -188,11 +189,7 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
|
||||
return CNoDestination();
|
||||
}
|
||||
|
||||
WitnessUnknown unk;
|
||||
unk.version = version;
|
||||
std::copy(data.begin(), data.end(), unk.program);
|
||||
unk.length = data.size();
|
||||
return unk;
|
||||
return WitnessUnknown{version, data};
|
||||
} else {
|
||||
error_str = strprintf("Invalid padding in Bech32 data section");
|
||||
return CNoDestination();
|
||||
|
||||
Reference in New Issue
Block a user