Skip to content

Commit 356988e

Browse files
committed
util: make EncodeBase58Check consume Spans
1 parent f0fce06 commit 356988e

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/base58.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet, in
132132
return DecodeBase58(str.c_str(), vchRet, max_ret_len);
133133
}
134134

135-
std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn)
135+
std::string EncodeBase58Check(Span<const unsigned char> input)
136136
{
137137
// add 4-byte hash check to the end
138-
std::vector<unsigned char> vch(vchIn);
138+
std::vector<unsigned char> vch(input.begin(), input.end());
139139
uint256 hash = Hash(vch);
140140
vch.insert(vch.end(), (unsigned char*)&hash, (unsigned char*)&hash + 4);
141141
return EncodeBase58(vch);

src/base58.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ NODISCARD bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet,
3939
NODISCARD bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len);
4040

4141
/**
42-
* Encode a byte vector into a base58-encoded string, including checksum
42+
* Encode a byte span into a base58-encoded string, including checksum
4343
*/
44-
std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn);
44+
std::string EncodeBase58Check(Span<const unsigned char> input);
4545

4646
/**
4747
* Decode a base58-encoded string (psz) that includes a checksum into a byte

src/bench/base58.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ static void Base58CheckEncode(benchmark::Bench& bench)
3434
200, 24
3535
}
3636
};
37-
std::vector<unsigned char> vch;
38-
vch.assign(buff.begin(), buff.end());
3937
bench.batch(buff.size()).unit("byte").run([&] {
40-
EncodeBase58Check(vch);
38+
EncodeBase58Check(buff);
4139
});
4240
}
4341

0 commit comments

Comments
 (0)