Browse Source

add ability to throw to fromHex

cl-refactor
CJentzsch 10 years ago
parent
commit
d8cf73b4ad
  1. 6
      alethzero/MainWin.cpp
  2. 4
      libdevcore/CommonData.cpp
  3. 3
      libdevcore/CommonData.h

6
alethzero/MainWin.cpp

@ -1330,15 +1330,15 @@ void Main::on_inject_triggered()
bytes b;
try
{
b = fromHex(s.toStdString());
b = fromHex(s.toStdString(), true);
}
catch(BadHexCharacter& _e)
catch (BadHexCharacter& _e)
{
cnote << "invalid hex character, transaction rejected";
cnote << boost::diagnostic_information(_e);
return;
}
catch(...)
catch (...)
{
cnote << "transaction rejected";
return;

4
libdevcore/CommonData.cpp

@ -78,7 +78,7 @@ int dev::fromHex(char _i)
BOOST_THROW_EXCEPTION(BadHexCharacter() << errinfo_invalidSymbol(_i));
}
bytes dev::fromHex(std::string const& _s)
bytes dev::fromHex(std::string const& _s, bool _throw)
{
unsigned s = (_s[0] == '0' && _s[1] == 'x') ? 2 : 0;
std::vector<uint8_t> ret;
@ -96,6 +96,7 @@ bytes dev::fromHex(std::string const& _s)
#ifndef BOOST_NO_EXCEPTIONS
cwarn << boost::current_exception_diagnostic_information();
#endif
if (_throw)
throw;
}
for (unsigned i = s; i < _s.size(); i += 2)
@ -108,6 +109,7 @@ bytes dev::fromHex(std::string const& _s)
#ifndef BOOST_NO_EXCEPTIONS
cwarn << boost::current_exception_diagnostic_information();
#endif
if (_throw)
throw;
}
return ret;

3
libdevcore/CommonData.h

@ -53,7 +53,8 @@ int fromHex(char _i);
/// Converts a (printable) ASCII hex string into the corresponding byte stream.
/// @example fromHex("41626261") == asBytes("Abba")
bytes fromHex(std::string const& _s);
/// If _throw = false, it replaces bad hex characters with 0's, otherwise it will throw an exception.
bytes fromHex(std::string const& _s, bool _throw = false);
#if 0
std::string toBase58(bytesConstRef _data);

Loading…
Cancel
Save