Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Commit

Permalink
Backend communicating with ethereum contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
darcys22 committed May 31, 2024
1 parent 504c606 commit c77da15
Show file tree
Hide file tree
Showing 14 changed files with 3,224 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/config.py
/__pycache__
/oxend/*.sock
*/__pycache__
5 changes: 5 additions & 0 deletions Makefile
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
36 changes: 36 additions & 0 deletions abi_manager.py
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.

Loading

0 comments on commit c77da15

Please sign in to comment.