|
|
@ -42,20 +42,20 @@ template <unsigned N> FixedHash<N> jsToFixed(std::string const& _s) |
|
|
|
|
|
|
|
inline std::string jsToFixed(double _s) |
|
|
|
{ |
|
|
|
return toJS(dev::u256(_s * (double)(dev::u256(1) << 128))); |
|
|
|
return toJS(dev::u256(_s * (double)(dev::u256(1) << 128))); |
|
|
|
} |
|
|
|
|
|
|
|
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) |
|
|
|
{ |
|
|
|
if (_s.substr(0, 2) == "0x") |
|
|
|
// Hex
|
|
|
|
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))); |
|
|
|
else if (_s.find_first_not_of("0123456789") == std::string::npos) |
|
|
|
// Decimal
|
|
|
|
return boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>(_s); |
|
|
|
else |
|
|
|
// Binary
|
|
|
|
return fromBigEndian<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>>(asBytes(jsPadded(_s, N))); |
|
|
|
if (_s.substr(0, 2) == "0x") |
|
|
|
// Hex
|
|
|
|
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))); |
|
|
|
else if (_s.find_first_not_of("0123456789") == std::string::npos) |
|
|
|
// Decimal
|
|
|
|
return boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>(_s); |
|
|
|
else |
|
|
|
// Binary
|
|
|
|
return fromBigEndian<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>>(asBytes(jsPadded(_s, N))); |
|
|
|
} |
|
|
|
|
|
|
|
inline Address jsToAddress(std::string const& _s) { return jsToFixed<20>(_s); } |
|
|
@ -64,38 +64,38 @@ inline u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); } |
|
|
|
|
|
|
|
inline std::string jsToBinary(std::string const& _s) |
|
|
|
{ |
|
|
|
return jsUnpadded(dev::toString(jsToBytes(_s))); |
|
|
|
return jsUnpadded(dev::toString(jsToBytes(_s))); |
|
|
|
} |
|
|
|
|
|
|
|
inline std::string jsToDecimal(std::string const& _s) |
|
|
|
{ |
|
|
|
return dev::toString(jsToU256(_s)); |
|
|
|
return dev::toString(jsToU256(_s)); |
|
|
|
} |
|
|
|
|
|
|
|
inline std::string jsFromBinary(dev::bytes _s, unsigned _padding = 32) |
|
|
|
{ |
|
|
|
_s.resize(std::max<unsigned>(_s.size(), _padding)); |
|
|
|
return "0x" + dev::toHex(_s); |
|
|
|
_s.resize(std::max<unsigned>(_s.size(), _padding)); |
|
|
|
return "0x" + dev::toHex(_s); |
|
|
|
} |
|
|
|
|
|
|
|
inline std::string jsFromBinary(std::string const& _s, unsigned _padding = 32) |
|
|
|
{ |
|
|
|
return jsFromBinary(asBytes(_s), _padding); |
|
|
|
return jsFromBinary(asBytes(_s), _padding); |
|
|
|
} |
|
|
|
|
|
|
|
inline double jsFromFixed(std::string const& _s) |
|
|
|
{ |
|
|
|
return (double)jsToU256(_s) / (double)(dev::u256(1) << 128); |
|
|
|
return (double)jsToU256(_s) / (double)(dev::u256(1) << 128); |
|
|
|
} |
|
|
|
|
|
|
|
struct TransactionJS |
|
|
|
{ |
|
|
|
Secret from; |
|
|
|
Address to; |
|
|
|
u256 value; |
|
|
|
bytes data; |
|
|
|
u256 gas; |
|
|
|
u256 gasPrice; |
|
|
|
Secret from; |
|
|
|
Address to; |
|
|
|
u256 value; |
|
|
|
bytes data; |
|
|
|
u256 gas; |
|
|
|
u256 gasPrice; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|