initial embarkjs implementation with support for client side deploys

This commit is contained in:
Iuri Matias 2016-08-18 07:45:08 -04:00
parent 88381bdda1
commit d1dae1bade
5 changed files with 5570 additions and 12 deletions

View File

@ -1,3 +1,9 @@
/*globals $, SimpleStorage, document*/
var addToLog = function(txt) {
$(".logs").append("<br>" + txt);
};
$(document).ready(function() {
$("button.set").click(function() {
@ -7,13 +13,10 @@ $(document).ready(function() {
});
$("button.get").click(function() {
var value = SimpleStorage.get().toNumber();
$(".value").html(value);
SimpleStorage.get().then(function(value) {
$(".value").html(value.toNumber());
});
addToLog("SimpleStorage.get()");
});
var addToLog = function(txt) {
$(".logs").append("<br>" + txt);
}
});

5476
js/bluebird.js Normal file

File diff suppressed because it is too large Load Diff

77
js/embark.js Normal file
View File

@ -0,0 +1,77 @@
EmbarkJS = {
};
options = {
abi: {},
address: {},
code: "",
options: {},
web3: {},
deployPromise: {}
};
//result += "\n" + className + "Abi = " + abi + ";";
//result += "\n" + className + "Contract = web3.eth.contract(" + className + "Abi);";
//result += "\n" + className + " = " + className + "Contract.at('" + contract.deployedAddress + "');";
EmbarkJS.Contract = function(options) {
var self = this;
this.abi = options.abi;
this.address = options.address;
this.code = options.code;
this.web3 = options.web3 || web3;
var ContractClass = web3.eth.contract(this.abi);
this._originalContractObject = ContractClass.at(this.address);
this._methods = Object.getOwnPropertyNames(this._originalContractObject).filter(function (p) {
// TODO: check for forbidden properties
if (typeof self._originalContractObject[p] === 'function') {
self[p] = Promise.promisify(self._originalContractObject[p]);
return true;
}
return false;
});
};
EmbarkJS.Contract.prototype.deploy = function(args) {
var self = this;
var contractParams;
contractParams = args;
contractParams.push({
from: web3.eth.accounts[0],
data: this.code,
gasLimit: 500000,
gasPrice: 10000000000000
});
var contractObject = web3.eth.contract(this.abi);
var promise = new Promise(function(resolve, reject) {
contractParams.push(function(err, transaction) {
console.log("callback");
if (err) {
console.log("error");
reject(err);
} else if (transaction.address !== undefined) {
console.log("address contract: " + transaction.address);
resolve(new EmbarkJS.Contract({abi: self.abi, code: self.code, address: transaction.address}));
}
});
console.log(contractParams);
// returns promise
// deploys contract
// wraps it around EmbarkJS.Contract
contractObject["new"].apply(contractObject, contractParams);
});
return promise;
};

View File

@ -26,11 +26,13 @@ ABIGenerator.prototype.generateContracts = function() {
var abi = JSON.stringify(contract.abiDefinition);
console.log('address is ' + contract.deployedAddress);
//console.log('address is ' + contract.deployedAddress);
result += "\n" + className + "Abi = " + abi + ";";
result += "\n" + className + "Contract = web3.eth.contract(" + className + "Abi);";
result += "\n" + className + " = " + className + "Contract.at('" + contract.deployedAddress + "');";
//result += "\n" + className + "Abi = " + abi + ";";
//result += "\n" + className + "Contract = web3.eth.contract(" + className + "Abi);";
//result += "\n" + className + " = " + className + "Contract.at('" + contract.deployedAddress + "');";
result += "\n" + className + " = new EmbarkJS.Contract({abi: " + abi + ", address: '" + contract.deployedAddress + "', code: '" + contract.code + "'});";
}
return result;

View File

@ -67,7 +67,7 @@ var Embark = {
}).map(function(file) {
console.log("reading " + file);
if (file === 'embark.js') {
return fs.readFileSync("../js/web3.js") + "\n" + abi;
return fs.readFileSync("../js/bluebird.js") + fs.readFileSync("../js/web3.js") + fs.readFileSync("../js/embark.js") + "\n" + abi;
} else {
return fs.readFileSync(file);
}