Browse Source

Cleaning up debug messages and abstracting some functionality

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
ee682f1949
  1. 17
      alethzero/MainWin.cpp
  2. 3
      alethzero/MainWin.h
  3. 48
      alethzero/OurWebThreeStubServer.cpp
  4. 2
      alethzero/OurWebThreeStubServer.h

17
alethzero/MainWin.cpp

@ -1635,6 +1635,13 @@ static shh::Topic topicFromText(QString _s)
return ret;
}
bool Main::sourceIsSolidity(std::string const& _source)
{
// TODO: Improve this heuristic
return (_source.substr(0, 8) == "contract" || _source.substr(0, 2) == "/*");
}
void Main::on_data_textChanged()
{
m_pcWarp.clear();
@ -1648,7 +1655,7 @@ void Main::on_data_textChanged()
{
m_data = fromHex(src);
}
else if (src.substr(0, 8) == "contract" || src.substr(0, 5) == "//sol") // improve this heuristic
else if (sourceIsSolidity(src))
{
dev::solidity::CompilerStack compiler;
try
@ -1874,12 +1881,11 @@ void Main::on_send_clicked()
Secret s = i.secret();
if (isCreation())
{
// If execution is a contract creation, add Natspec to
// a local Natspec LEVELDB
ethereum()->transact(s, value(), m_data, ui->gas->value(), gasPrice());
// LTODO: work in progress, recompile contract and get the hash of the code
// Also .. yeah improve the heuristic for Solidity and abstract to a function
string src = ui->data->toPlainText().toStdString();
if (src.substr(0, 8) == "contract" || src.substr(0, 2) == "/*") // improve this heuristic
if (sourceIsSolidity(src))
{
dev::solidity::CompilerStack compiler;
@ -1892,7 +1898,6 @@ void Main::on_send_clicked()
m_natspecDB.add(contractHash,
compiler.getMetadata(s, dev::solidity::DocumentationType::NATSPEC_USER));
}
}
catch (...)
{

3
alethzero/MainWin.h

@ -230,6 +230,9 @@ private:
void refreshBlockCount();
void refreshBalances();
/// Attempts to infer that @c _source contains Solidity code
bool sourceIsSolidity(std::string const& _source);
std::unique_ptr<Ui::Main> ui;
std::unique_ptr<dev::WebThreeDirect> m_webThree;

48
alethzero/OurWebThreeStubServer.cpp

@ -42,48 +42,32 @@ std::string OurWebThreeStubServer::shh_newIdentity()
return toJS(kp.pub());
}
bool OurWebThreeStubServer::authenticate(dev::TransactionSkeleton const& _t) const
bool OurWebThreeStubServer::showAuthenticationPopup(std::string const& _title, std::string const& _text) const
{
// To get the balance of the sender
cnote << "Sender has ETH: " << m_web3->ethereum()->postState().balance(_t.from);
// otherwise it's a transaction to a contract for which we have the natspec
QMessageBox userInput;
userInput.setText(QString::fromStdString(_title));
userInput.setInformativeText(QString::fromStdString(_text + "\n Do you wish to allow this?"));
userInput.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
userInput.button(QMessageBox::Ok)->setText("Allow");
userInput.button(QMessageBox::Cancel)->setText("Reject");
userInput.setDefaultButton(QMessageBox::Cancel);
return userInput.exec() == QMessageBox::Ok;
}
bool OurWebThreeStubServer::authenticate(dev::TransactionSkeleton const& _t) const
{
h256 contractCodeHash = m_web3->ethereum()->postState().codeHash(_t.to);
if (contractCodeHash == EmptySHA3)
{
// recipient has no code - nothing special about this transaction.
// TODO: show basic message for value transfer.
return true;
}
//LTODO: Just for debugging here
cnote << "Contract hash:\n" << contractCodeHash;
cnote << "Transaction Value:\n" << "0x" + toHex(_t.value);
cnote << "Transaction Data:\n" << "0x" + toHex(_t.data);
//LTODO: Actually find and use the method name here
// std::string userNotice = m_main->lookupNatSpecUserNotice(contractCodeHash, "multiply");
std::string userNotice = m_main->lookupNatSpecUserNotice(contractCodeHash, _t.data);
if (userNotice.empty())
{
QMessageBox userInput;
userInput.setText("Unverified Pending Transaction");
userInput.setInformativeText("An undocumented transaction is about to be executed."
"Are you really sure you want to go through with it?");
userInput.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
userInput.setDefaultButton(QMessageBox::Cancel);
return userInput.exec() == QMessageBox::Ok;
}
return showAuthenticationPopup("Unverified Pending Transaction",
"An undocumented transaction is about to be executed.");
// otherwise it's a transaction to a contract for which we have the natspec
QMessageBox userInput;
userInput.setText("Pending Transaction");
userInput.setInformativeText(QString::fromStdString(userNotice + "\n Do you wish to allow this?"));
userInput.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
userInput.button(QMessageBox::Ok)->setText("Allow");
userInput.button(QMessageBox::Cancel)->setText("Reject");
userInput.setDefaultButton(QMessageBox::Cancel);
return userInput.exec() == QMessageBox::Ok;
return showAuthenticationPopup("Pending Transaction", userNotice);
}

2
alethzero/OurWebThreeStubServer.h

@ -41,6 +41,8 @@ signals:
void onNewId(QString _s);
private:
bool showAuthenticationPopup(std::string const& _title, std::string const& _text) const;
dev::WebThreeDirect* m_web3;
Main* m_main;
};

Loading…
Cancel
Save