2018-07-07 15:29:45 +00:00
|
|
|
import {detectSeries} from 'async';
|
|
|
|
|
2018-05-11 16:27:27 +00:00
|
|
|
var EmbarkJS = {
|
2018-06-15 14:04:36 +00:00
|
|
|
onReady: function (cb) {
|
2018-06-10 16:11:34 +00:00
|
|
|
if (typeof (__embarkContext) === 'undefined') {
|
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
return __embarkContext.execWhenReady(cb);
|
|
|
|
}
|
2018-05-11 16:27:27 +00:00
|
|
|
};
|
2016-08-18 11:45:08 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.isNewWeb3 = function (web3Obj) {
|
2018-06-10 16:11:34 +00:00
|
|
|
var _web3 = web3Obj || (new Web3());
|
2017-12-13 22:10:33 +00:00
|
|
|
if (typeof(_web3.version) === "string") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return parseInt(_web3.version.api.split('.')[0], 10) >= 1;
|
2017-10-07 19:20:51 +00:00
|
|
|
};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Contract = function (options) {
|
|
|
|
var self = this;
|
|
|
|
var i, abiElement;
|
|
|
|
var ContractClass;
|
|
|
|
|
|
|
|
this.abi = options.abi;
|
|
|
|
this.address = options.address;
|
|
|
|
this.gas = options.gas;
|
|
|
|
this.code = '0x' + options.code;
|
|
|
|
//this.web3 = options.web3 || web3;
|
|
|
|
this.web3 = options.web3;
|
|
|
|
if (!this.web3 && typeof (web3) !== 'undefined') {
|
|
|
|
this.web3 = web3;
|
|
|
|
} else if (!this.web3) {
|
|
|
|
this.web3 = window.web3;
|
|
|
|
}
|
2018-06-10 14:07:02 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
if (EmbarkJS.isNewWeb3(this.web3)) {
|
|
|
|
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
|
|
|
|
ContractClass.setProvider(this.web3.currentProvider);
|
|
|
|
ContractClass.options.data = this.code;
|
2018-06-18 18:02:02 +00:00
|
|
|
ContractClass.options.from = this.from || this.web3.eth.defaultAccount;
|
2018-06-15 14:04:36 +00:00
|
|
|
ContractClass.abi = ContractClass.options.abi;
|
|
|
|
ContractClass.address = this.address;
|
|
|
|
ContractClass.gas = this.gas;
|
|
|
|
|
|
|
|
let originalMethods = Object.keys(ContractClass);
|
|
|
|
|
|
|
|
ContractClass._jsonInterface.forEach((abi) => {
|
|
|
|
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");
|
|
|
|
return;
|
|
|
|
}
|
2018-06-10 14:07:02 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
if (!abi.inputs) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-10 14:07:02 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
let numExpectedInputs = abi.inputs.length;
|
2018-06-10 14:07:02 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
if (abi.type === 'function' && abi.constant) {
|
|
|
|
ContractClass[abi.name] = function () {
|
|
|
|
let options = {}, cb = null, args = Array.from(arguments || []).slice(0, numExpectedInputs);
|
|
|
|
if (typeof (arguments[numExpectedInputs]) === 'function') {
|
|
|
|
cb = arguments[numExpectedInputs];
|
|
|
|
} else if (typeof (arguments[numExpectedInputs]) === 'object') {
|
|
|
|
options = arguments[numExpectedInputs];
|
|
|
|
cb = arguments[numExpectedInputs + 1];
|
|
|
|
}
|
2018-06-10 14:07:02 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
let ref = ContractClass.methods[abi.name];
|
|
|
|
let call = ref.apply(ref, ...arguments).call;
|
|
|
|
return call.apply(call, []);
|
|
|
|
};
|
|
|
|
} else if (abi.type === 'function') {
|
|
|
|
ContractClass[abi.name] = function () {
|
|
|
|
let options = {}, cb = null, args = Array.from(arguments || []).slice(0, numExpectedInputs);
|
|
|
|
if (typeof (arguments[numExpectedInputs]) === 'function') {
|
|
|
|
cb = arguments[numExpectedInputs];
|
|
|
|
} else if (typeof (arguments[numExpectedInputs]) === 'object') {
|
|
|
|
options = arguments[numExpectedInputs];
|
|
|
|
cb = arguments[numExpectedInputs + 1];
|
2018-06-10 14:07:02 +00:00
|
|
|
}
|
2018-06-09 23:29:32 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
let ref = ContractClass.methods[abi.name];
|
|
|
|
let send = ref.apply(ref, args).send;
|
|
|
|
return send.apply(send, [options, cb]);
|
|
|
|
};
|
|
|
|
} else if (abi.type === 'event') {
|
|
|
|
ContractClass[abi.name] = function (options, cb) {
|
|
|
|
let ref = ContractClass.events[abi.name];
|
|
|
|
return ref.apply(ref, [options, cb]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return ContractClass;
|
|
|
|
} else {
|
|
|
|
ContractClass = this.web3.eth.contract(this.abi);
|
2018-05-30 19:34:36 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
this.eventList = [];
|
2017-10-07 19:20:51 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
if (this.abi) {
|
|
|
|
for (i = 0; i < this.abi.length; i++) {
|
|
|
|
abiElement = this.abi[i];
|
|
|
|
if (abiElement.type === 'event') {
|
|
|
|
this.eventList.push(abiElement.name);
|
2017-03-17 14:02:26 +00:00
|
|
|
}
|
2017-10-07 19:20:51 +00:00
|
|
|
}
|
2018-06-15 14:04:36 +00:00
|
|
|
}
|
2018-05-30 19:35:07 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
var messageEvents = function () {
|
|
|
|
this.cb = function () {
|
2017-10-07 19:20:51 +00:00
|
|
|
};
|
2018-06-15 14:04:36 +00:00
|
|
|
};
|
2017-02-28 01:32:26 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
messageEvents.prototype.then = function (cb) {
|
|
|
|
this.cb = cb;
|
|
|
|
};
|
2017-02-28 01:32:26 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
messageEvents.prototype.error = function (err) {
|
|
|
|
return err;
|
|
|
|
};
|
2017-02-28 01:32:26 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
this._originalContractObject = ContractClass.at(this.address);
|
|
|
|
this._methods = Object.getOwnPropertyNames(this._originalContractObject).filter(function (p) {
|
|
|
|
// TODO: check for forbidden properties
|
|
|
|
if (self.eventList.indexOf(p) >= 0) {
|
2017-03-17 14:02:26 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
self[p] = function () {
|
|
|
|
var promise = new messageEvents();
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
args.push(function (err, result) {
|
|
|
|
if (err) {
|
|
|
|
promise.error(err);
|
|
|
|
} else {
|
|
|
|
promise.cb(result);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
self._originalContractObject[p].apply(self._originalContractObject[p], args);
|
|
|
|
return promise;
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
} else if (typeof self._originalContractObject[p] === 'function') {
|
|
|
|
self[p] = function (_args) {
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
var fn = self._originalContractObject[p];
|
|
|
|
var props = self.abi.find((x) => x.name == p);
|
|
|
|
|
|
|
|
var promise = new Promise(function (resolve, reject) {
|
|
|
|
args.push(function (err, transaction) {
|
|
|
|
promise.tx = transaction;
|
2017-10-07 19:20:51 +00:00
|
|
|
if (err) {
|
2018-06-15 14:04:36 +00:00
|
|
|
return reject(err);
|
2017-10-07 19:20:51 +00:00
|
|
|
}
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
var getConfirmation = function () {
|
|
|
|
self.web3.eth.getTransactionReceipt(transaction, function (err, receipt) {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
2017-10-07 19:20:51 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
if (receipt !== null) {
|
|
|
|
return resolve(receipt);
|
|
|
|
}
|
2016-08-18 11:45:08 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
setTimeout(getConfirmation, 1000);
|
|
|
|
});
|
|
|
|
};
|
2017-03-17 14:02:26 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
if (typeof transaction !== "string" || props.constant) {
|
|
|
|
resolve(transaction);
|
|
|
|
} else {
|
|
|
|
getConfirmation();
|
|
|
|
}
|
|
|
|
});
|
2016-08-18 11:45:08 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
fn.apply(fn, args);
|
|
|
|
});
|
2016-08-18 11:45:08 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
return promise;
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2017-03-12 21:59:21 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Contract.prototype.deploy = function (args, _options) {
|
|
|
|
var self = this;
|
|
|
|
var contractParams;
|
|
|
|
var options = _options || {};
|
|
|
|
|
|
|
|
contractParams = args || [];
|
|
|
|
|
|
|
|
contractParams.push({
|
|
|
|
from: this.web3.eth.accounts[0],
|
|
|
|
data: this.code,
|
|
|
|
gas: options.gas || 800000
|
|
|
|
});
|
|
|
|
|
|
|
|
var contractObject = this.web3.eth.contract(this.abi);
|
|
|
|
|
|
|
|
var promise = new Promise(function (resolve, reject) {
|
|
|
|
contractParams.push(function (err, transaction) {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
} else if (transaction.address !== undefined) {
|
|
|
|
resolve(new EmbarkJS.Contract({
|
|
|
|
abi: self.abi,
|
|
|
|
code: self.code,
|
|
|
|
address: transaction.address
|
|
|
|
}));
|
|
|
|
}
|
2017-03-17 14:02:26 +00:00
|
|
|
});
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
// returns promise
|
|
|
|
// deploys contract
|
|
|
|
// wraps it around EmbarkJS.Contract
|
|
|
|
contractObject["new"].apply(contractObject, contractParams);
|
|
|
|
});
|
2017-03-17 14:02:26 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
|
|
|
|
return promise;
|
2016-08-18 11:45:08 +00:00
|
|
|
};
|
|
|
|
|
2017-04-02 18:12:12 +00:00
|
|
|
EmbarkJS.Contract.prototype.new = EmbarkJS.Contract.prototype.deploy;
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Contract.prototype.at = function (address) {
|
|
|
|
return new EmbarkJS.Contract({abi: this.abi, code: this.code, address: address});
|
2017-04-02 18:12:12 +00:00
|
|
|
};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Contract.prototype.send = function (value, unit, _options) {
|
2017-04-02 18:12:12 +00:00
|
|
|
var options, wei;
|
|
|
|
if (typeof unit === 'object') {
|
|
|
|
options = unit;
|
|
|
|
wei = value;
|
|
|
|
} else {
|
|
|
|
options = _options || {};
|
|
|
|
wei = this.web3.toWei(value, unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
options.to = this.address;
|
|
|
|
options.value = wei;
|
|
|
|
|
|
|
|
this.web3.eth.sendTransaction(options);
|
|
|
|
};
|
|
|
|
|
2017-03-17 14:02:26 +00:00
|
|
|
EmbarkJS.Storage = {};
|
2017-03-13 13:38:30 +00:00
|
|
|
|
2018-04-30 05:56:43 +00:00
|
|
|
EmbarkJS.Storage.Providers = {};
|
2017-03-13 13:38:30 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Storage.saveText = function (text) {
|
2018-01-10 16:31:26 +00:00
|
|
|
if (!this.currentStorage) {
|
|
|
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
|
|
|
}
|
|
|
|
return this.currentStorage.saveText(text);
|
2016-08-26 11:01:22 +00:00
|
|
|
};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Storage.get = function (hash) {
|
2018-01-10 16:31:26 +00:00
|
|
|
if (!this.currentStorage) {
|
|
|
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
|
|
|
}
|
|
|
|
return this.currentStorage.get(hash);
|
2017-03-14 15:39:09 +00:00
|
|
|
};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Storage.uploadFile = function (inputSelector) {
|
2018-01-10 16:31:26 +00:00
|
|
|
if (!this.currentStorage) {
|
|
|
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
|
|
|
}
|
|
|
|
return this.currentStorage.uploadFile(inputSelector);
|
2017-03-18 14:14:19 +00:00
|
|
|
};
|
2017-03-14 15:39:09 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Storage.getUrl = function (hash) {
|
2018-01-10 16:31:26 +00:00
|
|
|
if (!this.currentStorage) {
|
|
|
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
|
|
|
}
|
|
|
|
return this.currentStorage.getUrl(hash);
|
2017-03-18 14:14:19 +00:00
|
|
|
};
|
2017-03-14 15:39:09 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Storage.registerProvider = function (providerName, obj) {
|
2017-12-28 00:10:05 +00:00
|
|
|
EmbarkJS.Storage.Providers[providerName] = obj;
|
2017-03-14 15:39:09 +00:00
|
|
|
};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Storage.setProvider = function (provider, options) {
|
2017-12-28 01:57:10 +00:00
|
|
|
let providerObj = this.Providers[provider];
|
2017-03-17 14:02:26 +00:00
|
|
|
|
2017-12-28 01:57:10 +00:00
|
|
|
if (!providerObj) {
|
2017-12-28 00:10:05 +00:00
|
|
|
throw new Error('Unknown storage provider');
|
2018-06-15 14:04:36 +00:00
|
|
|
}
|
2016-08-26 11:01:22 +00:00
|
|
|
|
2017-12-28 01:57:10 +00:00
|
|
|
this.currentStorage = providerObj;
|
2016-08-26 11:01:22 +00:00
|
|
|
|
2017-12-28 01:57:10 +00:00
|
|
|
return providerObj.setProvider(options);
|
2016-08-26 11:01:22 +00:00
|
|
|
};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Storage.isAvailable = function () {
|
2018-05-25 07:13:57 +00:00
|
|
|
if (!this.currentStorage) {
|
|
|
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
|
|
|
}
|
2018-04-30 05:56:43 +00:00
|
|
|
return this.currentStorage.isAvailable();
|
|
|
|
};
|
|
|
|
|
2018-07-07 15:29:45 +00:00
|
|
|
EmbarkJS.Storage.setProviders = async function (dappConnOptions) {
|
|
|
|
try {
|
|
|
|
await detectSeries(dappConnOptions, async (dappConn, callback) => {
|
|
|
|
if(dappConn === '$BZZ' || dappConn.provider === 'swarm'){
|
|
|
|
let options = dappConn;
|
|
|
|
if(dappConn === '$BZZ') options = {"useOnlyGivenProvider": true};
|
|
|
|
try{
|
|
|
|
await EmbarkJS.Storage.setProvider('swarm', options);
|
|
|
|
let isAvailable = await EmbarkJS.Storage.isAvailable();
|
|
|
|
callback(null, isAvailable);
|
|
|
|
}catch(err){
|
|
|
|
callback(null, false); // catch errors for when bzz object not initialised but config has requested it to be used
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(dappConn.provider === 'ipfs') {
|
|
|
|
// set the provider then check the connection, if true, use that provider, else, check next provider
|
|
|
|
try{
|
|
|
|
await EmbarkJS.Storage.setProvider('ipfs', dappConn);
|
|
|
|
let isAvailable = await EmbarkJS.Storage.isAvailable();
|
|
|
|
callback(null, isAvailable);
|
|
|
|
} catch(err) {
|
|
|
|
callback(null, false); // catch but keep looping by not passing err to callback
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, function(err, result){
|
|
|
|
if(!result) throw new Error('Could not connect to a storage provider using any of the dappConnections in the storage config');
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
throw new Error('Failed to connect to a storage provider: ' + err.message);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-17 14:02:26 +00:00
|
|
|
EmbarkJS.Messages = {};
|
2016-08-21 14:42:42 +00:00
|
|
|
|
2017-12-28 01:19:41 +00:00
|
|
|
EmbarkJS.Messages.Providers = {};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Messages.registerProvider = function (providerName, obj) {
|
2017-12-28 01:19:41 +00:00
|
|
|
EmbarkJS.Messages.Providers[providerName] = obj;
|
2017-07-24 11:27:52 +00:00
|
|
|
};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Messages.setProvider = function (provider, options) {
|
2017-12-28 02:04:12 +00:00
|
|
|
let providerObj = this.Providers[provider];
|
2017-12-28 01:19:41 +00:00
|
|
|
|
2017-12-28 02:04:12 +00:00
|
|
|
if (!providerObj) {
|
|
|
|
throw new Error('Unknown messages provider');
|
|
|
|
}
|
2017-12-28 01:19:41 +00:00
|
|
|
|
2017-12-28 02:04:12 +00:00
|
|
|
this.currentMessages = providerObj;
|
2017-12-28 01:19:41 +00:00
|
|
|
|
2017-12-28 02:04:12 +00:00
|
|
|
return providerObj.setProvider(options);
|
2016-08-21 14:42:42 +00:00
|
|
|
};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Messages.isAvailable = function () {
|
2018-04-30 05:56:43 +00:00
|
|
|
return this.currentMessages.isAvailable();
|
|
|
|
};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Messages.sendMessage = function (options) {
|
2018-01-10 16:31:26 +00:00
|
|
|
if (!this.currentMessages) {
|
|
|
|
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
|
|
|
|
}
|
|
|
|
return this.currentMessages.sendMessage(options);
|
2016-08-21 14:42:42 +00:00
|
|
|
};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Messages.listenTo = function (options, callback) {
|
2018-01-10 16:31:26 +00:00
|
|
|
if (!this.currentMessages) {
|
|
|
|
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
|
|
|
|
}
|
2018-05-02 16:10:11 +00:00
|
|
|
return this.currentMessages.listenTo(options, callback);
|
2016-08-21 14:42:42 +00:00
|
|
|
};
|
|
|
|
|
2018-05-22 17:59:22 +00:00
|
|
|
EmbarkJS.Names = {};
|
|
|
|
|
|
|
|
EmbarkJS.Names.Providers = {};
|
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Names.registerProvider = function (providerName, obj) {
|
2018-05-22 17:59:22 +00:00
|
|
|
EmbarkJS.Names.Providers[providerName] = obj;
|
2018-06-15 14:04:36 +00:00
|
|
|
};
|
2018-05-22 17:59:22 +00:00
|
|
|
|
2018-06-15 14:04:36 +00:00
|
|
|
EmbarkJS.Names.setProvider = function (provider, options) {
|
2018-05-22 17:59:22 +00:00
|
|
|
let providerObj = this.Providers[provider];
|
|
|
|
|
|
|
|
if (!providerObj) {
|
|
|
|
throw new Error('Unknown name system provider');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.currentNameSystems = providerObj;
|
|
|
|
|
|
|
|
return providerObj.setProvider(options);
|
|
|
|
};
|
|
|
|
|
|
|
|
// resolve resolves a name into an identifier of some kind
|
2018-07-10 19:59:42 +00:00
|
|
|
EmbarkJS.Names.resolve = function (name, callback) {
|
2018-05-22 17:59:22 +00:00
|
|
|
if (!this.currentNameSystems) {
|
|
|
|
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
|
|
|
}
|
2018-07-10 19:59:42 +00:00
|
|
|
return this.currentNameSystems.resolve(name, callback);
|
2018-06-15 14:04:36 +00:00
|
|
|
};
|
2018-05-22 17:59:22 +00:00
|
|
|
|
|
|
|
// the reverse of resolve, resolves using an identifier to get to a name
|
2018-07-10 19:59:42 +00:00
|
|
|
EmbarkJS.Names.lookup = function (identifier, callback) {
|
2018-05-22 17:59:22 +00:00
|
|
|
if (!this.currentNameSystems) {
|
|
|
|
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
|
|
|
}
|
2018-07-10 19:59:42 +00:00
|
|
|
return this.currentNameSystems.lookup(identifier, callback);
|
2018-06-15 14:04:36 +00:00
|
|
|
};
|
2018-05-22 17:59:22 +00:00
|
|
|
|
2018-07-11 16:47:15 +00:00
|
|
|
EmbarkJS.Names.isAvailable = function () {
|
|
|
|
return this.currentNameSystems.isAvailable();
|
2018-06-15 14:04:36 +00:00
|
|
|
};
|
2018-05-22 17:59:22 +00:00
|
|
|
|
|
|
|
// To Implement
|
|
|
|
|
2018-06-15 17:32:48 +00:00
|
|
|
|
2018-06-11 17:41:26 +00:00
|
|
|
// register a name
|
2018-05-22 17:59:22 +00:00
|
|
|
EmbarkJS.Names.register = function(name, options) {
|
2018-06-15 17:32:48 +00:00
|
|
|
if (!this.currentNameSystems) {
|
|
|
|
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
|
|
|
}
|
|
|
|
return this.currentNameSystems.register(name, options);
|
2018-07-10 19:59:42 +00:00
|
|
|
};
|
2018-05-22 17:59:22 +00:00
|
|
|
|
2017-07-24 11:27:52 +00:00
|
|
|
EmbarkJS.Utils = {
|
2018-06-15 14:04:36 +00:00
|
|
|
fromAscii: function (str) {
|
2017-07-24 11:27:52 +00:00
|
|
|
var _web3 = new Web3();
|
|
|
|
return _web3.utils ? _web3.utils.fromAscii(str) : _web3.fromAscii(str);
|
2017-10-09 12:59:02 +00:00
|
|
|
},
|
2018-06-15 14:04:36 +00:00
|
|
|
toAscii: function (str) {
|
2017-10-09 12:59:02 +00:00
|
|
|
var _web3 = new Web3();
|
|
|
|
return _web3.utils.toAscii(str);
|
2017-07-24 11:27:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-06-10 16:55:59 +00:00
|
|
|
export default EmbarkJS;
|