mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-15 08:14:29 +00:00
lint embarkjs
This commit is contained in:
parent
6991215b40
commit
cb8e0e9d3e
95
js/embark.js
95
js/embark.js
@ -1,5 +1,5 @@
|
|||||||
var EmbarkJS = {
|
var EmbarkJS = {
|
||||||
onReady: function(cb) {
|
onReady: function (cb) {
|
||||||
if (typeof (__embarkContext) === 'undefined') {
|
if (typeof (__embarkContext) === 'undefined') {
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
@ -7,7 +7,7 @@ var EmbarkJS = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.isNewWeb3 = function(web3Obj) {
|
EmbarkJS.isNewWeb3 = function (web3Obj) {
|
||||||
var _web3 = web3Obj || (new Web3());
|
var _web3 = web3Obj || (new Web3());
|
||||||
if (typeof(_web3.version) === "string") {
|
if (typeof(_web3.version) === "string") {
|
||||||
return true;
|
return true;
|
||||||
@ -15,7 +15,7 @@ EmbarkJS.isNewWeb3 = function(web3Obj) {
|
|||||||
return parseInt(_web3.version.api.split('.')[0], 10) >= 1;
|
return parseInt(_web3.version.api.split('.')[0], 10) >= 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Contract = function(options) {
|
EmbarkJS.Contract = function (options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var i, abiElement;
|
var i, abiElement;
|
||||||
var ContractClass;
|
var ContractClass;
|
||||||
@ -56,7 +56,7 @@ EmbarkJS.Contract = function(options) {
|
|||||||
let numExpectedInputs = abi.inputs.length;
|
let numExpectedInputs = abi.inputs.length;
|
||||||
|
|
||||||
if (abi.type === 'function' && abi.constant) {
|
if (abi.type === 'function' && abi.constant) {
|
||||||
ContractClass[abi.name] = function() {
|
ContractClass[abi.name] = function () {
|
||||||
let options = {}, cb = null, args = Array.from(arguments || []).slice(0, numExpectedInputs);
|
let options = {}, cb = null, args = Array.from(arguments || []).slice(0, numExpectedInputs);
|
||||||
if (typeof (arguments[numExpectedInputs]) === 'function') {
|
if (typeof (arguments[numExpectedInputs]) === 'function') {
|
||||||
cb = arguments[numExpectedInputs];
|
cb = arguments[numExpectedInputs];
|
||||||
@ -70,7 +70,7 @@ EmbarkJS.Contract = function(options) {
|
|||||||
return call.apply(call, []);
|
return call.apply(call, []);
|
||||||
};
|
};
|
||||||
} else if (abi.type === 'function') {
|
} else if (abi.type === 'function') {
|
||||||
ContractClass[abi.name] = function() {
|
ContractClass[abi.name] = function () {
|
||||||
let options = {}, cb = null, args = Array.from(arguments || []).slice(0, numExpectedInputs);
|
let options = {}, cb = null, args = Array.from(arguments || []).slice(0, numExpectedInputs);
|
||||||
if (typeof (arguments[numExpectedInputs]) === 'function') {
|
if (typeof (arguments[numExpectedInputs]) === 'function') {
|
||||||
cb = arguments[numExpectedInputs];
|
cb = arguments[numExpectedInputs];
|
||||||
@ -84,10 +84,10 @@ EmbarkJS.Contract = function(options) {
|
|||||||
return send.apply(send, [options, cb]);
|
return send.apply(send, [options, cb]);
|
||||||
};
|
};
|
||||||
} else if (abi.type === 'event') {
|
} else if (abi.type === 'event') {
|
||||||
ContractClass[abi.name] = function(options, cb) {
|
ContractClass[abi.name] = function (options, cb) {
|
||||||
let ref = ContractClass.events[abi.name];
|
let ref = ContractClass.events[abi.name];
|
||||||
return ref.apply(ref, [options, cb]);
|
return ref.apply(ref, [options, cb]);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -106,27 +106,28 @@ EmbarkJS.Contract = function(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var messageEvents = function() {
|
var messageEvents = function () {
|
||||||
this.cb = function() {};
|
this.cb = function () {
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
messageEvents.prototype.then = function(cb) {
|
messageEvents.prototype.then = function (cb) {
|
||||||
this.cb = cb;
|
this.cb = cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
messageEvents.prototype.error = function(err) {
|
messageEvents.prototype.error = function (err) {
|
||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
|
|
||||||
this._originalContractObject = ContractClass.at(this.address);
|
this._originalContractObject = ContractClass.at(this.address);
|
||||||
this._methods = Object.getOwnPropertyNames(this._originalContractObject).filter(function(p) {
|
this._methods = Object.getOwnPropertyNames(this._originalContractObject).filter(function (p) {
|
||||||
// TODO: check for forbidden properties
|
// TODO: check for forbidden properties
|
||||||
if (self.eventList.indexOf(p) >= 0) {
|
if (self.eventList.indexOf(p) >= 0) {
|
||||||
|
|
||||||
self[p] = function() {
|
self[p] = function () {
|
||||||
var promise = new messageEvents();
|
var promise = new messageEvents();
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = Array.prototype.slice.call(arguments);
|
||||||
args.push(function(err, result) {
|
args.push(function (err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
promise.error(err);
|
promise.error(err);
|
||||||
} else {
|
} else {
|
||||||
@ -139,20 +140,20 @@ EmbarkJS.Contract = function(options) {
|
|||||||
};
|
};
|
||||||
return true;
|
return true;
|
||||||
} else if (typeof self._originalContractObject[p] === 'function') {
|
} else if (typeof self._originalContractObject[p] === 'function') {
|
||||||
self[p] = function(_args) {
|
self[p] = function (_args) {
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = Array.prototype.slice.call(arguments);
|
||||||
var fn = self._originalContractObject[p];
|
var fn = self._originalContractObject[p];
|
||||||
var props = self.abi.find((x) => x.name == p);
|
var props = self.abi.find((x) => x.name == p);
|
||||||
|
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function (resolve, reject) {
|
||||||
args.push(function(err, transaction) {
|
args.push(function (err, transaction) {
|
||||||
promise.tx = transaction;
|
promise.tx = transaction;
|
||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var getConfirmation = function() {
|
var getConfirmation = function () {
|
||||||
self.web3.eth.getTransactionReceipt(transaction, function(err, receipt) {
|
self.web3.eth.getTransactionReceipt(transaction, function (err, receipt) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
@ -165,7 +166,7 @@ EmbarkJS.Contract = function(options) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof(transaction) !== "string" || props.constant) {
|
if (typeof transaction !== "string" || props.constant) {
|
||||||
resolve(transaction);
|
resolve(transaction);
|
||||||
} else {
|
} else {
|
||||||
getConfirmation();
|
getConfirmation();
|
||||||
@ -184,7 +185,7 @@ EmbarkJS.Contract = function(options) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Contract.prototype.deploy = function(args, _options) {
|
EmbarkJS.Contract.prototype.deploy = function (args, _options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var contractParams;
|
var contractParams;
|
||||||
var options = _options || {};
|
var options = _options || {};
|
||||||
@ -199,8 +200,8 @@ EmbarkJS.Contract.prototype.deploy = function(args, _options) {
|
|||||||
|
|
||||||
var contractObject = this.web3.eth.contract(this.abi);
|
var contractObject = this.web3.eth.contract(this.abi);
|
||||||
|
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function (resolve, reject) {
|
||||||
contractParams.push(function(err, transaction) {
|
contractParams.push(function (err, transaction) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else if (transaction.address !== undefined) {
|
} else if (transaction.address !== undefined) {
|
||||||
@ -224,11 +225,11 @@ EmbarkJS.Contract.prototype.deploy = function(args, _options) {
|
|||||||
|
|
||||||
EmbarkJS.Contract.prototype.new = EmbarkJS.Contract.prototype.deploy;
|
EmbarkJS.Contract.prototype.new = EmbarkJS.Contract.prototype.deploy;
|
||||||
|
|
||||||
EmbarkJS.Contract.prototype.at = function(address) {
|
EmbarkJS.Contract.prototype.at = function (address) {
|
||||||
return new EmbarkJS.Contract({ abi: this.abi, code: this.code, address: address });
|
return new EmbarkJS.Contract({abi: this.abi, code: this.code, address: address});
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Contract.prototype.send = function(value, unit, _options) {
|
EmbarkJS.Contract.prototype.send = function (value, unit, _options) {
|
||||||
var options, wei;
|
var options, wei;
|
||||||
if (typeof unit === 'object') {
|
if (typeof unit === 'object') {
|
||||||
options = unit;
|
options = unit;
|
||||||
@ -248,39 +249,39 @@ EmbarkJS.Storage = {};
|
|||||||
|
|
||||||
EmbarkJS.Storage.Providers = {};
|
EmbarkJS.Storage.Providers = {};
|
||||||
|
|
||||||
EmbarkJS.Storage.saveText = function(text) {
|
EmbarkJS.Storage.saveText = function (text) {
|
||||||
if (!this.currentStorage) {
|
if (!this.currentStorage) {
|
||||||
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
||||||
}
|
}
|
||||||
return this.currentStorage.saveText(text);
|
return this.currentStorage.saveText(text);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.get = function(hash) {
|
EmbarkJS.Storage.get = function (hash) {
|
||||||
if (!this.currentStorage) {
|
if (!this.currentStorage) {
|
||||||
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
||||||
}
|
}
|
||||||
return this.currentStorage.get(hash);
|
return this.currentStorage.get(hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.uploadFile = function(inputSelector) {
|
EmbarkJS.Storage.uploadFile = function (inputSelector) {
|
||||||
if (!this.currentStorage) {
|
if (!this.currentStorage) {
|
||||||
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
||||||
}
|
}
|
||||||
return this.currentStorage.uploadFile(inputSelector);
|
return this.currentStorage.uploadFile(inputSelector);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.getUrl = function(hash) {
|
EmbarkJS.Storage.getUrl = function (hash) {
|
||||||
if (!this.currentStorage) {
|
if (!this.currentStorage) {
|
||||||
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
||||||
}
|
}
|
||||||
return this.currentStorage.getUrl(hash);
|
return this.currentStorage.getUrl(hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.registerProvider = function(providerName, obj) {
|
EmbarkJS.Storage.registerProvider = function (providerName, obj) {
|
||||||
EmbarkJS.Storage.Providers[providerName] = obj;
|
EmbarkJS.Storage.Providers[providerName] = obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
EmbarkJS.Storage.setProvider = function (provider, options) {
|
||||||
let providerObj = this.Providers[provider];
|
let providerObj = this.Providers[provider];
|
||||||
|
|
||||||
if (!providerObj) {
|
if (!providerObj) {
|
||||||
@ -292,7 +293,7 @@ EmbarkJS.Storage.setProvider = function(provider, options) {
|
|||||||
return providerObj.setProvider(options);
|
return providerObj.setProvider(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.isAvailable = function(){
|
EmbarkJS.Storage.isAvailable = function () {
|
||||||
if (!this.currentStorage) {
|
if (!this.currentStorage) {
|
||||||
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
||||||
}
|
}
|
||||||
@ -303,11 +304,11 @@ EmbarkJS.Messages = {};
|
|||||||
|
|
||||||
EmbarkJS.Messages.Providers = {};
|
EmbarkJS.Messages.Providers = {};
|
||||||
|
|
||||||
EmbarkJS.Messages.registerProvider = function(providerName, obj) {
|
EmbarkJS.Messages.registerProvider = function (providerName, obj) {
|
||||||
EmbarkJS.Messages.Providers[providerName] = obj;
|
EmbarkJS.Messages.Providers[providerName] = obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages.setProvider = function(provider, options) {
|
EmbarkJS.Messages.setProvider = function (provider, options) {
|
||||||
let providerObj = this.Providers[provider];
|
let providerObj = this.Providers[provider];
|
||||||
|
|
||||||
if (!providerObj) {
|
if (!providerObj) {
|
||||||
@ -319,18 +320,18 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
|
|||||||
return providerObj.setProvider(options);
|
return providerObj.setProvider(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages.isAvailable = function(){
|
EmbarkJS.Messages.isAvailable = function () {
|
||||||
return this.currentMessages.isAvailable();
|
return this.currentMessages.isAvailable();
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages.sendMessage = function(options) {
|
EmbarkJS.Messages.sendMessage = function (options) {
|
||||||
if (!this.currentMessages) {
|
if (!this.currentMessages) {
|
||||||
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
|
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
|
||||||
}
|
}
|
||||||
return this.currentMessages.sendMessage(options);
|
return this.currentMessages.sendMessage(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages.listenTo = function(options, callback) {
|
EmbarkJS.Messages.listenTo = function (options, callback) {
|
||||||
if (!this.currentMessages) {
|
if (!this.currentMessages) {
|
||||||
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
|
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
|
||||||
}
|
}
|
||||||
@ -341,11 +342,11 @@ EmbarkJS.Names = {};
|
|||||||
|
|
||||||
EmbarkJS.Names.Providers = {};
|
EmbarkJS.Names.Providers = {};
|
||||||
|
|
||||||
EmbarkJS.Names.registerProvider = function(providerName, obj) {
|
EmbarkJS.Names.registerProvider = function (providerName, obj) {
|
||||||
EmbarkJS.Names.Providers[providerName] = obj;
|
EmbarkJS.Names.Providers[providerName] = obj;
|
||||||
}
|
};
|
||||||
|
|
||||||
EmbarkJS.Names.setProvider = function(provider, options) {
|
EmbarkJS.Names.setProvider = function (provider, options) {
|
||||||
let providerObj = this.Providers[provider];
|
let providerObj = this.Providers[provider];
|
||||||
|
|
||||||
if (!providerObj) {
|
if (!providerObj) {
|
||||||
@ -358,20 +359,20 @@ EmbarkJS.Names.setProvider = function(provider, options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// resolve resolves a name into an identifier of some kind
|
// resolve resolves a name into an identifier of some kind
|
||||||
EmbarkJS.Names.resolve = function(name) {
|
EmbarkJS.Names.resolve = function (name) {
|
||||||
if (!this.currentNameSystems) {
|
if (!this.currentNameSystems) {
|
||||||
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
||||||
}
|
}
|
||||||
return this.currentNameSystems.resolve(name);
|
return this.currentNameSystems.resolve(name);
|
||||||
}
|
};
|
||||||
|
|
||||||
// the reverse of resolve, resolves using an identifier to get to a name
|
// the reverse of resolve, resolves using an identifier to get to a name
|
||||||
EmbarkJS.Names.lookup = function(identifier) {
|
EmbarkJS.Names.lookup = function (identifier) {
|
||||||
if (!this.currentNameSystems) {
|
if (!this.currentNameSystems) {
|
||||||
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
||||||
}
|
}
|
||||||
return this.currentNameSystems.lookup(identifier);
|
return this.currentNameSystems.lookup(identifier);
|
||||||
}
|
};
|
||||||
|
|
||||||
// To Implement
|
// To Implement
|
||||||
|
|
||||||
@ -383,11 +384,11 @@ EmbarkJS.Names.register = function(name, options) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
EmbarkJS.Utils = {
|
EmbarkJS.Utils = {
|
||||||
fromAscii: function(str) {
|
fromAscii: function (str) {
|
||||||
var _web3 = new Web3();
|
var _web3 = new Web3();
|
||||||
return _web3.utils ? _web3.utils.fromAscii(str) : _web3.fromAscii(str);
|
return _web3.utils ? _web3.utils.fromAscii(str) : _web3.fromAscii(str);
|
||||||
},
|
},
|
||||||
toAscii: function(str) {
|
toAscii: function (str) {
|
||||||
var _web3 = new Web3();
|
var _web3 = new Web3();
|
||||||
return _web3.utils.toAscii(str);
|
return _web3.utils.toAscii(str);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user