Merge pull request #43 from redsquirrel/lib-linking-in-web3

Deploying and linking libraries in Web3 context
pull/1/head
chriseth 9 years ago
commit 2d91cce38c
  1. 58
      src/universal-dapp.js

@ -424,18 +424,14 @@ UniversalDApp.prototype.getCallButton = function (args) {
if (isConstructor) { if (isConstructor) {
if (args.bytecode.indexOf('_') >= 0) { if (args.bytecode.indexOf('_') >= 0) {
replaceOutput($result, $('<span>Deploying and linking required libraries...</span>')); replaceOutput($result, $('<span>Deploying and linking required libraries...</span>'));
if (self.options.vm) { self.linkBytecode(args.contractName, function (err, bytecode) {
self.linkBytecode(args.contractName, function (err, bytecode) { if (err) {
if (err) { replaceOutput($result, $('<span/>').text('Error deploying required libraries: ' + err));
replaceOutput($result, $('<span/>').text('Error deploying required libraries: ' + err)); } else {
} else { args.bytecode = bytecode;
args.bytecode = bytecode; handleCallButtonClick(ev, $result);
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>'));
}
return; return;
} else { } else {
data = args.bytecode + data; data = args.bytecode + data;
@ -487,19 +483,6 @@ UniversalDApp.prototype.getCallButton = function (args) {
} else if (args.abi.constant && !isConstructor) { } else if (args.abi.constant && !isConstructor) {
replaceOutput($result, getReturnOutput(result)); replaceOutput($result, getReturnOutput(result));
} else { } 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) { tryTillResponse(result, function (err, result) {
if (err) { if (err) {
replaceOutput($result, $('<span/>').text(err).addClass('error')); replaceOutput($result, $('<span/>').text(err).addClass('error'));
@ -584,8 +567,16 @@ UniversalDApp.prototype.deployLibrary = function (contractName, cb) {
if (err) { if (err) {
return cb(err); return cb(err);
} }
self.getContractByName(contractName).address = result.createdAddress; if (self.options.vm) {
cb(err, result.createdAddress); 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);
});
}
}); });
} }
}; };
@ -664,4 +655,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; module.exports = UniversalDApp;

Loading…
Cancel
Save