forked from blockfrost/blockfrost-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblocks.py
More file actions
289 lines (245 loc) · 10.1 KB
/
blocks.py
File metadata and controls
289 lines (245 loc) · 10.1 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import requests
from blockfrost.utils import request_wrapper, list_request_wrapper
@request_wrapper
def block_latest(self, **kwargs):
"""
Return the latest block available to the backends, also known as the tip of the blockchain.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1latest/get
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
:type return_type: str
:returns object.
:rtype: Namespace
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/latest",
headers=self.default_headers
)
@list_request_wrapper
def block_latest_transactions(self, **kwargs):
"""
Return the transactions within the latest block.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1latest~1txs/get
:param gather_pages: Optional. Default: false. Will collect all pages into one return
:type gather_pages: bool
:param count: Optional. Default: 100. The number of results displayed on one page.
:type count: int
:param page: Optional. The page number for listing the results.
:type page: int
:param order: Optional. "asc" or "desc". Default: "asc".
:type order: str
:returns A list of str objects.
:rtype [str]
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/latest/txs",
params=self.query_parameters(kwargs),
headers=self.default_headers
)
@request_wrapper
def block(self, hash_or_number: str, **kwargs):
"""
Return the content of a requested block.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1{hash_or_number}/get
:param hash_or_number: Hash or number of the requested block.
:type hash_or_number: str
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
:type return_type: str
:returns object.
:rtype: Namespace
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/{hash_or_number}",
headers=self.default_headers
)
@request_wrapper
def block_slot(self, slot_number: int, **kwargs):
"""
Return the content of a requested block for a specific slot.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1slot~1{slot_number}/get
:param slot_number: Slot position for requested block.
:type slot_number: int
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
:type return_type: str
:returns object.
:rtype: Namespace
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/slot/{slot_number}",
headers=self.default_headers
)
@request_wrapper
def block_epoch_slot(self, epoch_number: int, slot_number: int, **kwargs):
"""
Return the content of a requested block for a specific slot in an epoch.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1epoch~1{epoch_number}~1slot~1{slot_number}/get
:param epoch_number: Epoch for specific epoch slot.
:type epoch_number: int
:param slot_number: Slot position for requested block (epoch_slot).
:type slot_number: int
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
:type return_type: str
:returns object.
:rtype: Namespace
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/epoch/{epoch_number}/slot/{slot_number}",
headers=self.default_headers
)
@list_request_wrapper
def blocks_next(self, hash_or_number: str, **kwargs):
"""
Return the list of blocks following a specific block.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1{hash_or_number}~1next/get
:param hash_or_number: Hash or number of the requested block.
:type hash_or_number: str
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
:type return_type: str
:param gather_pages: Optional. Default: false. Will collect all pages into one return
:type gather_pages: bool
:param count: Optional. Default: 100. The number of results displayed on one page.
:type count: int
:param page: Optional. The page number for listing the results.
:type page: int
:returns A list of objects.
:rtype [Namespace]
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/{hash_or_number}/next",
params=self.query_parameters(kwargs),
headers=self.default_headers
)
@list_request_wrapper
def blocks_previous(self, hash_or_number: str, **kwargs):
"""
Return the list of blocks preceding a specific block.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1{hash_or_number}~1previous/get
:param hash_or_number: Hash or number of the requested block.
:type hash_or_number: str
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
:type return_type: str
:param gather_pages: Optional. Default: false. Will collect all pages into one return
:type gather_pages: bool
:param count: Optional. Default: 100. The number of results displayed on one page.
:type count: int
:param page: Optional. The page number for listing the results.
:type page: int
:returns A list of objects.
:rtype [Namespace]
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/{hash_or_number}/previous",
params=self.query_parameters(kwargs),
headers=self.default_headers
)
@list_request_wrapper
def block_transactions(self, hash_or_number: str, **kwargs):
"""
Return the transactions within the block.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1{hash_or_number}~1txs/get
:param hash_or_number: Hash or number of the requested block.
:type hash_or_number: str
:param gather_pages: Optional. Default: false. Will collect all pages into one return
:type gather_pages: bool
:param count: Optional. Default: 100. The number of results displayed on one page.
:type count: int
:param page: Optional. The page number for listing the results.
:type page: int
:param order: Optional. "asc" or "desc". Default: "asc".
:type order: str
:returns A list of str objects.
:rtype [str]
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/{hash_or_number}/txs",
params=self.query_parameters(kwargs),
headers=self.default_headers
)
@list_request_wrapper
def block_latest_transactions_cbor(self, **kwargs):
"""
Return the transactions within the latest block in CBOR format.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1latest~1txs~1cbor/get
:param gather_pages: Optional. Default: false. Will collect all pages into one return
:type gather_pages: bool
:param count: Optional. Default: 100. The number of results displayed on one page.
:type count: int
:param page: Optional. The page number for listing the results.
:type page: int
:param order: Optional. "asc" or "desc". Default: "asc".
:type order: str
:returns A list of objects.
:rtype [Namespace]
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/latest/txs/cbor",
params=self.query_parameters(kwargs),
headers=self.default_headers
)
@list_request_wrapper
def block_transactions_cbor(self, hash_or_number: str, **kwargs):
"""
Return the transactions within the block in CBOR format.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1{hash_or_number}~1txs~1cbor/get
:param hash_or_number: Hash or number of the requested block.
:type hash_or_number: str
:param gather_pages: Optional. Default: false. Will collect all pages into one return
:type gather_pages: bool
:param count: Optional. Default: 100. The number of results displayed on one page.
:type count: int
:param page: Optional. The page number for listing the results.
:type page: int
:param order: Optional. "asc" or "desc". Default: "asc".
:type order: str
:returns A list of objects.
:rtype [Namespace]
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/{hash_or_number}/txs/cbor",
params=self.query_parameters(kwargs),
headers=self.default_headers
)
@list_request_wrapper
def blocks_addresses(self, hash_or_number: str, **kwargs):
"""
Return list of addresses affected in the specified block with additional information, sorted by the bech32 address, ascending.
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1{hash_or_number}~1addresses/get
:param hash_or_number: Hash or number of the requested block.
:type hash_or_number: str
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
:type return_type: str
:param gather_pages: Optional. Default: false. Will collect all pages into one return
:type gather_pages: bool
:param count: Optional. Default: 100. The number of results displayed on one page.
:type count: int
:param page: Optional. The page number for listing the results.
:type page: int
:returns A list of objects.
:rtype [Namespace]
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/blocks/{hash_or_number}/addresses",
params=self.query_parameters(kwargs),
headers=self.default_headers
)