diff --git a/alethzero/DappLoader.cpp b/alethzero/DappLoader.cpp
index 69555521d..6ac1afbcb 100644
--- a/alethzero/DappLoader.cpp
+++ b/alethzero/DappLoader.cpp
@@ -39,13 +39,10 @@ using namespace dev;
using namespace dev::eth;
using namespace dev::crypto;
-Address c_registrar = Address("0000000000000000000000000000000000000a28");
-Address c_urlHint = Address("0000000000000000000000000000000000000a29");
-
QString contentsOfQResource(std::string const& res);
-DappLoader::DappLoader(QObject* _parent, WebThreeDirect* _web3):
- QObject(_parent), m_web3(_web3)
+DappLoader::DappLoader(QObject* _parent, WebThreeDirect* _web3, Address _nameReg):
+ QObject(_parent), m_web3(_web3), m_nameReg(_nameReg)
{
connect(&m_net, &QNetworkAccessManager::finished, this, &DappLoader::downloadComplete);
}
@@ -61,31 +58,35 @@ DappLocation DappLoader::resolveAppUri(QString const& _uri)
std::reverse(parts.begin(), parts.end());
parts.append(url.path().split('/', QString::SkipEmptyParts));
- Address address = c_registrar;
+ Address address = m_nameReg;
Address lastAddress;
int partIndex = 0;
h256 contentHash;
-
while (address && partIndex < parts.length())
{
lastAddress = address;
string32 name = ZeroString32;
QByteArray utf8 = parts[partIndex].toUtf8();
std::copy(utf8.data(), utf8.data() + utf8.size(), name.data());
- address = abiOut
(web3()->ethereum()->call(address, abiIn("addr(string32)", name)).output);
+ address = abiOut(web3()->ethereum()->call(address, abiIn("subRegistrar(bytes32)", name)).output);
domainParts.append(parts[partIndex]);
if (!address)
{
//we have the address of the last part, try to get content hash
- contentHash = abiOut(web3()->ethereum()->call(lastAddress, abiIn("content(string32)", name)).output);
+ contentHash = abiOut(web3()->ethereum()->call(lastAddress, abiIn("content(bytes32)", name)).output);
if (!contentHash)
throw dev::Exception() << errinfo_comment("Can't resolve address");
}
++partIndex;
}
- string32 contentUrl = abiOut(web3()->ethereum()->call(c_urlHint, abiIn("url(hash256)", contentHash)).output);
+ string32 urlHintName = ZeroString32;
+ QByteArray utf8 = QString("UrlHint").toUtf8();
+ std::copy(utf8.data(), utf8.data() + utf8.size(), urlHintName.data());
+
+ Address urlHint = abiOut(web3()->ethereum()->call(m_nameReg, abiIn("addr(bytes32)", urlHintName)).output);
+ string32 contentUrl = abiOut(web3()->ethereum()->call(urlHint, abiIn("url(bytes32)", contentHash)).output);
QString domain = domainParts.join('/');
parts.erase(parts.begin(), parts.begin() + partIndex);
QString path = parts.join('/');
@@ -237,6 +238,7 @@ void DappLoader::loadDapp(QString const& _uri)
DappLocation location = resolveAppUri(_uri);
contentUri = location.contentUri;
hash = location.contentHash;
+ uri = contentUri;
}
QNetworkRequest request(contentUri);
m_uriHashes[uri] = hash;
diff --git a/alethzero/DappLoader.h b/alethzero/DappLoader.h
index deba62c68..f2d3ee5e5 100644
--- a/alethzero/DappLoader.h
+++ b/alethzero/DappLoader.h
@@ -29,6 +29,7 @@
#include
#include
#include
+#include
namespace dev
{
@@ -69,7 +70,7 @@ class DappLoader: public QObject
{
Q_OBJECT
public:
- DappLoader(QObject* _parent, dev::WebThreeDirect* _web3);
+ DappLoader(QObject* _parent, dev::WebThreeDirect* _web3, dev::Address _nameReg);
///Load a new DApp. Resolves a name with a name reg contract. Asynchronous. dappReady is emitted once everything is read, dappError othervise
///@param _uri Eth name path
void loadDapp(QString const& _uri);
@@ -97,5 +98,6 @@ private:
std::map m_uriHashes;
std::set m_pageUrls;
QByteArray m_web3Js;
+ dev::Address m_nameReg;
};
diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp
index 023351361..4963d2742 100644
--- a/alethzero/MainWin.cpp
+++ b/alethzero/MainWin.cpp
@@ -174,7 +174,7 @@ Main::Main(QWidget *parent) :
ui->blockCount->setText(QString("PV%1.%2 D%3 %4-%5 v%6").arg(eth::c_protocolVersion).arg(eth::c_minorProtocolVersion).arg(c_databaseVersion).arg(QString::fromStdString(ProofOfWork::name())).arg(ProofOfWork::revision()).arg(dev::Version));
connect(ui->ourAccounts->model(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(ourAccountsRowsMoved()));
-
+
QSettings s("ethereum", "alethzero");
m_networkConfig = s.value("peers").toByteArray();
bytesConstRef network((byte*)m_networkConfig.data(), m_networkConfig.size());
@@ -197,7 +197,7 @@ Main::Main(QWidget *parent) :
});
m_dappHost.reset(new DappHost(8081));
- m_dappLoader = new DappLoader(this, web3());
+ m_dappLoader = new DappLoader(this, web3(), getNameReg());
connect(m_dappLoader, &DappLoader::dappReady, this, &Main::dappLoaded);
connect(m_dappLoader, &DappLoader::pageReady, this, &Main::pageLoaded);
// ui->webView->page()->settings()->setAttribute(QWebEngineSettings::DeveloperExtrasEnabled, true);
diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp
index 7863eb31d..61a3dee1f 100644
--- a/mix/ClientModel.cpp
+++ b/mix/ClientModel.cpp
@@ -151,6 +151,39 @@ QString ClientModel::encodeAbiString(QString _string)
return QString::fromStdString(toHex(encoder.encodeBytes(_string)));
}
+QString ClientModel::encodeStringParam(QString const& _param)
+{
+ ContractCallDataEncoder encoder;
+ return QString::fromStdString(toHex(encoder.encodeStringParam(_param, 32)));
+}
+
+QStringList ClientModel::encodeParams(QVariant const& _param, QString const& _contract, QString const& _function)
+{
+ QStringList ret;
+ CompiledContract const& compilerRes = m_codeModel->contract(_contract);
+ QList paramsList;
+ shared_ptr contractDef = compilerRes.sharedContract();
+ if (_contract == _function)
+ paramsList = contractDef->constructor()->parametersList();
+ else
+ for (QFunctionDefinition* tf: contractDef->functionsList())
+ if (tf->name() == _function)
+ {
+ paramsList = tf->parametersList();
+ break;
+ }
+ if (paramsList.length() > 0)
+ for (QVariableDeclaration* var: paramsList)
+ {
+ ContractCallDataEncoder encoder;
+ QSolidityType const* type = var->type();
+ QVariant value = _param.toMap().value(var->name());
+ encoder.encode(value, type->type());
+ ret.push_back(QString::fromStdString(toHex(encoder.encodedData())));
+ }
+ return ret;
+}
+
QVariantMap ClientModel::contractAddresses() const
{
QVariantMap res;
diff --git a/mix/ClientModel.h b/mix/ClientModel.h
index 714b81431..9b0529ae6 100644
--- a/mix/ClientModel.h
+++ b/mix/ClientModel.h
@@ -26,8 +26,10 @@
#include
#include