AST parser from solc json file
Project description
An AST parser for solc json outputs
Parsing AST with solidity source code and get contract information.
Usage
Using combined json, support for contract with multiple source files is limited:
from solc_json_parser.combined_json_parser import CombinedJsonParser
# The input can be a file path or source code
parser = CombinedJsonParser('contracts/BlackScholesEstimate_8.sol')
parser.all_contract_names
# List all functions in contract
parser.functions_in_contract_by_name('BlackScholesEstimate', name_only=True)
# Get source code by program counter
parser.source_by_pc('BlackScholesEstimate', 92)
{'pc': 92,
'fragment': 'function retBasedBlackScholesEstimate(\n uint256[] memory _numbers,\n uint256 _underlying,\n uint256 _time\n ) public pure {\n uint _vol = stddev(_numbers);\n blackScholesEstimate(_vol, _underlying, _time);\n }',
'begin': 2633,
'end': 2877,
'linenums': (69, 76),
'source_idx': 0,
'source_path': 'BlackScholesEstimate_8.sol'}
# Get deployment code by contract name
parser.get_deploy_bin_by_contract_name('BlackScholesEstimate')
# Get literal values by contract name
parser.get_literals('BlackScholesEstimate', True)
{'number': {0, 1, 2, 40}, 'string': set(), 'address': set(), 'other': set()}
Using standard json:
import json
from solc_json_parser.standard_json_parser import StandardJsonParser
with open('contracts/standard_json/75b8.standard-input.json') as f:
input_json = json.load(f)
version = '0.8.4'
parser = StandardJsonParser(input_json, version)
# Other usages are the same as combined json parser
Note
- This library only supports detecting Solidity version newer than or equal to
v0.4.11. This is due to the limitation of the base library py-solc-x.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
solc-json-parser-0.1.8.tar.gz
(35.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file solc-json-parser-0.1.8.tar.gz.
File metadata
- Download URL: solc-json-parser-0.1.8.tar.gz
- Upload date:
- Size: 35.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e4e1301e7c7dc389eb58d6f9482bc9f9f6656a76ca86965e264c749b775a096
|
|
| MD5 |
8982a08e99682e5a3a41b0084363fcdb
|
|
| BLAKE2b-256 |
bcf21ad4062194a2fa063f49f72e73423958d086becef9ed28650566dc6f05ca
|
File details
Details for the file solc_json_parser-0.1.8-py3-none-any.whl.
File metadata
- Download URL: solc_json_parser-0.1.8-py3-none-any.whl
- Upload date:
- Size: 39.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4769d27fa42d976fb918c078a3cc1399cfe21eb54545fad99554813ad4154f27
|
|
| MD5 |
c86babc69c9aa84f8e5c86cbf6b063fd
|
|
| BLAKE2b-256 |
e87c1bd42c6dc6035cfe611780a5411b87b8f2242bbc41e76a318b19f3a2abfb
|