embark-area-51/lib/modules/code_generator/code_templates/utils.js.ejs

56 lines
1.1 KiB
Plaintext
Raw Normal View History

2017-10-14 00:01:35 +00:00
function __reduce(arr, memo, iteratee, cb) {
if (typeof cb !== 'function') {
if (typeof memo === 'function' && typeof iteratee === 'function') {
cb = iteratee;
iteratee = memo;
memo = [];
} else {
throw new TypeError('expected callback to be a function');
}
}
if (!Array.isArray(arr)) {
cb(new TypeError('expected an array'));
return;
}
if (typeof iteratee !== 'function') {
cb(new TypeError('expected iteratee to be a function'));
return;
}
(function next(i, acc) {
if (i === arr.length) {
cb(null, acc);
return;
}
iteratee(acc, arr[i], function(err, val) {
if (err) {
cb(err);
return;
}
next(i + 1, val);
});
})(0, memo);
};
function __isNewWeb3_1() {
return (typeof(web3.version) === "string");
};
function __getAccounts(cb) {
if (__isNewWeb3_1()) {
web3.eth.getAccounts().then(function(accounts) {
cb(null, accounts);
2018-05-11 19:59:18 +00:00
return null;
}).catch(function(err) {
cb(err);
2018-05-11 19:59:18 +00:00
return null;
});
return;
}
web3.eth.getAccounts(cb);
};