This repository has been archived by the owner on Feb 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend communicating with ethereum contracts
- Loading branch information
Showing
14 changed files
with
3,224 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/config.py | ||
/__pycache__ | ||
/oxend/*.sock | ||
*/__pycache__ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
uwsgi: | ||
uwsgi --http 127.0.0.1:8000 --master -p 4 -w sent.py | ||
|
||
database: | ||
sqlite3 sent-backend.db < schema.sqlite |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
import os | ||
|
||
class ABIManager: | ||
def __init__(self, abi_dir='abis'): | ||
""" | ||
Initializes the ABIManager with the directory containing ABI JSON files. | ||
:param abi_dir: The directory where ABI files are stored. Default is 'abis'. | ||
""" | ||
self.abi_dir = abi_dir | ||
|
||
def load_abi(self, artifact_name): | ||
""" | ||
Loads the ABI from a specified artifact JSON file. | ||
:param artifact_name: The name of the artifact file (without .json extension). | ||
:return: The ABI extracted from the specified artifact JSON file. | ||
:raises FileNotFoundError: If the specified file does not exist. | ||
:raises KeyError: If the 'abi' key is not found in the JSON data. | ||
""" | ||
file_path = os.path.join(self.abi_dir, f"{artifact_name}.json") | ||
if not os.path.exists(file_path): | ||
raise FileNotFoundError(f"No such file: {file_path}") | ||
|
||
with open(file_path, 'r') as file: | ||
data = json.load(file) | ||
if 'abi' not in data: | ||
raise KeyError("Missing 'abi' key in the JSON file.") | ||
return data['abi'] | ||
|
||
# Example usage: | ||
# manager = ABIManager() | ||
# abi = manager.load_abi('MyContract') | ||
# This `abi` can now be used with Web3 library to interact with a smart contract. | ||
|
Oops, something went wrong.