Browse Source

Save/load gas pricing. Full integration.

cl-refactor
Gav Wood 10 years ago
parent
commit
0bd1b56c91
  1. 18
      alethzero/Context.cpp
  2. 4
      alethzero/Context.h
  3. 52
      alethzero/MainWin.cpp
  4. 4
      alethzero/MainWin.h
  5. 13
      alethzero/Transact.cpp
  6. 1
      alethzero/Transact.h
  7. 2
      alethzero/Transact.ui

18
alethzero/Context.cpp

@ -21,6 +21,7 @@
#include "Context.h"
#include <QComboBox>
#include <QSpinBox>
#include <libethcore/Common.h>
using namespace std;
using namespace dev;
@ -34,6 +35,23 @@ Context::~Context()
{
}
void setValueUnits(QComboBox* _units, QSpinBox* _value, u256 _v)
{
initUnits(_units);
_units->setCurrentIndex(0);
while (_v > 50000 && _units->currentIndex() < (int)(units().size() - 2))
{
_v /= 1000;
_units->setCurrentIndex(_units->currentIndex() + 1);
}
_value->setValue((unsigned)_v);
}
u256 fromValueUnits(QComboBox* _units, QSpinBox* _value)
{
return _value->value() * units()[units().size() - 1 - _units->currentIndex()].first;
}
void initUnits(QComboBox* _b)
{
for (auto n = (unsigned)units().size(); n-- != 0; )

4
alethzero/Context.h

@ -28,6 +28,7 @@
#include <libethcore/Common.h>
class QComboBox;
class QSpinBox;
namespace dev { namespace eth { struct StateDiff; class KeyManager; } }
@ -37,6 +38,8 @@ namespace dev { namespace eth { struct StateDiff; class KeyManager; } }
#define Span(S) "<span style=\"" S "\">"
void initUnits(QComboBox* _b);
void setValueUnits(QComboBox* _units, QSpinBox* _value, dev::u256 _v);
dev::u256 fromValueUnits(QComboBox* _units, QSpinBox* _value);
std::vector<dev::KeyPair> keysAsVector(QList<dev::KeyPair> const& _keys);
@ -67,5 +70,6 @@ public:
virtual dev::Secret retrieveSecret(dev::Address const& _a) const = 0;
virtual dev::eth::KeyManager& keyManager() = 0;
virtual dev::u256 gasPrice() const = 0;
};

52
alethzero/MainWin.cpp

@ -129,7 +129,7 @@ static QString filterOutTerminal(QString _s)
Main::Main(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Main),
m_transact(this, this),
m_transact(nullptr),
m_dappLoader(nullptr),
m_webPage(nullptr)
{
@ -233,6 +233,11 @@ Main::Main(QWidget *parent) :
// inspector->setPage(page);
setBeneficiary(*m_keyManager.accounts().begin());
readSettings();
m_transact = new Transact(this, this);
m_transact->setWindowFlags(Qt::Dialog);
m_transact->setWindowModality(Qt::WindowModal);
#if !ETH_FATDB
removeDockWidget(ui->dockWidget_accounts);
#endif
@ -269,33 +274,14 @@ void Main::on_gasPrices_triggered()
Ui_GasPricing gp;
gp.setupUi(&d);
d.setWindowTitle("Gas Pricing");
initUnits(gp.bidUnits);
u256 bid = static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->bid();
gp.bidUnits->setCurrentIndex(0);
while (bid > 50000 && gp.bidUnits->currentIndex() < (int)(units().size() - 2))
{
bid /= 1000;
gp.bidUnits->setCurrentIndex(gp.bidUnits->currentIndex() + 1);
}
gp.bidValue->setValue((unsigned)bid);
// TODO: refactor into a single function.
initUnits(gp.askUnits);
u256 ask = static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->ask();
gp.askUnits->setCurrentIndex(0);
while (ask > 50000 && gp.askUnits->currentIndex() < (int)(units().size() - 2))
{
ask /= 1000;
gp.askUnits->setCurrentIndex(gp.askUnits->currentIndex() + 1);
}
gp.askValue->setValue((unsigned)ask);
setValueUnits(gp.bidUnits, gp.bidValue, static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->bid());
setValueUnits(gp.askUnits, gp.askValue, static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->ask());
if (d.exec() == QDialog::Accepted)
{
// TODO: refactor into a single function.
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setBid(gp.bidValue->value() * units()[units().size() - 1 - gp.bidUnits->currentIndex()].first);
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setAsk(gp.askValue->value() * units()[units().size() - 1 - gp.askUnits->currentIndex()].first);
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setBid(fromValueUnits(gp.bidUnits, gp.bidValue));
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setAsk(fromValueUnits(gp.askUnits, gp.askValue));
m_transact->resetGasPrice();
}
}
@ -504,10 +490,8 @@ void Main::load(QString _s)
void Main::on_newTransaction_triggered()
{
m_transact.setEnvironment(m_keyManager.accounts(), ethereum(), &m_natSpecDB);
m_transact.setWindowFlags(Qt::Dialog);
m_transact.setWindowModality(Qt::WindowModal);
m_transact.show();
m_transact->setEnvironment(m_keyManager.accounts(), ethereum(), &m_natSpecDB);
m_transact->show();
}
void Main::on_loadJS_triggered()
@ -690,6 +674,11 @@ void Main::on_paranoia_triggered()
ethereum()->setParanoia(ui->paranoia->isChecked());
}
dev::u256 Main::gasPrice() const
{
return ethereum()->gasPricer()->bid();
}
void Main::writeSettings()
{
QSettings s("ethereum", "alethzero");
@ -706,6 +695,8 @@ void Main::writeSettings()
s.setValue("identities", b);
}
s.setValue("askPrice", QString::fromStdString(toString(static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->ask())));
s.setValue("bidPrice", QString::fromStdString(toString(static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->bid())));
s.setValue("upnp", ui->upnp->isChecked());
s.setValue("forceAddress", ui->forcePublicIP->text());
s.setValue("forceMining", ui->forceMining->isChecked());
@ -789,6 +780,9 @@ void Main::readSettings(bool _skipGeometry)
}
}
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setAsk(u256(s.value("askPrice", "500000000000").toString().toStdString()));
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setBid(u256(s.value("bidPrice", "500000000000").toString().toStdString()));
ui->upnp->setChecked(s.value("upnp", true).toBool());
ui->forcePublicIP->setText(s.value("forceAddress", "").toString());
ui->dropPeers->setChecked(false);

4
alethzero/MainWin.h

@ -91,7 +91,7 @@ public:
QList<dev::KeyPair> owned() const { return m_myIdentities; }
dev::u256 gasPrice() const { return 10 * dev::eth::szabo; }
dev::u256 gasPrice() const override;
dev::eth::KeyManager& keyManager() override { return m_keyManager; }
bool doConfirm();
@ -282,7 +282,7 @@ private:
static std::string fromRaw(dev::h256 _n, unsigned* _inc = nullptr);
NatspecHandler m_natSpecDB;
Transact m_transact;
Transact* m_transact;
std::unique_ptr<DappHost> m_dappHost;
DappLoader* m_dappLoader;
QWebEnginePage* m_webPage;

13
alethzero/Transact.cpp

@ -58,11 +58,9 @@ Transact::Transact(Context* _c, QWidget* _parent):
{
ui->setupUi(this);
initUnits(ui->gasPriceUnits);
initUnits(ui->valueUnits);
ui->valueUnits->setCurrentIndex(6);
ui->gasPriceUnits->setCurrentIndex(4);
ui->gasPrice->setValue(10);
resetGasPrice();
setValueUnits(ui->valueUnits, ui->value, 0);
on_destination_currentTextChanged(QString());
}
@ -92,6 +90,11 @@ void Transact::setEnvironment(AddressHash const& _accounts, dev::eth::Client* _e
ui->from->setCurrentIndex(0);
}
void Transact::resetGasPrice()
{
setValueUnits(ui->gasPriceUnits, ui->gasPrice, m_context->gasPrice());
}
bool Transact::isCreation() const
{
return ui->destination->currentText().isEmpty() || ui->destination->currentText() == "(Create Contract)";

1
alethzero/Transact.h

@ -41,6 +41,7 @@ public:
explicit Transact(Context* _context, QWidget* _parent = 0);
~Transact();
void resetGasPrice();
void setEnvironment(dev::AddressHash const& _accounts, dev::eth::Client* _eth, NatSpecFace* _natSpecDB);
private slots:

2
alethzero/Transact.ui

@ -159,7 +159,7 @@
<string>@ </string>
</property>
<property name="minimum">
<number>1</number>
<number>0</number>
</property>
<property name="maximum">
<number>430000000</number>

Loading…
Cancel
Save