Browse Source

Fix destination address in AlethZero.

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

13
alethzero/Context.cpp

@ -39,12 +39,17 @@ Context::~Context()
void dev::az::setValueUnits(QComboBox* _units, QSpinBox* _value, u256 _v)
{
initUnits(_units);
_units->setCurrentIndex(0);
while (_v > 50000 && _units->currentIndex() < (int)(units().size() - 2))
if (_v > 0)
{
_v /= 1000;
_units->setCurrentIndex(_units->currentIndex() + 1);
_units->setCurrentIndex(0);
while (_v > 50000 && _units->currentIndex() < (int)(units().size() - 2))
{
_v /= 1000;
_units->setCurrentIndex(_units->currentIndex() + 1);
}
}
else
_units->setCurrentIndex(6);
_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;
}
Address Transact::to() const
{
return m_main->fromString(ui->destination->currentText().toStdString()).first;
}
u256 Transact::total() const
{
return value() + fee();
@ -166,12 +161,7 @@ void Transact::on_destination_currentTextChanged(QString)
{
if (ui->destination->currentText().size() && ui->destination->currentText() != "(Create Contract)")
{
pair<Address, bytes> p;
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());
auto p = toAccount();
if (p.first)
ui->calculatedName->setText(QString::fromStdString(m_main->render(p.first)));
else
@ -210,7 +200,7 @@ void Transact::on_copyUnsigned_clicked()
t = Transaction(value(), gasPrice(), ui->gas->value(), m_data, nonce);
else
// 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())));
}
@ -331,9 +321,17 @@ string Transact::natspecNotice(Address _to, bytes const& _data)
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()
@ -342,7 +340,7 @@ GasRequirements Transact::determineGasRequirements()
qint64 baseGas = (qint64)Transaction::gasRequired(m_data, 0);
Address from = fromAccount();
Address to = toAccount();
Address to = toAccount().first;
ExecutionResult lastGood;
bool haveUpperBound = false;
@ -452,7 +450,7 @@ void Transact::rejigData()
// Add Natspec information
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
if (ui->gas->value() == ui->gas->minimum())

2
alethzero/Transact.h

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

Loading…
Cancel
Save