Browse Source

Fix destination address in AlethZero.

cl-refactor
Gav Wood 10 years ago
parent
commit
bfc7851d68
  1. 5
      alethzero/Context.cpp
  2. 30
      alethzero/Transact.cpp
  3. 2
      alethzero/Transact.h

5
alethzero/Context.cpp

@ -39,12 +39,17 @@ Context::~Context()
void dev::az::setValueUnits(QComboBox* _units, QSpinBox* _value, u256 _v) void dev::az::setValueUnits(QComboBox* _units, QSpinBox* _value, u256 _v)
{ {
initUnits(_units); initUnits(_units);
if (_v > 0)
{
_units->setCurrentIndex(0); _units->setCurrentIndex(0);
while (_v > 50000 && _units->currentIndex() < (int)(units().size() - 2)) while (_v > 50000 && _units->currentIndex() < (int)(units().size() - 2))
{ {
_v /= 1000; _v /= 1000;
_units->setCurrentIndex(_units->currentIndex() + 1); _units->setCurrentIndex(_units->currentIndex() + 1);
} }
}
else
_units->setCurrentIndex(6);
_value->setValue((unsigned)_v); _value->setValue((unsigned)_v);
} }

30
alethzero/Transact.cpp

@ -121,11 +121,6 @@ u256 Transact::gasPrice() const
return ui->gasPrice->value() * units()[units().size() - 1 - ui->gasPriceUnits->currentIndex()].first; return ui->gasPrice->value() * units()[units().size() - 1 - ui->gasPriceUnits->currentIndex()].first;
} }
Address Transact::to() const
{
return m_main->fromString(ui->destination->currentText().toStdString()).first;
}
u256 Transact::total() const u256 Transact::total() const
{ {
return value() + fee(); return value() + fee();
@ -166,12 +161,7 @@ void Transact::on_destination_currentTextChanged(QString)
{ {
if (ui->destination->currentText().size() && ui->destination->currentText() != "(Create Contract)") if (ui->destination->currentText().size() && ui->destination->currentText() != "(Create Contract)")
{ {
pair<Address, bytes> p; auto p = toAccount();
if (!ui->destination->currentData().isNull() && ui->destination->currentText() == ui->destination->itemText(ui->destination->currentIndex()))
p.first = Address(ui->destination->currentData().toString().trimmed().toStdString());
else
p = m_main->fromString(ui->destination->currentText().trimmed().toStdString());
if (p.first) if (p.first)
ui->calculatedName->setText(QString::fromStdString(m_main->render(p.first))); ui->calculatedName->setText(QString::fromStdString(m_main->render(p.first)));
else else
@ -210,7 +200,7 @@ void Transact::on_copyUnsigned_clicked()
t = Transaction(value(), gasPrice(), ui->gas->value(), m_data, nonce); t = Transaction(value(), gasPrice(), ui->gas->value(), m_data, nonce);
else else
// TODO: cache like m_data. // TODO: cache like m_data.
t = Transaction(value(), gasPrice(), ui->gas->value(), to(), m_data, nonce); t = Transaction(value(), gasPrice(), ui->gas->value(), toAccount().first, m_data, nonce);
qApp->clipboard()->setText(QString::fromStdString(toHex(t.rlp()))); qApp->clipboard()->setText(QString::fromStdString(toHex(t.rlp())));
} }
@ -331,9 +321,17 @@ string Transact::natspecNotice(Address _to, bytes const& _data)
return "Destination not a contract."; return "Destination not a contract.";
} }
Address Transact::toAccount() pair<Address, bytes> Transact::toAccount()
{ {
return isCreation() ? Address() : m_main->fromString(ui->destination->currentText().toStdString()).first; pair<Address, bytes> p;
if (!isCreation())
{
if (!ui->destination->currentData().isNull() && ui->destination->currentText() == ui->destination->itemText(ui->destination->currentIndex()))
p.first = Address(ui->destination->currentData().toString().trimmed().toStdString());
else
p = m_main->fromString(ui->destination->currentText().trimmed().toStdString());
}
return p;
} }
GasRequirements Transact::determineGasRequirements() GasRequirements Transact::determineGasRequirements()
@ -342,7 +340,7 @@ GasRequirements Transact::determineGasRequirements()
qint64 baseGas = (qint64)Transaction::gasRequired(m_data, 0); qint64 baseGas = (qint64)Transaction::gasRequired(m_data, 0);
Address from = fromAccount(); Address from = fromAccount();
Address to = toAccount(); Address to = toAccount().first;
ExecutionResult lastGood; ExecutionResult lastGood;
bool haveUpperBound = false; bool haveUpperBound = false;
@ -452,7 +450,7 @@ void Transact::rejigData()
// Add Natspec information // Add Natspec information
if (!isCreation()) if (!isCreation())
htmlInfo = "<div class=\"info\"><span class=\"icon\">INFO</span> " + QString::fromStdString(natspecNotice(toAccount(), m_data)).toHtmlEscaped() + "</div>" + htmlInfo; htmlInfo = "<div class=\"info\"><span class=\"icon\">INFO</span> " + QString::fromStdString(natspecNotice(toAccount().first, m_data)).toHtmlEscaped() + "</div>" + htmlInfo;
// Update gas // Update gas
if (ui->gas->value() == ui->gas->minimum()) if (ui->gas->value() == ui->gas->minimum())

2
alethzero/Transact.h

@ -81,7 +81,7 @@ private:
void updateNonce(); void updateNonce();
dev::Address fromAccount(); dev::Address fromAccount();
dev::Address toAccount(); std::pair<dev::Address, bytes> toAccount();
void updateDestination(); void updateDestination();
void updateFee(); void updateFee();
bool isCreation() const; bool isCreation() const;

Loading…
Cancel
Save