Last active
August 18, 2020 06:19
-
-
Save raineorshine/e74ee7c447548afb12989ab2610ee020 to your computer and use it in GitHub Desktop.
Generate an AST for an Ethereum Solidity contract with the solidity-parser module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo {} > package.json | |
npm install --save solidity-parser | |
FILE=MyContract.sol | |
node -e "console.log(JSON.stringify(require('solidity-parser').parseFile('./${FILE}'), null, 2))" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "Program", | |
"body": [ | |
{ | |
"type": "ContractStatement", | |
"name": "MyContract", | |
"is": [], | |
"body": [ | |
{ | |
"type": "ExpressionStatement", | |
"expression": { | |
"type": "AssignmentExpression", | |
"operator": "=", | |
"left": { | |
"type": "DeclarativeExpression", | |
"name": "counter", | |
"literal": { | |
"type": "Type", | |
"literal": "uint", | |
"members": [], | |
"array_parts": [] | |
}, | |
"is_constant": false, | |
"is_public": false, | |
"is_memory": false | |
}, | |
"right": { | |
"type": "Literal", | |
"value": 0 | |
} | |
} | |
}, | |
{ | |
"type": "FunctionDeclaration", | |
"name": "Count", | |
"params": null, | |
"modifiers": null, | |
"body": { | |
"type": "BlockStatement", | |
"body": [ | |
{ | |
"type": "ExpressionStatement", | |
"expression": { | |
"type": "UpdateExpression", | |
"operator": "++", | |
"argument": { | |
"type": "Identifier", | |
"name": "counter" | |
}, | |
"prefix": false | |
} | |
} | |
] | |
}, | |
"is_abstract": false | |
}, | |
{ | |
"type": "FunctionDeclaration", | |
"name": "CallCount", | |
"params": null, | |
"modifiers": null, | |
"body": { | |
"type": "BlockStatement", | |
"body": [ | |
{ | |
"type": "ExpressionStatement", | |
"expression": { | |
"type": "CallExpression", | |
"callee": { | |
"type": "Identifier", | |
"name": "Count" | |
}, | |
"arguments": [] | |
} | |
} | |
] | |
}, | |
"is_abstract": false | |
}, | |
{ | |
"type": "FunctionDeclaration", | |
"name": "Send", | |
"params": null, | |
"modifiers": null, | |
"body": { | |
"type": "BlockStatement", | |
"body": [ | |
{ | |
"type": "ExpressionStatement", | |
"expression": { | |
"type": "CallExpression", | |
"callee": { | |
"type": "MemberExpression", | |
"object": { | |
"type": "MemberExpression", | |
"object": { | |
"type": "Identifier", | |
"name": "msg" | |
}, | |
"property": { | |
"type": "Identifier", | |
"name": "sender" | |
}, | |
"computed": false | |
}, | |
"property": { | |
"type": "Identifier", | |
"name": "send" | |
}, | |
"computed": false | |
}, | |
"arguments": [ | |
{ | |
"type": "Literal", | |
"value": 1 | |
} | |
] | |
} | |
} | |
] | |
}, | |
"is_abstract": false | |
}, | |
{ | |
"type": "FunctionDeclaration", | |
"name": "Call", | |
"params": null, | |
"modifiers": null, | |
"body": { | |
"type": "BlockStatement", | |
"body": [ | |
{ | |
"type": "ExpressionStatement", | |
"expression": { | |
"type": "CallExpression", | |
"arguments": [], | |
"callee": { | |
"type": "MemberExpression", | |
"property": { | |
"type": "Identifier", | |
"name": "call" | |
}, | |
"computed": false, | |
"object": { | |
"type": "CallExpression", | |
"callee": { | |
"type": "MemberExpression", | |
"object": { | |
"type": "MemberExpression", | |
"object": { | |
"type": "Identifier", | |
"name": "msg" | |
}, | |
"property": { | |
"type": "Identifier", | |
"name": "sender" | |
}, | |
"computed": false | |
}, | |
"property": { | |
"type": "Identifier", | |
"name": "value" | |
}, | |
"computed": false | |
}, | |
"arguments": [ | |
{ | |
"type": "Literal", | |
"value": 1 | |
} | |
] | |
} | |
} | |
} | |
} | |
] | |
}, | |
"is_abstract": false | |
} | |
] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract MyContract { | |
uint counter = 0; | |
function Count() { | |
counter++; | |
} | |
function CallCount() { | |
Count(); | |
} | |
function Send() { | |
msg.sender.send(1); | |
} | |
function Call() { | |
msg.sender.value(1).call(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment