-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit da3c046
Showing
25 changed files
with
230 additions
and
0 deletions.
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 |
---|---|---|
@@ -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. |
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,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 |
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,2 @@ | ||
from .manager import PayLinkProtocolManager | ||
from .event import Event |
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,2 @@ | ||
PLP_ROUTER_ADDRESS = "0xf76Ea386437B011A14F133A3fCdd421788CD8827" | ||
PLP_PURCHASE_TOPIC = "0xd2f563bab83cfae3f320e2a0abd440c6add9be679a8eee00b2c26c183bc64d87" |
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,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})" |
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,2 @@ | ||
class PayLinkProtocolError(Exception): | ||
pass |
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,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) |
Binary file not shown.
Binary file not shown.
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,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() |
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,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: [email protected] | ||
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 |
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,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 |
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 @@ | ||
|
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,2 @@ | ||
web3>=5.0.0 | ||
hexbytes>=0.2.0 |
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 @@ | ||
paylink_protocol |
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,2 @@ | ||
from .manager import PayLinkProtocolManager | ||
from .event import Event |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,2 @@ | ||
PLP_ROUTER_ADDRESS = "0xf76Ea386437B011A14F133A3fCdd421788CD8827" | ||
PLP_PURCHASE_TOPIC = "0xd2f563bab83cfae3f320e2a0abd440c6add9be679a8eee00b2c26c183bc64d87" |
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,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})" |
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,2 @@ | ||
class PayLinkProtocolError(Exception): | ||
pass |
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,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) |
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,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="[email protected]", | ||
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", | ||
) |