Browse Source

Units.

cl-refactor
Gav Wood 11 years ago
parent
commit
52b2417142
  1. 4
      TODO
  2. 50
      alephzero/MainWin.cpp
  3. 2
      libethereum/Common.h

4
TODO

@ -23,6 +23,10 @@ General:
- Better logging.
- Colours.
- Time/thread/channel stamp.
- Move over to new system.
AlephZero:
- Allow units to be selected for transactions.
### GAV

50
alephzero/MainWin.cpp

@ -73,10 +73,50 @@ void Main::readSettings()
}*/
}
std::string formatBalance(u256 _b)
{
static const vector<pair<u256, string>> c_units =
{
{((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000, "Uether"},
{((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000, "Vether"},
{((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000, "Dether"},
{(((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000, "Nether"},
{(((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000, "Yether"},
{(((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000, "Zether"},
{((u256(1000000000) * 1000000000) * 1000000000) * 1000000000, "Eether"},
{((u256(1000000000) * 1000000000) * 1000000000) * 1000000, "Pether"},
{((u256(1000000000) * 1000000000) * 1000000000) * 1000, "Tether"},
{(u256(1000000000) * 1000000000) * 1000000000, "Gether"},
{(u256(1000000000) * 1000000000) * 1000000, "Mether"},
{(u256(1000000000) * 1000000000) * 1000, "Kether"},
{u256(1000000000) * 1000000000, "ether"},
{u256(1000000000) * 1000000, "finney"},
{u256(1000000000) * 1000, "szabo"},
{u256(1000000000), "Gwei"},
{u256(1000000), "Mwei"},
{u256(1000), "Kwei"}
};
ostringstream ret;
if (_b > c_units[0].first * 10000)
{
ret << (_b / c_units[0].first) << " " << c_units[0].second;
return ret.str();
}
ret << setprecision(5);
for (auto const& i: c_units)
if (_b >= i.first * 100)
{
ret << (double(_b / (i.first / 1000)) / 1000.0) << " " << i.second;
return ret.str();
}
ret << _b << " wei";
return ret.str();
}
void Main::refresh()
{
m_client.lock();
ui->balance->setText(QString::fromStdString(toString(m_client.state().balance(m_myKey.address()))) + " wei");
ui->balance->setText(QString::fromStdString(formatBalance(m_client.state().balance(m_myKey.address()))));
ui->peerCount->setText(QString::fromStdString(toString(m_client.peerCount())) + " peer(s)");
ui->address->setText(QString::fromStdString(asHex(m_client.state().address().asArray())));
ui->peers->clear();
@ -90,15 +130,15 @@ void Main::refresh()
auto acs = m_client.state().addresses();
ui->accounts->clear();
for (auto i: acs)
ui->accounts->addItem(QString("%1 wei @ %2").arg(toString(i.second).c_str()).arg(asHex(i.first.asArray()).c_str()));
ui->accounts->addItem(QString("%1 @ %2").arg(formatBalance(i.second).c_str()).arg(asHex(i.first.asArray()).c_str()));
ui->transactionQueue->clear();
for (pair<h256, bytes> const& i: m_client.transactionQueue().transactions())
{
Transaction t(i.second);
ui->transactionQueue->addItem(QString("%1 wei (%2 fee) @ %3 <- %4")
.arg(toString(t.value).c_str())
.arg(toString(t.fee).c_str())
ui->transactionQueue->addItem(QString("%1 (%2 fee) @ %3 <- %4")
.arg(formatBalance(t.value).c_str())
.arg(formatBalance(t.fee).c_str())
.arg(asHex(t.receiveAddress.asArray()).c_str())
.arg(asHex(t.sender().asArray()).c_str()) );
}

2
libethereum/Common.h

@ -203,7 +203,7 @@ public:
#else
#define cbug(X) eth::DebugOutputStream<X>()
#define csbug(X) eth::DebugOutputStream<X, false>()
#define cdebug eth::DebugOutputStream<lb::DebugChannel, true>()
#define cdebug eth::DebugOutputStream<eth::DebugChannel, true>()
#endif
#define clog eth::SysLogOutputStream<true>()

Loading…
Cancel
Save