Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
paylinkprotocol authored Nov 30, 2024
0 parents commit da3c046
Show file tree
Hide file tree
Showing 25 changed files with 230 additions and 0 deletions.
26 changes: 26 additions & 0 deletions LICENSE
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.
16 changes: 16 additions & 0 deletions README.md
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
2 changes: 2 additions & 0 deletions build/lib/paylink_protocol/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .manager import PayLinkProtocolManager
from .event import Event
2 changes: 2 additions & 0 deletions build/lib/paylink_protocol/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PLP_ROUTER_ADDRESS = "0xf76Ea386437B011A14F133A3fCdd421788CD8827"
PLP_PURCHASE_TOPIC = "0xd2f563bab83cfae3f320e2a0abd440c6add9be679a8eee00b2c26c183bc64d87"
10 changes: 10 additions & 0 deletions build/lib/paylink_protocol/event.py
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})"
2 changes: 2 additions & 0 deletions build/lib/paylink_protocol/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class PayLinkProtocolError(Exception):
pass
38 changes: 38 additions & 0 deletions build/lib/paylink_protocol/manager.py
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 added dist/paylink_protocol-1.0.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/paylink_protocol-1.0.0.tar.gz
Binary file not shown.
7 changes: 7 additions & 0 deletions examples/listen_events.py
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()
32 changes: 32 additions & 0 deletions paylink_protocol.egg-info/PKG-INFO
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
13 changes: 13 additions & 0 deletions paylink_protocol.egg-info/SOURCES.txt
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
1 change: 1 addition & 0 deletions paylink_protocol.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions paylink_protocol.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web3>=5.0.0
hexbytes>=0.2.0
1 change: 1 addition & 0 deletions paylink_protocol.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
paylink_protocol
2 changes: 2 additions & 0 deletions paylink_protocol/__init__.py
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.
2 changes: 2 additions & 0 deletions paylink_protocol/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PLP_ROUTER_ADDRESS = "0xf76Ea386437B011A14F133A3fCdd421788CD8827"
PLP_PURCHASE_TOPIC = "0xd2f563bab83cfae3f320e2a0abd440c6add9be679a8eee00b2c26c183bc64d87"
10 changes: 10 additions & 0 deletions paylink_protocol/event.py
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})"
2 changes: 2 additions & 0 deletions paylink_protocol/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class PayLinkProtocolError(Exception):
pass
38 changes: 38 additions & 0 deletions paylink_protocol/manager.py
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)
24 changes: 24 additions & 0 deletions setup.py
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",
)

0 comments on commit da3c046

Please sign in to comment.