eosio::checksum256 share::hex_to_checksum256(const std::string& in) {
eosio::check(in.length() == 64, "checksum size is error");
std::string hex{"0123456789abcdef"};
eosio::checksum256 out;
for (int i = 0; i < 32; i++) {
auto d1 = hex.find(in[2 * i]);
auto d2 = hex.find(in[2 * i + 1]);
eosio::check(d1 != std::string::npos || d2 != std::string::npos,
"invalid sha256");
// checksum256 is composed of little endian int128_t
reinterpret_cast<char*>(out.data())[i / 16 * 16 + 15 - (i % 16)] =
(d1 << 4) + d2;
}
return out;
}
EOSIO 智能合约 hex 字符串转 checksum256
最新推荐文章于 2023-01-13 10:15:02 发布