39 template <
unsigned N> std::string
toJS(boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N, N, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>
const& _n)
43 std::string res = h[0] !=
'0' ? h : h.substr(1);
47 inline std::string
toJS(
bytes const& _n, std::size_t _padding = 0)
50 n.resize(std::max<unsigned>(n.size(), _padding));
51 return "0x" +
toHex(n);
56 std::stringstream stream;
61 template<
typename T> std::string
toJS(
T const& _i)
63 std::stringstream stream;
64 stream <<
"0x" << std::hex << _i;
86 if (_s.substr(0, 2) ==
"0x")
88 return FixedHash<N>(_s.substr(2 + std::max<unsigned>(N * 2, _s.size() - 2) - N * 2));
89 else if (_s.find_first_not_of(
"0123456789") == std::string::npos)
97 template <
unsigned N> boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>
jsToInt(std::string
const& _s)
99 if (_s.substr(0, 2) ==
"0x")
101 return fromBigEndian<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>>(
fromHex(_s.substr(2)));
102 else if (_s.find_first_not_of(
"0123456789") == std::string::npos)
104 return boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>(_s);
110 inline u256 jsToU256(std::string
const& _s) {
return jsToInt<32>(_s); }
115 inline int jsToInt(std::string
const& _s)
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
std::string jsToDecimal(std::string const &_s)
FixedHash< N > jsToFixed(std::string const &_s)
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< N *8, N *8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> Arith
The corresponding arithmetic type.
bytes unpadded(bytes _b)
Removing all trailing '0'. Returns empty array if input contains only '0' char.
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
FixedHash< T > const & makeInsecure() const
std::string toJS(FixedHash< S > const &_h)
string fromRaw(h256 _n)
Convert h256 into user-readable string (by directly using std::string constructor). If it can't be interpreted as an ASCII string, empty string is returned.
std::vector< byte > bytes
bytes toCompactBigEndian(T _val, unsigned _min=0)
Convenience function for toBigEndian.
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
bytes paddedRight(bytes _b, unsigned _l)
Add '0' on, or remove items from, the back of _b until it is of length _l.
bytes jsToBytes(string const &_s, OnFailed _f)
bytes padded(bytes _b, unsigned _l)
Add '0' on, or remove items from, the front of _b until it is of length _l.
T fromBigEndian(_In const &_bytes)
Converts a big-endian byte-stream represented on a templated collection to a templated integer value...
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< N *8, N *8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > jsToInt(std::string const &_s)
Convert a string representation of a number to an int String can be a normal decimal number...
bytes unpadLeft(bytes _b)
Remove all 0 byte on the head of _s.
u256 jsToU256(std::string const &_s)
#define DEV_IGNORE_EXCEPTIONS(X)