Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getMinerData: async function(args, callback) {
var minerEthAddress = args[0];
var minerData = null;
if(web3utils.isAddress(minerEthAddress.toString()) ){
minerData = await self.getMinerData(minerEthAddress);
}else{
console.log('getMinerData error: not a valid address')
}
var minDiff = self.getPoolMinimumShareDifficulty();
if(minerData.varDiff < minDiff)
{
minerData.varDiff = minDiff;
}
// console.log('meep',minerData)
callback(null, JSON.stringify( minerData ) );
},
static approveFeeBatch (tasks, options) {
if (options && !web3Utils.isAddress (options.from)) {
return Promise.reject ('Missing account option');
}
let promise = null;
for (let i = 0; i < tasks.length; i++) {
const task = tasks[i];
if (!task.checkWorkerVerified ()) {
// Don't allow computations for an unverified worker
promise = Promise.reject ('Cannot continue with task ' + task._worker.signer +
'because it failed verification: ' + task._worker.verified.err);
break;
}
}
if (promise === null) {
let fee = 0;
var outputTransactionFormatter = function (tx) {
if (tx.blockNumber !== null)
tx.blockNumber = utils.hexToNumber(tx.blockNumber);
if (tx.transactionIndex !== null)
tx.transactionIndex = utils.hexToNumber(tx.transactionIndex);
tx.nonce = utils.hexToNumber(tx.nonce);
tx.gas = utils.hexToNumber(tx.gas);
tx.gasPrice = outputBigNumberFormatter(tx.gasPrice);
tx.value = outputBigNumberFormatter(tx.value);
if (tx.to && utils.isAddress(tx.to)) { // tx.to could be `0x0` or `null` while contract creation
tx.to = utils.toChecksumAddress(tx.to);
} else {
tx.to = null; // set to `null` if invalid address
}
if (tx.from) {
tx.from = utils.toChecksumAddress(tx.from);
}
return tx;
};
let userAddress = _userAddress;
let base = 10;
let skillId = _skillId.toString();
if (skillId.slice(0, 2) === "0x") {
// We've been passed a hex string
skillId = skillId.slice(2);
base = 16;
}
let isAddress = web3Utils.isAddress(colonyAddress);
// TODO should we return errors here?
if (!isAddress) {
return false;
}
isAddress = web3Utils.isAddress(userAddress);
if (!isAddress) {
return false;
}
if (colonyAddress.substring(0, 2) === "0x") {
colonyAddress = colonyAddress.slice(2);
}
if (userAddress.substring(0, 2) === "0x") {
userAddress = userAddress.slice(2);
}
colonyAddress = colonyAddress.toLowerCase();
userAddress = userAddress.toLowerCase();
const key = `0x${new BN(colonyAddress, 16).toString(16, 40)}${new BN(skillId.toString(), base).toString(16, 64)}${new BN(
userAddress,
16
).toString(16, 40)}`;
return key;
await this.web3Store.getWeb3Promise.then(async () => {
if(Web3Utils.isAddress(this.web3Store.defaultAccount) && tokenAddress !== "0x000000000000000000000000000000000000bEEF"){
this.tokenAddress = tokenAddress;
await this.getDecimals(tokenAddress)
await this.getBalance()
await this.getAllowance()
await this.getCurrentFee()
this.getTokenSymbol(tokenAddress)
this.getEthBalance()
this.getArrayLimit()
} else {
this.tokenAddress = tokenAddress;
await this.getCurrentFee()
await this.getEthBalance()
this.getArrayLimit()
this.decimals = 18;
this.defAccTokenBalance = this.ethBalance;
}
selectAccount(public_address)
{
if(web3Utils.isAddress(public_address))
{
if(this.hasAddress(public_address)){
vaultData.selected_account_address = public_address;
console.log('\n')
console.log('Selected account: ', public_address)
}else{
//console.log('\n')
//console.log(public_address, ' is not an ethereum address saved in your miner. View your accounts with "account list" and select one of those. The ability to import an account does not exist and this is a "good practice" security measure. ' )
account = {
address: public_address,
privateKey: null ,
accountType: 'readOnly'
}
vaultData.account_list.push(account)
export const isEthereumAddress = (value: string) => isAddress(value)
try {
value = value.replace(/^0x/, '');
if (value.length % 2) {
value = '0' + value;
}
const _value = exports.hex2bytes(value);
const valueBytes = new Uint8Array(32);
valueBytes.set(_value, 32 - _value.length);
tx.setValue(valueBytes);
}
catch (err) {
throw err;
}
}
if (to) {
if (utils.isAddress(to)) {
tx[`setTo${_version}`](_to);
}
else {
throw new Error(`Invalid to address`);
}
}
if (validUntilBlock === undefined || isNaN(+validUntilBlock)) {
throw new Error(`ValidUntilBlock should be set`);
}
else {
tx.setValidUntilBlock(+validUntilBlock);
}
if (_chainId === undefined) {
throw new Error(`Chain Id should be set`);
}
else {
const isRecipientValid = (current) => {
return web3Utils.isAddress(current)
}
const validateAddress = Joi.string().custom(value => {
return web3Utils.isAddress(value)
})