feat: remove requests as a dep for get_abis.py script and add docs
This commit is contained in:
@@ -7,3 +7,16 @@ We then can define all of the abis via `substreams_ethereum::Abigen::new` in our
|
|||||||
## Recommendation
|
## Recommendation
|
||||||
|
|
||||||
It would be apt to convert (maybe through copilot) the python code into the `build.rs` file and then automate the `Abigen` functionality.
|
It would be apt to convert (maybe through copilot) the python code into the `build.rs` file and then automate the `Abigen` functionality.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Requires `python 3.8+`,
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd abi
|
||||||
|
python get_abis.py
|
||||||
|
```
|
||||||
|
|
||||||
|
This will populate the files in the `abi` folder.
|
||||||
|
|
||||||
|
When the `build.rs` file runs (when `rust-analyzer` activates or `cargo build` is manually ran), Abigen will generate new rust src files from the abis in the `src/abi` folder.
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
import urllib.request
|
||||||
import requests
|
|
||||||
|
|
||||||
# Exports contract ABI in JSON
|
# Exports contract ABI in JSON
|
||||||
|
|
||||||
@@ -38,13 +37,12 @@ def __main__():
|
|||||||
print(f"Getting ABI for {name} at {addr} ({normalized_name})")
|
print(f"Getting ABI for {name} at {addr} ({normalized_name})")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
...
|
with urllib.request.urlopen(ABI_ENDPOINT.format(address=addr)) as response:
|
||||||
response = requests.get(ABI_ENDPOINT.format(address=addr))
|
response_json = json.loads(response.read().decode())
|
||||||
response_json = response.json()
|
abi_json = json.loads(response_json["result"])
|
||||||
abi_json = json.loads(response_json["result"])
|
result = json.dumps(abi_json, indent=4, sort_keys=True)
|
||||||
result = json.dumps(abi_json, indent=4, sort_keys=True)
|
with open(f"{normalized_name}.json", "w") as f:
|
||||||
with open(f"{normalized_name}.json", "w") as f:
|
f.write(result)
|
||||||
f.write(result)
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(response.content)
|
print(response.content)
|
||||||
raise err
|
raise err
|
||||||
|
|||||||
Reference in New Issue
Block a user