diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0440a1a --- /dev/null +++ b/LICENSE @@ -0,0 +1,26 @@ + +--- + +### **`LICENSE`** +```text +MIT License + +Copyright (c) 2024 Paylink Protocol + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..de90a39 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# PayLink Protocol Library + +A Python library for interacting with the PayLink Protocol on Ethereum. + +## Features + +- Subscribe to PayLink Protocol events +- Decode event data into Python objects +- Works with any Ethereum-compatible RPC endpoint + +## Installation + +Install the library via pip: + +```bash +pip install paylink_protocol diff --git a/build/lib/paylink_protocol/__init__.py b/build/lib/paylink_protocol/__init__.py new file mode 100644 index 0000000..2453eef --- /dev/null +++ b/build/lib/paylink_protocol/__init__.py @@ -0,0 +1,2 @@ +from .manager import PayLinkProtocolManager +from .event import Event \ No newline at end of file diff --git a/build/lib/paylink_protocol/constants.py b/build/lib/paylink_protocol/constants.py new file mode 100644 index 0000000..7b1ffed --- /dev/null +++ b/build/lib/paylink_protocol/constants.py @@ -0,0 +1,2 @@ +PLP_ROUTER_ADDRESS = "0xf76Ea386437B011A14F133A3fCdd421788CD8827" +PLP_PURCHASE_TOPIC = "0xd2f563bab83cfae3f320e2a0abd440c6add9be679a8eee00b2c26c183bc64d87" \ No newline at end of file diff --git a/build/lib/paylink_protocol/event.py b/build/lib/paylink_protocol/event.py new file mode 100644 index 0000000..e2bea8f --- /dev/null +++ b/build/lib/paylink_protocol/event.py @@ -0,0 +1,10 @@ +class Event: + def __init__(self, app_id, purchased_token, purchase_amount, user_id, customer_user_address): + self.app_id = app_id + self.purchased_token = purchased_token + self.purchase_amount = purchase_amount + self.user_id = user_id + self.customer_user_address = customer_user_address + + def __str__(self): + return f"Event(app_id={self.app_id}, purchased_token={self.purchased_token}, purchase_amount={self.purchase_amount}, user_id={self.user_id}, customer_user_address={self.customer_user_address})" diff --git a/build/lib/paylink_protocol/exceptions.py b/build/lib/paylink_protocol/exceptions.py new file mode 100644 index 0000000..3552e1a --- /dev/null +++ b/build/lib/paylink_protocol/exceptions.py @@ -0,0 +1,2 @@ +class PayLinkProtocolError(Exception): + pass diff --git a/build/lib/paylink_protocol/manager.py b/build/lib/paylink_protocol/manager.py new file mode 100644 index 0000000..9a06c4e --- /dev/null +++ b/build/lib/paylink_protocol/manager.py @@ -0,0 +1,38 @@ +from .constants import PLP_ROUTER_ADDRESS, PLP_PURCHASE_TOPIC +from .event import Event +from web3 import Web3 +from hexbytes import HexBytes +import time + +class PayLinkProtocolManager: + def __init__(self, rpc_url, app_id): + self.app_id = app_id + self.web3 = Web3(Web3.HTTPProvider(rpc_url)) + + def subscribe(self): + app_id_bytes = self.app_id.to_bytes(32, byteorder="big") + filter_params = { + "fromBlock": "latest", + "address": PLP_ROUTER_ADDRESS, + "topics": [ + PLP_PURCHASE_TOPIC, + Web3.to_hex(app_id_bytes) + ] + } + + event_filter = self.web3.eth.filter(filter_params) + while True: + try: + for log in event_filter.get_new_entries(): + log_data = HexBytes(log["data"]) + purchased_token = Web3.to_checksum_address("0x" + log["topics"][2].hex()[-40:]) + user_id = int.from_bytes(log_data[:32], byteorder="big") + purchase_amount = int.from_bytes(log_data[32:64], byteorder="big") + customer_user_address = Web3.to_checksum_address("0x" + log_data[64:96].hex()[-40:]) + + event = Event(self.app_id, purchased_token, purchase_amount, user_id, customer_user_address) + print(event) + time.sleep(2) + except Exception as e: + print(f"Error in event listener: {e}") + time.sleep(10) diff --git a/dist/paylink_protocol-1.0.0-py3-none-any.whl b/dist/paylink_protocol-1.0.0-py3-none-any.whl new file mode 100644 index 0000000..dbe1f59 Binary files /dev/null and b/dist/paylink_protocol-1.0.0-py3-none-any.whl differ diff --git a/dist/paylink_protocol-1.0.0.tar.gz b/dist/paylink_protocol-1.0.0.tar.gz new file mode 100644 index 0000000..e8b5218 Binary files /dev/null and b/dist/paylink_protocol-1.0.0.tar.gz differ diff --git a/examples/listen_events.py b/examples/listen_events.py new file mode 100644 index 0000000..3fe44c0 --- /dev/null +++ b/examples/listen_events.py @@ -0,0 +1,7 @@ +from paylink_protocol import PayLinkProtocolManager + +RPC_URL = "https://eth-sepolia.g.alchemy.com/v2/lAY70T35Lt5A4ViwfULpWvgeKfA4k5Q5" +APP_ID = 1732888855 + +manager = PayLinkProtocolManager(RPC_URL, APP_ID) +manager.subscribe() diff --git a/paylink_protocol.egg-info/PKG-INFO b/paylink_protocol.egg-info/PKG-INFO new file mode 100644 index 0000000..3bebce1 --- /dev/null +++ b/paylink_protocol.egg-info/PKG-INFO @@ -0,0 +1,32 @@ +Metadata-Version: 2.1 +Name: paylink_protocol +Version: 1.0.0 +Summary: A Python library for managing the PayLink Protocol on Ethereum. +Home-page: https://github.com/paylinkprotocol +Author: Paylink Protocol +Author-email: mail@paylinkprotocol.com +Classifier: Programming Language :: Python :: 3 +Classifier: License :: OSI Approved :: MIT License +Classifier: Operating System :: OS Independent +Requires-Python: >=3.7 +Description-Content-Type: text/markdown +License-File: LICENSE +Requires-Dist: web3>=5.0.0 +Requires-Dist: hexbytes>=0.2.0 + +# PayLink Protocol Library + +A Python library for interacting with the PayLink Protocol on Ethereum. + +## Features + +- Subscribe to PayLink Protocol events +- Decode event data into Python objects +- Works with any Ethereum-compatible RPC endpoint + +## Installation + +Install the library via pip: + +```bash +pip install paylink_protocol diff --git a/paylink_protocol.egg-info/SOURCES.txt b/paylink_protocol.egg-info/SOURCES.txt new file mode 100644 index 0000000..d07b30f --- /dev/null +++ b/paylink_protocol.egg-info/SOURCES.txt @@ -0,0 +1,13 @@ +LICENSE +README.md +setup.py +paylink_protocol/__init__.py +paylink_protocol/constants.py +paylink_protocol/event.py +paylink_protocol/exceptions.py +paylink_protocol/manager.py +paylink_protocol.egg-info/PKG-INFO +paylink_protocol.egg-info/SOURCES.txt +paylink_protocol.egg-info/dependency_links.txt +paylink_protocol.egg-info/requires.txt +paylink_protocol.egg-info/top_level.txt \ No newline at end of file diff --git a/paylink_protocol.egg-info/dependency_links.txt b/paylink_protocol.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/paylink_protocol.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/paylink_protocol.egg-info/requires.txt b/paylink_protocol.egg-info/requires.txt new file mode 100644 index 0000000..867027c --- /dev/null +++ b/paylink_protocol.egg-info/requires.txt @@ -0,0 +1,2 @@ +web3>=5.0.0 +hexbytes>=0.2.0 diff --git a/paylink_protocol.egg-info/top_level.txt b/paylink_protocol.egg-info/top_level.txt new file mode 100644 index 0000000..d75b8dd --- /dev/null +++ b/paylink_protocol.egg-info/top_level.txt @@ -0,0 +1 @@ +paylink_protocol diff --git a/paylink_protocol/__init__.py b/paylink_protocol/__init__.py new file mode 100644 index 0000000..2453eef --- /dev/null +++ b/paylink_protocol/__init__.py @@ -0,0 +1,2 @@ +from .manager import PayLinkProtocolManager +from .event import Event \ No newline at end of file diff --git a/paylink_protocol/__pycache__/__init__.cpython-312.pyc b/paylink_protocol/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..0769a9f Binary files /dev/null and b/paylink_protocol/__pycache__/__init__.cpython-312.pyc differ diff --git a/paylink_protocol/__pycache__/constants.cpython-312.pyc b/paylink_protocol/__pycache__/constants.cpython-312.pyc new file mode 100644 index 0000000..4d0405f Binary files /dev/null and b/paylink_protocol/__pycache__/constants.cpython-312.pyc differ diff --git a/paylink_protocol/__pycache__/event.cpython-312.pyc b/paylink_protocol/__pycache__/event.cpython-312.pyc new file mode 100644 index 0000000..60e3245 Binary files /dev/null and b/paylink_protocol/__pycache__/event.cpython-312.pyc differ diff --git a/paylink_protocol/__pycache__/manager.cpython-312.pyc b/paylink_protocol/__pycache__/manager.cpython-312.pyc new file mode 100644 index 0000000..4371459 Binary files /dev/null and b/paylink_protocol/__pycache__/manager.cpython-312.pyc differ diff --git a/paylink_protocol/constants.py b/paylink_protocol/constants.py new file mode 100644 index 0000000..7b1ffed --- /dev/null +++ b/paylink_protocol/constants.py @@ -0,0 +1,2 @@ +PLP_ROUTER_ADDRESS = "0xf76Ea386437B011A14F133A3fCdd421788CD8827" +PLP_PURCHASE_TOPIC = "0xd2f563bab83cfae3f320e2a0abd440c6add9be679a8eee00b2c26c183bc64d87" \ No newline at end of file diff --git a/paylink_protocol/event.py b/paylink_protocol/event.py new file mode 100644 index 0000000..e2bea8f --- /dev/null +++ b/paylink_protocol/event.py @@ -0,0 +1,10 @@ +class Event: + def __init__(self, app_id, purchased_token, purchase_amount, user_id, customer_user_address): + self.app_id = app_id + self.purchased_token = purchased_token + self.purchase_amount = purchase_amount + self.user_id = user_id + self.customer_user_address = customer_user_address + + def __str__(self): + return f"Event(app_id={self.app_id}, purchased_token={self.purchased_token}, purchase_amount={self.purchase_amount}, user_id={self.user_id}, customer_user_address={self.customer_user_address})" diff --git a/paylink_protocol/exceptions.py b/paylink_protocol/exceptions.py new file mode 100644 index 0000000..3552e1a --- /dev/null +++ b/paylink_protocol/exceptions.py @@ -0,0 +1,2 @@ +class PayLinkProtocolError(Exception): + pass diff --git a/paylink_protocol/manager.py b/paylink_protocol/manager.py new file mode 100644 index 0000000..9a06c4e --- /dev/null +++ b/paylink_protocol/manager.py @@ -0,0 +1,38 @@ +from .constants import PLP_ROUTER_ADDRESS, PLP_PURCHASE_TOPIC +from .event import Event +from web3 import Web3 +from hexbytes import HexBytes +import time + +class PayLinkProtocolManager: + def __init__(self, rpc_url, app_id): + self.app_id = app_id + self.web3 = Web3(Web3.HTTPProvider(rpc_url)) + + def subscribe(self): + app_id_bytes = self.app_id.to_bytes(32, byteorder="big") + filter_params = { + "fromBlock": "latest", + "address": PLP_ROUTER_ADDRESS, + "topics": [ + PLP_PURCHASE_TOPIC, + Web3.to_hex(app_id_bytes) + ] + } + + event_filter = self.web3.eth.filter(filter_params) + while True: + try: + for log in event_filter.get_new_entries(): + log_data = HexBytes(log["data"]) + purchased_token = Web3.to_checksum_address("0x" + log["topics"][2].hex()[-40:]) + user_id = int.from_bytes(log_data[:32], byteorder="big") + purchase_amount = int.from_bytes(log_data[32:64], byteorder="big") + customer_user_address = Web3.to_checksum_address("0x" + log_data[64:96].hex()[-40:]) + + event = Event(self.app_id, purchased_token, purchase_amount, user_id, customer_user_address) + print(event) + time.sleep(2) + except Exception as e: + print(f"Error in event listener: {e}") + time.sleep(10) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3e38cc6 --- /dev/null +++ b/setup.py @@ -0,0 +1,24 @@ +from setuptools import setup, find_packages + +setup( + name="paylink_protocol", + version="1.0.0", + description="A Python library for managing the PayLink Protocol on Ethereum.", + long_description=open("README.md").read(), + long_description_content_type="text/markdown", + author="Paylink Protocol", + author_email="mail@paylinkprotocol.com", + url="https://github.com/paylinkprotocol", + packages=find_packages(), + include_package_data=True, + install_requires=[ + "web3>=5.0.0", + "hexbytes>=0.2.0" + ], + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], + python_requires=">=3.7", +)