Skip to content

Commit

Permalink
Merge pull request #45 from nicov-iov/fix/D1-822/silence-other-spammy…
Browse files Browse the repository at this point in the history
…-logs

fix: remove spammy logs (no matching event and method reverted)
  • Loading branch information
IOVgomezdn authored Dec 19, 2023
2 parents 1eedbbc + 6580f55 commit adf0a5f
Show file tree
Hide file tree
Showing 22 changed files with 4,919 additions and 8,097 deletions.
3 changes: 1 addition & 2 deletions dist/examples/getDeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ function help(msg) {
console.log(`Set environment variable URL to change node url`);
console.log(`Example: export URL=http://localhost:4444`);
process.exit(0);
}
//# sourceMappingURL=getDeployment.js.map
}
9 changes: 4 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, "BcSearch", { enumerable: true, get: function () {return _BcSearch.BcSearch;} });Object.defineProperty(exports, "Contract", { enumerable: true, get: function () {return _Contract.default;} });Object.defineProperty(exports, "ContractParser", { enumerable: true, get: function () {return _ContractParser.ContractParser;} });exports.default = exports.abi = void 0;var _ContractParser = require("./lib/ContractParser");
"use strict";Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, "ContractParser", { enumerable: true, get: function () {return _ContractParser.ContractParser;} });Object.defineProperty(exports, "BcSearch", { enumerable: true, get: function () {return _BcSearch.BcSearch;} });Object.defineProperty(exports, "Contract", { enumerable: true, get: function () {return _Contract.default;} });exports.default = exports.abi = void 0;var _ContractParser = require("./lib/ContractParser");
var _BcSearch = require("./lib/BcSearch");
var _Contract = _interopRequireDefault(require("./lib/Contract"));
var _bridgeAbi = require("./lib/nativeContracts/bridgeAbi");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
const abi = exports.abi = { bridge: _bridgeAbi.getBridgeAbi };var _default = exports.default =
const abi = { bridge: _bridgeAbi.getBridgeAbi };exports.abi = abi;var _default =

_ContractParser.ContractParser;

// HOTFIX: because the dependency @ethersproject/abi:5.7.0 spam the logs with 'duplicate definition' warning, this temporary fix should silence those messages until a newer version of the library fixes the issue
const originalConsoleLog = console.log;
exports.default = _default;const originalConsoleLog = console.log;
console.log = function (message) {
if (!String(message).includes('duplicate definition')) {
originalConsoleLog(message);
}
};
//# sourceMappingURL=index.js.map
};
5 changes: 2 additions & 3 deletions dist/lib/Abi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions dist/lib/BcSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var _rskUtils = require("@rsksmart/rsk-utils");

function BcSearch(nod3) {
const getBlock = (hashOrNumber) => {
const getBlock = hashOrNumber => {
return nod3.eth.getBlock(hashOrNumber);
};

Expand All @@ -27,7 +27,7 @@ function BcSearch(nod3) {
};

const deploymentBlock = (address, highBlock, lowBlock) => {
return block((blockNumber) => isContractAtBlock(address, blockNumber), highBlock, lowBlock);
return block(blockNumber => isContractAtBlock(address, blockNumber), highBlock, lowBlock);
};
const searchReceipt = async (transactions, cb) => {
for (let tx of transactions) {
Expand All @@ -44,11 +44,11 @@ function BcSearch(nod3) {
try {
blockNumber = blockNumber || (await deploymentBlock(address, highBlock));
block = block || (await nod3.eth.getBlock(blockNumber, true));
let transactions = block.transactions.filter((tx) => !(0, _rskUtils.isAddress)(tx.to));
let transaction = await searchReceipt(transactions, (receipt) => receipt.contractAddress === address);
let transactions = block.transactions.filter(tx => !(0, _rskUtils.isAddress)(tx.to));
let transaction = await searchReceipt(transactions, receipt => receipt.contractAddress === address);
if (!transaction) {// internal transactions
blockTrace = blockTrace || (await nod3.trace.block(block.hash));
let internalTx = blockTrace.find((trace) => isItxDeployment(address, trace));
let internalTx = blockTrace.find(trace => isItxDeployment(address, trace));
if (internalTx) transaction = { internalTx };
}
if (transaction) transaction.timestamp = block.timestamp;
Expand All @@ -59,7 +59,6 @@ function BcSearch(nod3) {
};

return Object.freeze({ block, deploymentBlock, deploymentTx, isItxDeployment });
}var _default = exports.default =
}var _default =

BcSearch;
//# sourceMappingURL=BcSearch.js.map
BcSearch;exports.default = _default;
7 changes: 3 additions & 4 deletions dist/lib/Contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ function Contract(abi, { address, nod3 } = {}) {
if (!abi || typeof abi !== 'object') throw new Error('Invalid abi');
const contractInterface = new _abi.Interface(abi);

const at = (newAddress) => {
const at = newAddress => {
address = newAddress;
};

const setNod3 = (nod3Instance) => {
const setNod3 = nod3Instance => {
nod3 = nod3Instance;
};

Expand Down Expand Up @@ -37,5 +37,4 @@ function Contract(abi, { address, nod3 } = {}) {
}
};
return Object.freeze({ at, setNod3, encodeCall, decodeCall, call });
}
//# sourceMappingURL=Contract.js.map
}
38 changes: 19 additions & 19 deletions dist/lib/ContractParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var _utils = require("./utils");function _interopRequireDefault(obj) {return obj

function mapInterfacesToERCs(interfaces) {
return Object.keys(interfaces).
filter((k) => interfaces[k] === true).
map((t) => _types.contractsInterfaces[t] || t);
filter(k => interfaces[k] === true).
map(t => _types.contractsInterfaces[t] || t);
}

function hasMethodSelector(txInputData, selector) {
Expand Down Expand Up @@ -67,8 +67,8 @@ class ContractParser {

getAbiMethods() {
let methods = {};
this.abi.filter((def) => def.type === 'function').
map((m) => {
this.abi.filter(def => def.type === 'function').
map(m => {
let sig = m[_types.ABI_SIGNATURE] || (0, _utils.abiSignatureData)(m);
sig.name = m.name;
methods[sig.method] = sig;
Expand All @@ -77,7 +77,7 @@ class ContractParser {
}

parseTxLogs(logs, abi) {
return this.decodeLogs(logs, abi).map((event) => {
return this.decodeLogs(logs, abi).map(event => {
this.addEventAddresses(event);
event.abi = (0, _utils.removeAbiSignatureData)(event.abi);
return event;
Expand All @@ -96,7 +96,7 @@ class ContractParser {
if (v.type === 'address[]') {
let value = args[i] || [];
if (Array.isArray(value)) {// temp fix to undecoded events
value.forEach((v) => _addresses.push(v));
value.forEach(v => _addresses.push(v));
} else {
let i = 0;
while (2 + (i + 1) * 40 <= value.length) {
Expand All @@ -119,7 +119,7 @@ class ContractParser {
}
const { isNativeContract } = this.nativeContracts;
const { nativeContractsEvents } = this;
return logs.map((log) => {
return logs.map(log => {
const { address } = log;
const decoder = isNativeContract(address) ? nativeContractsEvents.getEventDecoder(log) : eventDecoder;
return decoder.decodeLog(log);
Expand All @@ -137,19 +137,20 @@ class ContractParser {
const res = await contract.call(method, params, options);
return res;
} catch (err) {
this.log.warn(`Method ${method} call ${err}`);
// temporary fix to avoid errored contract calls spam logs
// this.log.warn(`Method ${method} call ${err}`)
return null;
}
}

async getTokenData(contract, { methods } = {}) {
methods = methods || ['name', 'symbol', 'decimals', 'totalSupply'];
let result = await Promise.all(
methods.map((m) =>
this.call(m, contract).
then((res) => res).
catch((err) => this.log.debug(`[${contract.address}] Error executing ${m} Error: ${err}`)))
);
methods.map((m) =>
this.call(m, contract).
then(res => res).
catch(err => this.log.debug(`[${contract.address}] Error executing ${m} Error: ${err}`))));

return result.reduce((v, a, i) => {
let name = methods[i];
v[name] = a;
Expand All @@ -160,7 +161,7 @@ class ContractParser {
getMethodsBySelectors(txInputData) {
let methods = this.getMethodsSelectors();
return Object.keys(methods).
filter((method) => hasMethodSelector(txInputData, methods[method]) === true);
filter(method => hasMethodSelector(txInputData, methods[method]) === true);
}

async getContractInfo(txInputData, contract) {
Expand Down Expand Up @@ -230,7 +231,7 @@ class ContractParser {

getInterfacesByMethods(methods, isErc165) {
return Object.keys(_interfacesIds.default).
map((i) => {
map(i => {
return [i, (0, _rskUtils.includesAll)(methods, _interfacesIds.default[i].methods)];
}).
reduce((obj, value) => {
Expand All @@ -257,8 +258,7 @@ class ContractParser {
} catch (err) {
return Promise.reject(err);
}
}
}exports.ContractParser = ContractParser;var _default = exports.default =
}}exports.ContractParser = ContractParser;var _default =


ContractParser;
//# sourceMappingURL=ContractParser.js.map
ContractParser;exports.default = _default;
26 changes: 14 additions & 12 deletions dist/lib/EventDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ var _abi = require("@ethersproject/abi");
function EventDecoder(abi, logger) {
const contractInterface = new _abi.Interface((0, _utils.addSignatureDataToAbi)(abi));

const getEventAbi = (topics) => {
const getEventAbi = topics => {
topics = [...topics];
const sigHash = (0, _rskUtils.remove0x)(topics.shift());
let events = abi.filter((i) => {
let events = abi.filter(i => {
let { indexed, signature } = (0, _utils.getSignatureDataFromAbi)(i);
return signature === sigHash && indexed === topics.length;
});
Expand All @@ -29,15 +29,15 @@ function EventDecoder(abi, logger) {

const encodeElement = (type, decoded) => {
if (Array.isArray(decoded)) {
decoded = decoded.map((d) => formatElement(type, d));
decoded = decoded.map(d => formatElement(type, d));
if (decoded.length === 1) decoded = decoded.join();
} else {
decoded = formatElement(type, decoded);
}
return decoded;
};

const decodeLog = (log) => {
const decodeLog = log => {
try {
const { eventFragment, name, args, topic } = contractInterface.parseLog(log);

Expand All @@ -47,25 +47,27 @@ function EventDecoder(abi, logger) {

for (const i in eventFragment.inputs) {
parsedArgs.push(
encodeElement(eventFragment.inputs[i].type, args[i])
);
encodeElement(eventFragment.inputs[i].type, args[i]));

}

return Object.assign({}, log, {
signature: (0, _rskUtils.remove0x)(topic),
event: name,
address,
args: parsedArgs,
abi: JSON.parse(eventFragment.format('json'))
});
abi: JSON.parse(eventFragment.format('json')) });

} catch (e) {
logger.error(e);
// temporary fix to avoid ethers "no matching event" error spam
if (!e.message.includes('no matching event')) {
logger.error(e);
}
return log;
}
};

return Object.freeze({ decodeLog, getEventAbi });
}var _default = exports.default =
}var _default =

EventDecoder;
//# sourceMappingURL=EventDecoder.js.map
EventDecoder;exports.default = _default;
27 changes: 13 additions & 14 deletions dist/lib/btcUtils.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.sha256 = exports.rskAddressFromBtcPublicKey = exports.pubToAddress = exports.parsePublic = exports.h160toAddress = exports.h160 = exports.decompressPublic = exports.compressPublic = void 0;var _crypto = _interopRequireDefault(require("crypto"));
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.rskAddressFromBtcPublicKey = exports.compressPublic = exports.decompressPublic = exports.parsePublic = exports.pubToAddress = exports.h160toAddress = exports.h160 = exports.sha256 = void 0;var _crypto = _interopRequireDefault(require("crypto"));
var bs58 = _interopRequireWildcard(require("bs58"));
var _rskUtils = require("@rsksmart/rsk-utils");
var _secp256k = _interopRequireDefault(require("secp256k1"));function _getRequireWildcardCache(e) {if ("function" != typeof WeakMap) return null;var r = new WeakMap(),t = new WeakMap();return (_getRequireWildcardCache = function (e) {return e ? t : r;})(e);}function _interopRequireWildcard(e, r) {if (!r && e && e.__esModule) return e;if (null === e || "object" != typeof e && "function" != typeof e) return { default: e };var t = _getRequireWildcardCache(r);if (t && t.has(e)) return t.get(e);var n = { __proto__: null },a = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) {var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];}return n.default = e, t && t.set(e, n), n;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var _secp256k = _interopRequireDefault(require("secp256k1"));function _getRequireWildcardCache() {if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function () {return cache;};return cache;}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;}if (obj === null || typeof obj !== "object" && typeof obj !== "function") {return { default: obj };}var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

const PREFIXES = {
mainnet: {
pubKeyHash: '00',
scriptHash: '05'
},
scriptHash: '05' },

testnet: {
pubKeyHash: '6F',
scriptHash: 'C4'
},
scriptHash: 'C4' },

regtest: {
pubKeyHash: '00',
scriptHash: '00'
}
};
const getNetPrefix = (netName) => {
scriptHash: '00' } };


const getNetPrefix = netName => {
let prefixes = PREFIXES[netName];
if (!prefixes) throw new Error(`Unknown network ${netName}`);
return prefixes;
Expand Down Expand Up @@ -48,9 +48,8 @@ const parsePublic = (pub, compressed) => {
return _secp256k.default.publicKeyConvert(pub, compressed);
};exports.parsePublic = parsePublic;

const decompressPublic = (compressed) => parsePublic(compressed, false).toString('hex');exports.decompressPublic = decompressPublic;
const decompressPublic = compressed => parsePublic(compressed, false).toString('hex');exports.decompressPublic = decompressPublic;

const compressPublic = (pub) => parsePublic(pub, true).toString('hex');exports.compressPublic = compressPublic;
const compressPublic = pub => parsePublic(pub, true).toString('hex');exports.compressPublic = compressPublic;

const rskAddressFromBtcPublicKey = (cpk) => (0, _rskUtils.add0x)((0, _rskUtils.keccak256)(parsePublic(cpk, false).slice(1)).slice(-40));exports.rskAddressFromBtcPublicKey = rskAddressFromBtcPublicKey;
//# sourceMappingURL=btcUtils.js.map
const rskAddressFromBtcPublicKey = cpk => (0, _rskUtils.add0x)((0, _rskUtils.keccak256)(parsePublic(cpk, false).slice(1)).slice(-40));exports.rskAddressFromBtcPublicKey = rskAddressFromBtcPublicKey;
21 changes: 10 additions & 11 deletions dist/lib/compileJsonAbis.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const jsonPath = `${__dirname}/jsonAbis`;
const ozPath = _path.default.resolve('node_modules/openzeppelin-solidity/build/contracts');
const destinationFile = `${__dirname}/compiled_abi.json`;

compileAbi([jsonPath, ozPath]).then((abi) => {
compileAbi([jsonPath, ozPath]).then(abi => {
writeFile(destinationFile, JSON.stringify(abi, null, 2)).
then(() => {
console.log(`New ABI saved on ${destinationFile}`);
Expand All @@ -25,11 +25,11 @@ async function compileAbi(dirs) {
let jsonFiles = [];
for (let dir of dirs) {
let files = await readDir(dir);
files = files.filter((file) => _path.default.extname(file) === '.json');
files = files.filter(file => _path.default.extname(file) === '.json');
if (!files || !files.length) throw new Error(`No json files in dir ${dir}`);
jsonFiles = jsonFiles.concat(files.map((file) => `${dir}/${file}`));
jsonFiles = jsonFiles.concat(files.map(file => `${dir}/${file}`));
}
let abi = await Promise.all(jsonFiles.map((file) => readJson(`${file}`).then((content) => {
let abi = await Promise.all(jsonFiles.map(file => readJson(`${file}`).then(content => {
return Array.isArray(content) ? content : content.abi;
})));
if (!abi) throw new Error(`Invalid abi `);
Expand All @@ -55,15 +55,15 @@ async function readJson(file) {

function processAbi(abi) {
// remove fallbacks
abi = abi.filter((a) => a.type !== 'fallback');
abi = abi.filter(a => a.type !== 'fallback');
// remove duplicates
abi = [...new Set(abi.map((a) => JSON.stringify(a)))].map((a) => JSON.parse(a));
abi = [...new Set(abi.map(a => JSON.stringify(a)))].map(a => JSON.parse(a));
// add signatures
abi = (0, _utils.addSignatureDataToAbi)(abi);
// detect 4 bytes collisions
let signatures = abi.map((a) => a[_types.ABI_SIGNATURE].signature).filter((v) => v);
let signatures = abi.map(a => a[_types.ABI_SIGNATURE].signature).filter(v => v);
signatures = [...new Set(signatures)];
let fourBytes = signatures.map((s) => s.slice(0, 8));
let fourBytes = signatures.map(s => s.slice(0, 8));
if (fourBytes.length !== [...new Set(fourBytes)].length) {
console.log(fourBytes.filter((v, i) => fourBytes.indexOf(v) !== i));
throw new Error('4bytes collision');
Expand All @@ -73,8 +73,7 @@ function processAbi(abi) {
return abi;
}

process.on('unhandledRejection', (err) => {
process.on('unhandledRejection', err => {
console.error(err);
process.exit(9);
});
//# sourceMappingURL=compileJsonAbis.js.map
});
Loading

0 comments on commit adf0a5f

Please sign in to comment.