Browse Source

add UrlHint Registration in NameReg

cl-refactor
yann300 10 years ago
parent
commit
6b4fd27dfd
  1. 18
      alethzero/DappLoader.cpp
  2. 4
      alethzero/DappLoader.h
  3. 4
      alethzero/MainWin.cpp
  4. 19
      mix/qml/DeploymentDialog.qml
  5. 45
      mix/qml/js/NetworkDeployment.js

18
alethzero/DappLoader.cpp

@ -39,13 +39,10 @@ using namespace dev;
using namespace dev::eth;
using namespace dev::crypto;
Address c_registrar = Address("6a16d3a392de03c67c1880acca6a9d650015c8ae");
Address c_urlHint = Address("43c6d48ef55d10a786eb3e244824c820d5359b43");
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,12 +58,11 @@ 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;
@ -85,7 +81,12 @@ DappLocation DappLoader::resolveAppUri(QString const& _uri)
++partIndex;
}
string32 contentUrl = abiOut<string32>(web3()->ethereum()->call(c_urlHint, abiIn("url(bytes32)", contentHash)).output);
string32 urlHintName = ZeroString32;
QByteArray utf8 = QString("UrlHint").toUtf8();
std::copy(utf8.data(), utf8.data() + utf8.size(), urlHintName.data());
Address urlHint = abiOut<Address>(web3()->ethereum()->call(m_nameReg, abiIn("addr(bytes32)", urlHintName)).output);
string32 contentUrl = abiOut<string32>(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;

4
alethzero/DappLoader.h

@ -29,6 +29,7 @@
#include <QUrl>
#include <QNetworkAccessManager>
#include <libdevcore/FixedHash.h>
#include <libdevcrypto/Common.h>
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<QUrl, dev::h256> m_uriHashes;
std::set<QUrl> m_pageUrls;
QByteArray m_web3Js;
dev::Address m_nameReg;
};

4
alethzero/MainWin.cpp

@ -173,7 +173,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());
@ -196,7 +196,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);

19
mix/qml/DeploymentDialog.qml

@ -19,7 +19,6 @@ Dialog {
visible: false
property alias applicationUrlEth: applicationUrlEth.text
property alias applicationUrlHttp: applicationUrlHttp.text
property alias urlHintContract: urlHintAddr.text
property alias localPackageUrl: localPackageUrl.text
property string packageHash
property string packageBase64
@ -44,6 +43,7 @@ Dialog {
id: 0
}];
console.log(packageHash);
TransactionHelper.rpcCall(requests, function(arg1, arg2)
{
modelAccounts.clear();
@ -271,12 +271,15 @@ Dialog {
DefaultLabel
{
text: qsTr("Root Registrar address:")
visible: false //still use it for now in dev env.
}
DefaultTextField
{
Layout.preferredWidth: 350
id: registrarAddr
text: "c6d9d2cd449a754c494264e1809c50e34d64562b"
visible: false
}
DefaultLabel
@ -449,20 +452,6 @@ Dialog {
Layout.preferredWidth: 350
id: localPackageUrl
readOnly: true
}
DefaultLabel
{
Layout.preferredWidth: 355
text: qsTr("URL Hint contract address:")
}
DefaultTextField
{
Layout.preferredWidth: 350
id: urlHintAddr
enabled: rowRegister.isOkToRegister()
}
DefaultLabel

45
mix/qml/js/NetworkDeployment.js

@ -224,11 +224,6 @@ function checkEthPath(dappUrl, callBack)
{
// the first owned registrar must have been created to follow the path.
var str = clientModel.encodeStringParam(dappUrl[0]);
console.log("prarma = " + str + " " + deploymentDialog.eth);
console.log("0x5a3a05bd" + str);
console.log(deploymentDialog.currentAccount);
console.log(deploymentDialog.eth);
var requests = [];
requests.push({
//subRegistrar()
@ -271,7 +266,7 @@ function checkRegistration(dappUrl, addr, callBack)
//getOwner()
jsonrpc: "2.0",
method: "eth_call",
params: [ { "gas" : 2000, "from": deploymentDialog.currentAccount, "to": '0x' + addr, "data": "0x02571be3" } ],
params: [ { "gas" : 2000, "from": deploymentDialog.currentAccount, "to": '0x' + addr, "data": "0x02571be3" }, "pending" ],
id: jsonRpcRequestId++
});
@ -279,7 +274,7 @@ function checkRegistration(dappUrl, addr, callBack)
//register()
jsonrpc: "2.0",
method: "eth_call",
params: [ { "from": deploymentDialog.currentAccount, "to": '0x' + addr, "data": "0x5a3a05bd" + str } ],
params: [ { "from": deploymentDialog.currentAccount, "to": '0x' + addr, "data": "0x5a3a05bd" + str }, "pending" ],
id: jsonRpcRequestId++
});
@ -363,11 +358,8 @@ function registerContentHash(registrar, callBack)
var txt = qsTr("Finalizing Dapp registration ...");
deploymentStepChanged(txt);
console.log(txt);
console.log(" 45 64 564 0 " + deploymentDialog.packageHash);
var requests = [];
var paramTitle = clientModel.encodeStringParam(projectModel.projectTitle);
console.log("ggg " + paramTitle);
console.log('registrar ' + registrar);
requests.push({
//setContent()
@ -384,19 +376,40 @@ function registerContentHash(registrar, callBack)
function registerToUrlHint()
{
deploymentStepChanged(qsTr("Registering application Resources (" + deploymentDialog.applicationUrlHttp) + ") ...");
urlHintAddress(function(urlHint){
var requests = [];
var paramUrlHttp = clientModel.encodeStringParam(deploymentDialog.applicationUrlHttp);
requests.push({
//urlHint => suggestUrl
jsonrpc: "2.0",
method: "eth_sendTransaction",
params: [ { "to": '0x' + urlHint, "from": deploymentDialog.currentAccount, "gas": "0xfffff", "data": "0x584e86ad" + deploymentDialog.packageHash + paramUrlHttp } ],
id: jsonRpcRequestId++
});
rpcCall(requests, function (httpRequest, response) {
deploymentComplete();
});
});
}
function urlHintAddress(callBack)
{
var requests = [];
var paramUrlHttp = clientModel.encodeStringParam(deploymentDialog.applicationUrlHttp);
console.log("package hash " + deploymentDialog.packageHash);
var urlHint = clientModel.encodeStringParam("UrlHint");
requests.push({
//urlHint => suggestUrl
//registrar: get UrlHint addr
jsonrpc: "2.0",
method: "eth_sendTransaction",
params: [ { "to": '0x' + deploymentDialog.urlHintContract, "from": deploymentDialog.currentAccount, "gas": "0xfffff", "data": "0x584e86ad" + deploymentDialog.packageHash + paramUrlHttp } ],
method: "eth_call",
params: [ { "to": '0x' + deploymentDialog.eth, "from": deploymentDialog.currentAccount, "gas": "0xfffff", "data": "0x3b3b57de" + urlHint }, "pending" ],
id: jsonRpcRequestId++
});
rpcCall(requests, function (httpRequest, response) {
deploymentComplete();
var res = JSON.parse(response);
callBack(normalizeAddress(res[0].result));
});
}

Loading…
Cancel
Save