Browse Source

Minor rename.

Report errors properly.
cl-refactor
Gav Wood 10 years ago
parent
commit
7b6710ac5b
  1. 4
      alethzero/MainWin.cpp
  2. 25
      eth/main.cpp
  3. 6
      libdevcore/CommonData.cpp
  4. 8
      libdevcore/CommonData.h
  5. 10
      neth/main.cpp
  6. 2
      test/TestHelper.cpp

4
alethzero/MainWin.cpp

@ -583,7 +583,7 @@ Address Main::fromString(QString const& _n) const
{ {
try try
{ {
return Address(fromHex(_n.toStdString(), ThrowType::Throw)); return Address(fromHex(_n.toStdString(), WhenError::Throw));
} }
catch (BadHexCharacter& _e) catch (BadHexCharacter& _e)
{ {
@ -1388,7 +1388,7 @@ void Main::on_inject_triggered()
QString s = QInputDialog::getText(this, "Inject Transaction", "Enter transaction dump in hex"); QString s = QInputDialog::getText(this, "Inject Transaction", "Enter transaction dump in hex");
try try
{ {
bytes b = fromHex(s.toStdString(), ThrowType::Throw); bytes b = fromHex(s.toStdString(), WhenError::Throw);
ethereum()->inject(&b); ethereum()->inject(&b);
} }
catch (BadHexCharacter& _e) catch (BadHexCharacter& _e)

25
eth/main.cpp

@ -273,10 +273,9 @@ int main(int argc, char** argv)
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc) else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
clientName = argv[++i]; clientName = argv[++i];
else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc) else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc)
{
try try
{ {
coinbase = h160(fromHex(argv[++i], ThrowType::Throw)); coinbase = h160(fromHex(argv[++i], WhenError::Throw));
} }
catch (BadHexCharacter& _e) catch (BadHexCharacter& _e)
{ {
@ -289,7 +288,6 @@ int main(int argc, char** argv)
cwarn << "coinbase rejected"; cwarn << "coinbase rejected";
break; break;
} }
}
else if ((arg == "-s" || arg == "--secret") && i + 1 < argc) else if ((arg == "-s" || arg == "--secret") && i + 1 < argc)
us = KeyPair(h256(fromHex(argv[++i]))); us = KeyPair(h256(fromHex(argv[++i])));
else if (arg == "--structured-logging-format" && i + 1 < argc) else if (arg == "--structured-logging-format" && i + 1 < argc)
@ -300,20 +298,24 @@ int main(int argc, char** argv)
dbPath = argv[++i]; dbPath = argv[++i];
else if ((arg == "-B" || arg == "--block-fees") && i + 1 < argc) else if ((arg == "-B" || arg == "--block-fees") && i + 1 < argc)
{ {
try { try
{
blockFees = stof(argv[++i]); blockFees = stof(argv[++i]);
} }
catch (...) { catch (...)
{
cerr << "Bad " << arg << " option: " << argv[++i] << endl; cerr << "Bad " << arg << " option: " << argv[++i] << endl;
return -1; return -1;
} }
} }
else if ((arg == "-e" || arg == "--ether-price") && i + 1 < argc) else if ((arg == "-e" || arg == "--ether-price") && i + 1 < argc)
{ {
try { try
{
etherPrice = stof(argv[++i]); etherPrice = stof(argv[++i]);
} }
catch (...) { catch (...)
{
cerr << "Bad " << arg << " option: " << argv[++i] << endl; cerr << "Bad " << arg << " option: " << argv[++i] << endl;
return -1; return -1;
} }
@ -434,7 +436,8 @@ int main(int argc, char** argv)
c->setAddress(coinbase); c->setAddress(coinbase);
} }
cout << "Address: " << endl << toHex(us.address().asArray()) << endl; cout << "Transaction Signer: " << us.address() << endl;
cout << "Mining Benefactor: " << coinbase << endl;
web3.startNetwork(); web3.startNetwork();
if (bootstrap) if (bootstrap)
@ -720,7 +723,7 @@ int main(int argc, char** argv)
u256 minGas = (u256)Client::txGas(bytes(), 0); u256 minGas = (u256)Client::txGas(bytes(), 0);
try try
{ {
Address dest = h160(fromHex(hexAddr, ThrowType::Throw)); Address dest = h160(fromHex(hexAddr, WhenError::Throw));
c->submitTransaction(us.secret(), amount, dest, bytes(), minGas); c->submitTransaction(us.secret(), amount, dest, bytes(), minGas);
} }
catch (BadHexCharacter& _e) catch (BadHexCharacter& _e)
@ -764,7 +767,7 @@ int main(int argc, char** argv)
stringstream ssc; stringstream ssc;
try try
{ {
init = fromHex(sinit, ThrowType::Throw); init = fromHex(sinit, WhenError::Throw);
} }
catch (BadHexCharacter& _e) catch (BadHexCharacter& _e)
{ {
@ -925,7 +928,7 @@ int main(int argc, char** argv)
{ {
try try
{ {
coinbase = h160(fromHex(hexAddr, ThrowType::Throw)); coinbase = h160(fromHex(hexAddr, WhenError::Throw));
} }
catch (BadHexCharacter& _e) catch (BadHexCharacter& _e)
{ {

6
libdevcore/CommonData.cpp

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

8
libdevcore/CommonData.h

@ -35,9 +35,9 @@ namespace dev
// String conversion functions, mainly to/from hex/nibble/byte representations. // String conversion functions, mainly to/from hex/nibble/byte representations.
enum class ThrowType enum class WhenError
{ {
NoThrow = 0, DontThrow = 0,
Throw = 1, Throw = 1,
}; };
@ -59,8 +59,8 @@ int fromHex(char _i);
/// Converts a (printable) ASCII hex string into the corresponding byte stream. /// Converts a (printable) ASCII hex string into the corresponding byte stream.
/// @example fromHex("41626261") == asBytes("Abba") /// @example fromHex("41626261") == asBytes("Abba")
/// If _throw = ThrowType::NoThrow, it replaces bad hex characters with 0's, otherwise it will throw an exception. /// If _throw = ThrowType::DontThrow, it replaces bad hex characters with 0's, otherwise it will throw an exception.
bytes fromHex(std::string const& _s, ThrowType _throw = ThrowType::NoThrow); bytes fromHex(std::string const& _s, WhenError _throw = WhenError::DontThrow);
#if 0 #if 0
std::string toBase58(bytesConstRef _data); std::string toBase58(bytesConstRef _data);

10
neth/main.cpp

@ -373,7 +373,7 @@ int main(int argc, char** argv)
{ {
try try
{ {
coinbase = h160(fromHex(argv[++i], ThrowType::Throw)); coinbase = h160(fromHex(argv[++i], WhenError::Throw));
} }
catch (BadHexCharacter& _e) catch (BadHexCharacter& _e)
{ {
@ -734,8 +734,8 @@ int main(int argc, char** argv)
{ {
try try
{ {
Secret secret = h256(fromHex(sechex, ThrowType::Throw)); Secret secret = h256(fromHex(sechex, WhenError::Throw));
Address dest = h160(fromHex(fields[0], ThrowType::Throw)); Address dest = h160(fromHex(fields[0], WhenError::Throw));
c->submitTransaction(secret, amount, dest, data, gas, gasPrice); c->submitTransaction(secret, amount, dest, data, gas, gasPrice);
} }
catch (BadHexCharacter& _e) catch (BadHexCharacter& _e)
@ -786,7 +786,7 @@ int main(int argc, char** argv)
u256 minGas = (u256)Client::txGas(bytes(), 0); u256 minGas = (u256)Client::txGas(bytes(), 0);
try try
{ {
Address dest = h160(fromHex(fields[0], ThrowType::Throw)); Address dest = h160(fromHex(fields[0], WhenError::Throw));
c->submitTransaction(us.secret(), amount, dest, bytes(), minGas); c->submitTransaction(us.secret(), amount, dest, bytes(), minGas);
} }
catch (BadHexCharacter& _e) catch (BadHexCharacter& _e)
@ -852,7 +852,7 @@ int main(int argc, char** argv)
stringstream ssc; stringstream ssc;
try try
{ {
init = fromHex(sinit, ThrowType::Throw); init = fromHex(sinit, WhenError::Throw);
} }
catch (BadHexCharacter& _e) catch (BadHexCharacter& _e)
{ {

2
test/TestHelper.cpp

@ -240,7 +240,7 @@ byte toByte(json_spirit::mValue const& _v)
bytes importByteArray(std::string const& _str) bytes importByteArray(std::string const& _str)
{ {
return fromHex(_str.substr(0, 2) == "0x" ? _str.substr(2) : _str, ThrowType::Throw); return fromHex(_str.substr(0, 2) == "0x" ? _str.substr(2) : _str, WhenError::Throw);
} }
bytes importData(json_spirit::mObject& _o) bytes importData(json_spirit::mObject& _o)

Loading…
Cancel
Save