MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / EncodeBase58

Function EncodeBase58

src/commons/base58.cpp:68–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend) {
69 // Skip & count leading zeroes.
70 int zeroes = 0;
71 while (pbegin != pend && *pbegin == 0) {
72 pbegin++;
73 zeroes++;
74 }
75 // Allocate enough space in big-endian base58 representation.
76 vector<unsigned char> b58((pend - pbegin) * 138 / 100 + 1); // log(256) / log(58), rounded up.
77 // Process the bytes.
78 while (pbegin != pend) {
79 int carry = *pbegin;
80 // Apply "b58 = b58 * 256 + ch".
81 for (vector<unsigned char>::reverse_iterator it = b58.rbegin(); it != b58.rend(); it++) {
82 carry += 256 * (*it);
83 *it = carry % 58;
84 carry /= 58;
85 }
86 assert(carry == 0);
87 pbegin++;
88 }
89 // Skip leading zeroes in base58 result.
90 vector<unsigned char>::iterator it = b58.begin();
91 while (it != b58.end() && *it == 0)
92 it++;
93 // Translate the result into a string.
94 string str;
95 str.reserve(zeroes + (b58.end() - it));
96 str.assign(zeroes, '1');
97 while (it != b58.end())
98 str += pszBase58[*(it++)];
99 return str;
100}
101
102string EncodeBase58(const vector<unsigned char>& vch) {
103 return EncodeBase58(&vch[0], &vch[0] + vch.size());

Callers 3

BOOST_AUTO_TEST_CASEFunction · 0.85
InitRPCAuthenticationFunction · 0.85
EncodeBase58CheckFunction · 0.85

Calls 4

reserveMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68