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);
}
function accumulatorToBN(accumulator, numLimbs) {
const shift = 256;
let newBN = (new BN(accumulator[0].toString(16), 16))
for (let i = 1; i < numLimbs; i++) {
newBN.iushln(shift);
const limb = (new BN(accumulator[i].toString(16), 16))
newBN.iadd(limb);
}
return newBN;
}
function newBigNumber(value) {
var hex = new BigNumber(value).toString(16);
return new BN(hex, 16);
}
value: function(extra) {
var value = new BN(utils.randomHexString(seed + '-numberValue-' + extra, 1, size / 8).substring(2), 16);
if (sign) {
var signBit = (new BN(1)).shln(size - 1);
if (!signBit.and(value).isZero()) {
value = value.maskn(size - 1).mul(new BN(-1));
}
}
if (value.isNeg()) {
return '-0x' + value.toString('hex').substring(1);
}
return '0x' + value.toString('hex');
}
}
const clean_input = function(str) {
if ((typeof str === 'number') || (str.isBigNumber === true) || BN.isBN(str)) str = `${ str.toString(16) }`
if ((!str) || (typeof str !== 'string') || (str === '0x')) str = '00'
if (str.indexOf('0x') === 0) str = str.substr(2)
if (str.length % 2 === 1) str = `0${str}`
return `0x${str}`
}
const clean_input = function(str) {
if ((typeof str === 'number') || (str.isBigNumber === true) || BN.isBN(str)) str = `${ str.toString(16) }`
if ((!str) || (typeof str !== 'string') || (str === '0x')) str = '00'
if (str.indexOf('0x') === 0) str = str.substr(2)
if (str.length % 2 === 1) str = `0${str}`
return `0x${str}`
}
function feeSubtracted(x, n = 1) {
assert(BN.isBN(x), "x is not a bignum")
assert(Number.isInteger(n) && n > 0, "n is not a valid integer")
const result = x.mul(FEE_DENOMINATOR_MINUS_ONE).div(FEE_DENOMINATOR)
return n === 1 ? result : feeSubtracted(result, n - 1)
}
function feeAdded(x) {
assert(BN.isBN(x))
return x.mul(feeDenominator).div(feeDenominatorMinusOne)
}
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("---------");
}
}
function hrpToSat (hrpString, outputString) {
let millisatoshisBN = hrpToMillisat(hrpString, false)
if (!millisatoshisBN.mod(new BN(1000, 10)).eq(new BN(0, 10))) {
throw new Error('Amount is outside of valid range')
}
let result = millisatoshisBN.div(new BN(1000, 10))
return outputString ? result.toString() : result
}