-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
32 lines (25 loc) · 947 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const solc = require('solc');
// Solidity source code
const sourceCode = "";
// Compile the Solidity code
const compiledCode = solc.compile(sourceCode, 1);
// Get the AST from the compiled code
const ast = JSON.parse(compiledCode.contracts[':YourContractName'].ast);
// Function to recursively traverse the AST
function findTransferEvents(node) {
if (node.nodeType === 'FunctionDefinition') {
// Check if the function contains the 'Transfer' event
const containsTransferEvent = node.body.statements.some(statement =>
statement.nodeType === 'EmitStatement' &&
statement.eventCall.expression.name === 'Transfer'
);
if (containsTransferEvent) {
console.log('Function with Transfer event:', node.name);
}
}
if (node.children) {
node.children.forEach(child => findTransferEvents(child));
}
}
// Start traversing the AST
findTransferEvents(ast);