Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function checkIfString(val: string | number) {
if (typeof val === 'string') {
if (/[g-z]/i.test(val)) {
// if 'latest' 'earliest' 'pending'
return val;
}
return /^0x/i.test(val) ? val : '0x' + new BN(val).toString(16);
}
return '0x' + val.toString(16);
}
async printCurrentState() {
for (let i = 0; i < Object.keys(this.reputations).length; i += 1) {
const key = Object.keys(this.reputations)[i];
const decimalValue = new BN(this.reputations[key].slice(2, 66), 16);
const keyElements = ReputationMiner.breakKeyInToElements(key);
const [colonyAddress, , userAddress] = keyElements;
const skillId = parseInt(keyElements[1], 16);
console.log("colonyAddress", colonyAddress);
console.log("userAddress", userAddress);
console.log("skillId", skillId);
console.log("value", decimalValue.toString());
console.log("---------");
}
}
const fixedFromDecimal = (value: number | string | BigNumber | BN, decimals: number) => {
if (value instanceof BN) {
return value;
}
const d = new BN(10 ** decimals);
if (typeof value === 'number') {
return new BN(value).mul(d);
}
const valueBigNumber = typeof value === 'string' ? new BigNumber(value) : value;
const dBigNumber = new BigNumber(d.toString(10));
return new BN(valueBigNumber.times(dBigNumber).toString(), 10);
};
function toBN(value) {
const hex = BigNumber.from(value).toHexString();
if (hex[0] === "-") {
return (new BN("-" + hex.substring(3), 16));
}
return new BN(hex.substring(2), 16);
}
function throwFault(fault, operation, value) {
function toBN(value) {
const hex = BigNumber.from(value).toHexString();
if (hex[0] === "-") {
return (new BN("-" + hex.substring(3), 16));
}
return new BN(hex.substring(2), 16);
}
function throwFault(fault, operation, value) {