@iexec/iexec-oracle-factory-wrapper
Version:
A wrapper for creating API based oracles for ethereum on the top of iExec
26 lines • 853 B
JavaScript
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Big } from 'big.js';
const sortObjKeys = (obj) => Object.keys(obj)
.sort()
.reduce((acc, curr) => {
if (typeof obj[curr] === 'object') {
acc[curr] = sortObjKeys(obj[curr]);
}
else {
acc[curr] = obj[curr];
}
return acc;
}, {});
const formatParamsJson = (obj) => JSON.stringify(sortObjKeys(obj));
const formatOracleGetNumber = (resultBn) => {
const resultBig = new Big(resultBn.toString()).times(new Big('1e-18'));
try {
resultBig.constructor.strict = true;
return resultBig.toNumber();
}
catch (e) {
throw new Error(`Converting ${resultBig.toString()} to number will result in losing precision`);
}
};
export { sortObjKeys, formatParamsJson, formatOracleGetNumber };
//# sourceMappingURL=format.js.map