Skip to content

Commit

Permalink
Added more in subscription payload
Browse files Browse the repository at this point in the history
  • Loading branch information
joemarct committed Jun 23, 2021
1 parent bd935ce commit b72aa82
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import watchtower

# Subscribe function accepts either BCH or SLP address
data = {
address: 'simpleledger:qqz95enwd6qdcy5wnf05hp590sjjknwfuq8sjhpv6x',
project_id: '0000-0000-0000', # <-- Generate this ID by creating a project at Watchtower.cash
wallet_hash: 'abcd0123456', # <-- (Optional) You generate this to track which HD wallet the address belongs to
webhook_url: 'https://xxx.com/webhook-call-receiver' # <-- (Optional) Your webhook receiver URL
'address': address, #'simpleledger:qqz95enwd6qdcy5wnf05hp590sjjknwfuq8sjhpv6x',
'project_id': x, #'0000-0000-0000', # <-- Generate this ID by creating a project at Watchtower.cash
'wallet_hash': 'abcd0123456', # <-- (Optional) You generate this to track which HD wallet the address belongs to
'wallet_index': 0, # <-- (Optional) The index used to generate this address from HD wallet
'webhook_url': 'https://xxx.com/webhook-call-receiver' # <-- (Optional) Your webhook receiver URL
}

result = watchtower.subscribe(**data)
Expand Down
43 changes: 32 additions & 11 deletions watchtower/subscription.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import requests
import uuid


def subscribe(address, project_id, wallet_hash=None, webhook_url=None):
url = 'https://watchtower.cash/api/webhook/subscribe/'
payload = {
'address': address,
'web_url': webhook_url
}
resp = requests.post(
url,
json=payload
)
return resp.json()
def is_valid_uuid(val):
try:
uuid.UUID(str(val))
return True
except ValueError:
return False


def subscribe(address, project_id=None, wallet_hash=None, wallet_index=None, webhook_url=None):
response = {'success': False}
proceed = False
if project_id:
if is_valid_uuid(project_id):
proceed = True
else:
response['error'] = 'project_id is invalid UUID'
if proceed:
url = 'https://watchtower.cash/api/subscription/'
payload = {
'address': address,
'project_id': project_id,
'wallet_hash': wallet_hash,
'wallet_index': wallet_index,
'webhook_url': webhook_url
}
resp = requests.post(
url,
json=payload
)
return resp.json()
return response

0 comments on commit b72aa82

Please sign in to comment.