Commit 7669354e authored by Dave Hoover's avatar Dave Hoover

Deploying and linking libraries in Web3 context

parent f738864d
......@@ -418,18 +418,14 @@ UniversalDApp.prototype.getCallButton = function (args) {
if (isConstructor) {
if (args.bytecode.indexOf('_') >= 0) {
replaceOutput($result, $('<span>Deploying and linking required libraries...</span>'));
if (self.options.vm) {
self.linkBytecode(args.contractName, function (err, bytecode) {
if (err) {
replaceOutput($result, $('<span/>').text('Error deploying required libraries: ' + err));
} else {
args.bytecode = bytecode;
handleCallButtonClick(ev, $result);
}
});
} else {
replaceOutput($result, $('<span>Contract needs to be linked to a library, this is only supported in the JavaScript VM for now.</span>'));
}
self.linkBytecode(args.contractName, function (err, bytecode) {
if (err) {
replaceOutput($result, $('<span/>').text('Error deploying required libraries: ' + err));
} else {
args.bytecode = bytecode;
handleCallButtonClick(ev, $result);
}
});
return;
} else {
data = args.bytecode + data;
......@@ -481,19 +477,6 @@ UniversalDApp.prototype.getCallButton = function (args) {
} else if (args.abi.constant && !isConstructor) {
replaceOutput($result, getReturnOutput(result));
} else {
function tryTillResponse (txhash, done) {
this.web3.eth.getTransactionReceipt(result, testResult);
function testResult (err, address) {
if (!err && !address) {
setTimeout(function () { tryTillResponse(txhash, done); }, 500);
} else {
done(err, address);
}
}
}
tryTillResponse(result, function (err, result) {
if (err) {
replaceOutput($result, $('<span/>').text(err).addClass('error'));
......@@ -578,8 +561,16 @@ UniversalDApp.prototype.deployLibrary = function (contractName, cb) {
if (err) {
return cb(err);
}
self.getContractByName(contractName).address = result.createdAddress;
cb(err, result.createdAddress);
if (self.options.vm) {
self.getContractByName(contractName).address = result.createdAddress;
cb(err, result.createdAddress);
} else {
tryTillResponse(result, function(err, finalResult) {
if (err) return cb(err);
self.getContractByName(contractName).address = finalResult.contractAddress;
cb(null, finalResult.contractAddress);
});
}
});
}
};
......@@ -658,4 +649,17 @@ UniversalDApp.prototype.runTx = function (data, args, cb) {
}
};
function tryTillResponse (txhash, done) {
this.web3.eth.getTransactionReceipt(txhash, testResult);
function testResult (err, address) {
if (!err && !address) {
setTimeout(function () { tryTillResponse(txhash, done); }, 500);
} else {
done(err, address);
}
}
}
module.exports = UniversalDApp;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment