Skip to content

Commit

Permalink
partial bitcoin#19660: refactor: Make HexStr take a span
Browse files Browse the repository at this point in the history
Modified some code not backported yet

0a8aa62 refactor: Make HexStr take a span (Wladimir J. van der Laan)

Pull request description:

  Make `HexSt`r take a span of bytes, instead of an awkward pair of templated iterators. This simplifies most of the uses.

ACKs for top commit:
  elichai:
    Code review ACK 0a8aa62
  hebasto:
    re-ACK 0a8aa62
  jonatack:
    re-ACK 0a8aa62

Tree-SHA512: 6e178ece5cbac62119c857a10299b1e85422938084c3f03063e17119a5129e0c28016e05a6fabaa4c271a7e0a37c7cd89fa47c435ee19b38a5acfe80d00de992
  • Loading branch information
laanwj authored and christiancfifi committed Aug 25, 2021
1 parent b6bc515 commit a00dd81
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ UniValue finalizepsbt(const JSONRPCRequest& request)

if (complete && extract) {
ssTx << mtx;
result_str = HexStr(ssTx.str());
result_str = HexStr(ssTx);
result.pushKV("hex", result_str);
} else {
ssTx << psbtx;
Expand Down
2 changes: 1 addition & 1 deletion src/script/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class OriginPubkeyProvider final : public PubkeyProvider

std::string OriginString() const
{
return HexStr(std::begin(m_origin.fingerprint), std::end(m_origin.fingerprint)) + FormatKeyPath(m_origin.path);
return HexStr(m_origin.fingerprint) + FormatKeyPath(m_origin.path);
}

public:
Expand Down
13 changes: 13 additions & 0 deletions src/util/strencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,3 +629,16 @@ std::string Capitalize(std::string str)
str[0] = ToUpper(str.front());
return str;
}

std::string HexStr(const Span<const uint8_t> s)
{
std::string rv;
static constexpr char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
rv.reserve(s.size() * 2);
for (uint8_t v: s) {
rv.push_back(hexmap[v >> 4]);
rv.push_back(hexmap[v & 15]);
}
return rv;
}

0 comments on commit a00dd81

Please sign in to comment.