-
Notifications
You must be signed in to change notification settings - Fork 1
/
pcspy.py
109 lines (93 loc) · 3.51 KB
/
pcspy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# PocketCoin Spy by James Lawrence
#
# Filename: pcspy.py
# Version: 0.0.1
# Date: 3 Nov 2024
#
# A Script to show each stake reward from a given day
#
# Example: python3 pcspy.py 2024-01-31
#
# Freely use or distribute this code. No warrenties of any kind. Use at your own risk
# Requires Python 3.9 (It might work on downlevel versions)
import requests, sys, configparser
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
def get_address_transactions(url, address, page=1, page_size=999999):
latestblock = str(get_last_blocks(url))
params = {
"method": "getaddresstransactions",
"params": [
address, # Your address
latestblock, # Top block height for starting pagination
page, # Start page number
page_size, # Page size
1, # Direction transactions (-1: outgoing, 1: incoming, 0: both)
3 # Type of transaction. 1 - stacking,
]
}
response = requests.post(url, json=params)
data = response.json()
formatted_transactions = []
for transaction in data['result']:
#print(transaction)
if 'height' not in transaction:
continue
formatted_transactions.append(format_transactions(address, transaction))
return formatted_transactions
def format_transactions(address, transaction):
amount_input = sum(vin['value'] for vin in transaction['vin'])
amount_final = sum(vout['value'] for vout in transaction['vout'] if vout['scriptPubKey']['addresses'][0] == address)
amount = amount_final - amount_input
return {
"txid": transaction['txid'],
"type": transaction['type'],
"height": transaction['height'],
"nTime": datetime.utcfromtimestamp(transaction['nTime']).strftime("%Y-%m-%d %H:%M:%S"),
"amount": amount
}
def get_last_blocks(url):
params = {
"method": "getlastblocks",
"params": [
1, # Direction transactions (-1: outgoing, 1: incoming, 0: both)
]
}
response = requests.post(url, json=params)
data = response.json()
return{data['result'][0]['height']}
#Load Settings
config = configparser.ConfigParser()
config.read('pcspy.conf')
url = config['main']['url']
address = config['main']['address']
tz = config['main']['tz']
localtime = ZoneInfo(tz)
if len(sys.argv) != 2:
print()
print("******************* pcspy.py ******************")
print()
print("pcspy.py returns all of stake rewards for a specified date")
print()
print("exacly one option is required which is the date to return stake rewards for in the format of YYYY-mm-dd")
print()
print("Example: python3 pcspy.py 2024-01-31")
print()
exit()
checkdate = sys.argv[1]
transactions = get_address_transactions(url, address)
totalamt = 0
print()
print("Listing transactions for " + checkdate)
print()
print()
for transaction in transactions:
datetime_object = datetime.strptime(transaction['nTime'], '%Y-%m-%d %H:%M:%S').replace(tzinfo=timezone.utc)
datetimestring = datetime_object.astimezone(localtime).strftime("%Y-%m-%d %H:%M:%S")
dateonlystring = datetimestring[0:10]
if dateonlystring == checkdate:
totalamt = totalamt + transaction['amount']
print(f"{transaction['txid']}\t{transaction['type']}\t{transaction['height']}\t{datetime_object.astimezone(localtime)}\t{round(transaction['amount'], 8):.8f}")
print()
rndtotalamt = round(totalamt, 8)
print(f'Total: {rndtotalamt:.8f}')