-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonero_async_jsonrpc.py
196 lines (141 loc) · 5.95 KB
/
monero_async_jsonrpc.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
from httpx import AsyncClient
class monero_async_client:
def __init__(self, ip='127.0.0.1', port=28088, ssl_verify=False, http2=False, headers=None, proxies=None, json_id='0', jsonrpc='2.0'):
if headers:
self.headers = headers
else:
self.headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
self.client = AsyncClient(
headers=self.headers,
http2=http2,
verify=ssl_verify,
proxies=proxies,
)
self.base_json_payload = {
'jsonrpc': jsonrpc,
'id': json_id,
}
self.base_url = f'http://{ip}:{port}/json_rpc'
async def incoming_transactions(self, **kwargs):
get_incoming_transactions_json_payload = self.base_json_payload
get_incoming_transactions_json_payload.update({
'method': 'incoming_transfers',
})
if kwargs:
get_incoming_transactions_json_payload.update(kwargs)
get_incoming_transactions_response = await self.client.post(
url=self.base_url,
json=get_incoming_transactions_json_payload
)
return get_incoming_transactions_response.json()
async def get_height(self, **kwargs):
get_height_json_payload = self.base_json_payload
get_height_json_payload.update({
'method': 'get_height',
})
if kwargs:
get_height_json_payload.update(kwargs)
get_height_response = await self.client.post(
url=self.base_url,
json=get_height_json_payload
)
return get_height_response.json()
async def transfer(self, **kwargs):
transfer_json_payload = self.base_json_payload
transfer_json_payload.update({
'method': 'transfer',
})
if kwargs:
transfer_json_payload.update(kwargs)
transfer_response = await self.client.post(
url=self.base_url,
json=transfer_json_payload
)
return transfer_response.json()
async def get_transfers(self, **kwargs):
get_transfer_json_payload = self.base_json_payload
get_transfer_json_payload.update({
'method': 'get_transfers',
})
if kwargs:
get_transfer_json_payload.update(kwargs)
get_transfer_response = await self.client.post(
url=self.base_url,
json=get_transfer_json_payload
)
return get_transfer_response.json()
async def get_balance(self, **kwargs):
get_balance_json_payload = self.base_json_payload
get_balance_json_payload.update({
'method': 'get_balance',
})
if kwargs:
get_balance_json_payload.update(kwargs)
get_balance_response = await self.client.post(
url=self.base_url,
json=get_balance_json_payload
)
return get_balance_response.json()
async def make_integrated_address(self, **kwargs):
make_integrated_address_json_payload = self.base_json_payload
make_integrated_address_json_payload.update({
'method': 'make_integrated_address',
})
if kwargs:
make_integrated_address_json_payload.update(kwargs)
make_integrated_address_response = await self.client.post(
url=self.base_url,
json=make_integrated_address_json_payload
)
return make_integrated_address_response.json()
async def set_daemon(self, **kwargs):
set_daemon_json_payload = self.base_json_payload
set_daemon_json_payload.update({
'method': 'set_daemon',
})
if kwargs:
set_daemon_json_payload.update(kwargs)
set_daemon_response = await self.client.post(
url=self.base_url,
json=set_daemon_json_payload
)
return set_daemon_response.json()
async def rescan_blockchain(self, **kwargs):
rescan_blockchain_json_payload = self.base_json_payload
rescan_blockchain_json_payload.update({
'method': 'rescan_blockchain',
})
if kwargs:
rescan_blockchain_json_payload.update(kwargs)
rescan_blockchain_response = await self.client.post(
url=self.base_url,
json=rescan_blockchain_json_payload
)
return rescan_blockchain_response.json()
async def get_payments(self, **kwargs):
get_payments_json_payload = self.base_json_payload
get_payments_json_payload.update({
'method': 'get_payments',
})
if kwargs:
get_payments_json_payload.update(kwargs)
get_payments_response = await self.client.post(
url=self.base_url,
json=get_payments_json_payload
)
return get_payments_response.json()
async def get_bulk_payments(self, **kwargs):
get_bulk_payments_json_payload = self.base_json_payload
get_bulk_payments_json_payload.update({
'method': 'get_bulk_payments',
})
if kwargs:
get_bulk_payments_json_payload.update(kwargs)
get_bulk_payments_response = await self.client.post(
url=self.base_url,
json=get_bulk_payments_json_payload
)
return get_bulk_payments_response.json()