|
25 | 25 |
|
26 | 26 | class Tron(TronBase): |
27 | 27 |
|
28 | | - def get_event_result(self, contract_address=None, since=0, event_name=None, block_number=None): |
29 | | - """Will return all events matching the filters. |
30 | | -
|
31 | | - Args: |
32 | | - contract_address (str): Address to query for events. |
33 | | - since (int): Filter for events since certain timestamp. |
34 | | - event_name (str): Name of the event to filter by. |
35 | | - block_number (str): Specific block number to query |
36 | | -
|
37 | | - Examples: |
38 | | - >>> tron.get_event_result('TQyXdrUaZaw155WrB3F3HAZZ3EeiLVx4V2', 0) |
39 | | -
|
40 | | - """ |
41 | | - |
42 | | - if not self.event_server: |
43 | | - raise TronError('No event server configured') |
44 | | - |
45 | | - if not self.is_address(contract_address): |
46 | | - raise InvalidTronError('Invalid contract address provided') |
47 | | - |
48 | | - if event_name and not contract_address: |
49 | | - raise TronError('Usage of event name filtering requires a contract address') |
50 | | - |
51 | | - if block_number and not event_name: |
52 | | - raise TronError('Usage of block number filtering requires an event name') |
53 | | - |
54 | | - route_params = [] |
55 | | - |
56 | | - if contract_address: |
57 | | - route_params.append(contract_address) |
58 | | - |
59 | | - if event_name: |
60 | | - route_params.append(event_name) |
61 | | - |
62 | | - if block_number: |
63 | | - route_params.append(block_number) |
64 | | - |
65 | | - route = '/'.join(route_params) |
66 | | - return self.event_server.request("/event/contract/{}?since={}".format(route, since)) |
67 | | - |
68 | | - def get_event_transaction_id(self, tx_id): |
69 | | - """Will return all events within a transactionID. |
70 | | -
|
71 | | - Args: |
72 | | - tx_id (str): TransactionID to query for events. |
73 | | -
|
74 | | - Examples: |
75 | | - >>> tron.get_event_transaction_id('660028584562b3ae687090f77e989bc7b0bc8b0a8f677524630002c06fd1d57c') |
76 | | -
|
77 | | - """ |
78 | | - |
79 | | - if not self.event_server: |
80 | | - raise TronError('No event server configured') |
81 | | - |
82 | | - response = self.event_server.request('/event/transaction/' + tx_id) |
83 | | - return response |
84 | | - |
85 | 28 | def get_current_block(self): |
86 | 29 | """Query the latest block |
87 | 30 |
|
@@ -380,6 +323,63 @@ def send(self, **kwargs): |
380 | 323 | kwargs.get('to_address'), |
381 | 324 | kwargs.get('amount')) |
382 | 325 |
|
| 326 | + def get_event_result(self, contract_address=None, since=0, event_name=None, block_number=None): |
| 327 | + """Will return all events matching the filters. |
| 328 | +
|
| 329 | + Args: |
| 330 | + contract_address (str): Address to query for events. |
| 331 | + since (int): Filter for events since certain timestamp. |
| 332 | + event_name (str): Name of the event to filter by. |
| 333 | + block_number (str): Specific block number to query |
| 334 | +
|
| 335 | + Examples: |
| 336 | + >>> tron.get_event_result('TQyXdrUaZaw155WrB3F3HAZZ3EeiLVx4V2', 0) |
| 337 | +
|
| 338 | + """ |
| 339 | + |
| 340 | + if not self.event_server: |
| 341 | + raise TronError('No event server configured') |
| 342 | + |
| 343 | + if not self.is_address(contract_address): |
| 344 | + raise InvalidTronError('Invalid contract address provided') |
| 345 | + |
| 346 | + if event_name and not contract_address: |
| 347 | + raise TronError('Usage of event name filtering requires a contract address') |
| 348 | + |
| 349 | + if block_number and not event_name: |
| 350 | + raise TronError('Usage of block number filtering requires an event name') |
| 351 | + |
| 352 | + route_params = [] |
| 353 | + |
| 354 | + if contract_address: |
| 355 | + route_params.append(contract_address) |
| 356 | + |
| 357 | + if event_name: |
| 358 | + route_params.append(event_name) |
| 359 | + |
| 360 | + if block_number: |
| 361 | + route_params.append(block_number) |
| 362 | + |
| 363 | + route = '/'.join(route_params) |
| 364 | + return self.event_server.request("/event/contract/{}?since={}".format(route, since)) |
| 365 | + |
| 366 | + def get_event_transaction_id(self, tx_id): |
| 367 | + """Will return all events within a transactionID. |
| 368 | +
|
| 369 | + Args: |
| 370 | + tx_id (str): TransactionID to query for events. |
| 371 | +
|
| 372 | + Examples: |
| 373 | + >>> tron.get_event_transaction_id('660028584562b3ae687090f77e989bc7b0bc8b0a8f677524630002c06fd1d57c') |
| 374 | +
|
| 375 | + """ |
| 376 | + |
| 377 | + if not self.event_server: |
| 378 | + raise TronError('No event server configured') |
| 379 | + |
| 380 | + response = self.event_server.request('/event/transaction/' + tx_id) |
| 381 | + return response |
| 382 | + |
383 | 383 | def send_trx(self, **kwargs): |
384 | 384 | """Send funds to the Tron account (option 3) |
385 | 385 |
|
|
0 commit comments