Browse Source

Fixes and cleanup in OurWebThreeStubServer

- All fixes are Natspec related
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
295a277418
  1. 53
      alethzero/OurWebThreeStubServer.cpp
  2. 11
      alethzero/OurWebThreeStubServer.h

53
alethzero/OurWebThreeStubServer.cpp

@ -31,19 +31,19 @@ using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;
OurWebThreeStubServer::OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, dev::WebThreeDirect& _web3, OurWebThreeStubServer::OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, WebThreeDirect& _web3,
std::vector<dev::KeyPair> const& _accounts, Main* main): vector<KeyPair> const& _accounts, Main* main):
WebThreeStubServer(_conn, _web3, _accounts), m_web3(&_web3), m_main(main) WebThreeStubServer(_conn, _web3, _accounts), m_web3(&_web3), m_main(main)
{} {}
std::string OurWebThreeStubServer::shh_newIdentity() string OurWebThreeStubServer::shh_newIdentity()
{ {
dev::KeyPair kp = dev::KeyPair::create(); KeyPair kp = dev::KeyPair::create();
emit onNewId(QString::fromStdString(toJS(kp.sec()))); emit onNewId(QString::fromStdString(toJS(kp.sec())));
return toJS(kp.pub()); return toJS(kp.pub());
} }
bool OurWebThreeStubServer::showAuthenticationPopup(std::string const& _title, std::string const& _text) const bool OurWebThreeStubServer::showAuthenticationPopup(string const& _title, string const& _text) const
{ {
QMessageBox userInput; QMessageBox userInput;
userInput.setText(QString::fromStdString(_title)); userInput.setText(QString::fromStdString(_title));
@ -55,16 +55,31 @@ bool OurWebThreeStubServer::showAuthenticationPopup(std::string const& _title, s
return userInput.exec() == QMessageBox::Ok; return userInput.exec() == QMessageBox::Ok;
} }
bool OurWebThreeStubServer::authenticate(dev::TransactionSkeleton const& _t) void OurWebThreeStubServer::showBasicValueTransferNotice(u256 _value) const
{
QMessageBox notice;
notice.setText("Basic Value Transfer Transaction");
notice.setInformativeText(QString::fromStdString("Value is " + toString(_value)));
notice.setStandardButtons(QMessageBox::Ok);
notice.exec();
}
bool OurWebThreeStubServer::authenticate(TransactionSkeleton const& _t)
{ {
h256 contractCodeHash = m_web3->ethereum()->postState().codeHash(_t.to); h256 contractCodeHash = m_web3->ethereum()->postState().codeHash(_t.to);
if (contractCodeHash == EmptySHA3) if (contractCodeHash == EmptySHA3)
// recipient has no code - nothing special about this transaction. // contract creation
// TODO: show basic message for value transfer.
return true; return true;
std::string userNotice = m_main->lookupNatSpecUserNotice(contractCodeHash, _t.data); if (false) //TODO: When is is just a value transfer?
{
// recipient has no code - nothing special about this transaction, show basic value transfer info
showBasicValueTransferNotice(_t.value);
return true;
}
string userNotice = m_main->lookupNatSpecUserNotice(contractCodeHash, _t.data);
if (userNotice.empty()) if (userNotice.empty())
return showAuthenticationPopup("Unverified Pending Transaction", return showAuthenticationPopup("Unverified Pending Transaction",
"An undocumented transaction is about to be executed."); "An undocumented transaction is about to be executed.");
@ -83,17 +98,17 @@ QNatspecExpressionEvaluator::QNatspecExpressionEvaluator(OurWebThreeStubServer*
QNatspecExpressionEvaluator::~QNatspecExpressionEvaluator() QNatspecExpressionEvaluator::~QNatspecExpressionEvaluator()
{} {}
QString QNatspecExpressionEvaluator::evalExpression(QString const& _expression) QString QNatspecExpressionEvaluator::evalExpression(QString const& _expression) const
{ {
// load natspec.js only when we need it for natspec evaluation
// evaluate the natspec
m_main->evalRaw(contentsOfQResource(":/js/natspec.js")); m_main->evalRaw(contentsOfQResource(":/js/natspec.js"));
QVariant result = m_main->evalRaw("evaluateExpression('" + _expression + "')");
// _expression should be in the format like this if (result.type() == QVariant::Invalid)
// auto toEval = QString::fromStdString("the result of calling multiply(4) is `multiply(4)`"); {
auto toEval = _expression; cerr << "Could not evaluate natspec expression: \"" << _expression.toStdString() << "\"" << endl;
auto result = m_main->evalRaw("evaluateExpression('" + toEval + "')"); // return the expression unevaluated
return _expression;
}
return result.toString(); return result.toString();
} }

11
alethzero/OurWebThreeStubServer.h

@ -42,6 +42,7 @@ signals:
private: private:
bool showAuthenticationPopup(std::string const& _title, std::string const& _text) const; bool showAuthenticationPopup(std::string const& _title, std::string const& _text) const;
void showBasicValueTransferNotice(dev::u256 _value) const;
dev::WebThreeDirect* m_web3; dev::WebThreeDirect* m_web3;
Main* m_main; Main* m_main;
@ -51,14 +52,14 @@ private:
class QNatspecExpressionEvaluator: public QObject class QNatspecExpressionEvaluator: public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
QNatspecExpressionEvaluator(OurWebThreeStubServer* _server, Main* _main); QNatspecExpressionEvaluator(OurWebThreeStubServer* _server, Main* _main);
virtual ~QNatspecExpressionEvaluator(); virtual ~QNatspecExpressionEvaluator();
QString evalExpression(QString const& _expression); QString evalExpression(QString const& _expression) const;
private: private:
OurWebThreeStubServer* m_server; OurWebThreeStubServer* m_server;
Main* m_main; Main* m_main;
}; };

Loading…
Cancel
Save