mirror of https://github.com/embarklabs/embark.git
clean up, improve setting the web3 object
This commit is contained in:
parent
3185a1374c
commit
e119007f76
13
js/embark.js
13
js/embark.js
|
@ -19,27 +19,28 @@ EmbarkJS.Contract = function(options) {
|
||||||
this.address = options.address;
|
this.address = options.address;
|
||||||
this.code = '0x' + options.code;
|
this.code = '0x' + options.code;
|
||||||
//this.web3 = options.web3 || web3;
|
//this.web3 = options.web3 || web3;
|
||||||
this.web3 = options.web3 || window.web3;
|
this.web3 = options.web3;
|
||||||
|
if (!this.web3 && typeof ('web3') !== 'undefined') {
|
||||||
|
this.web3 = web3;
|
||||||
|
} else {
|
||||||
|
this.web3 = window.web3;
|
||||||
|
}
|
||||||
|
|
||||||
if (EmbarkJS.isNewWeb3()) {
|
if (EmbarkJS.isNewWeb3()) {
|
||||||
// TODO:
|
|
||||||
// add default **from** address
|
|
||||||
// add gasPrice
|
|
||||||
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
|
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
|
||||||
ContractClass.setProvider(this.web3.currentProvider);
|
ContractClass.setProvider(this.web3.currentProvider);
|
||||||
ContractClass.options.data = this.code;
|
ContractClass.options.data = this.code;
|
||||||
|
ContractClass.options.from = this.from;
|
||||||
ContractClass.abi = ContractClass.options.abi;
|
ContractClass.abi = ContractClass.options.abi;
|
||||||
ContractClass.address = this.address;
|
ContractClass.address = this.address;
|
||||||
|
|
||||||
let originalMethods = Object.keys(ContractClass);
|
let originalMethods = Object.keys(ContractClass);
|
||||||
let methods = [];
|
|
||||||
|
|
||||||
ContractClass._jsonInterface.forEach((abi) => {
|
ContractClass._jsonInterface.forEach((abi) => {
|
||||||
if (originalMethods.indexOf(abi.name) >= 0) {
|
if (originalMethods.indexOf(abi.name) >= 0) {
|
||||||
console.log(abi.name + " is a reserved word and cannot be used as a contract method, property or event");
|
console.log(abi.name + " is a reserved word and cannot be used as a contract method, property or event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
methods.push(abi.name);
|
|
||||||
|
|
||||||
if (!abi.inputs) {
|
if (!abi.inputs) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue