Add example request, response and other details in json array for future use
(node, method, params, response=None, description=None)
| 396 | |
| 397 | |
| 398 | def update_example(node, method, params, response=None, description=None): |
| 399 | """Add example request, response and other details in json array for future use""" |
| 400 | method_examples = EXAMPLES_JSON.get(method, {'examples': []}) |
| 401 | method_id = len(method_examples['examples']) + 1 |
| 402 | req = { |
| 403 | 'id': f'example:{method}#{method_id}', |
| 404 | 'method': method, |
| 405 | 'params': params |
| 406 | } |
| 407 | logger.info(f'Method \'{method}\', Params {params}') |
| 408 | # Execute the RPC call and get the response |
| 409 | if response is None: |
| 410 | response = node.rpc.call(method, params) |
| 411 | logger.info(f'{method} response: {response}') |
| 412 | # Return response without updating the file because user doesn't want to update the example |
| 413 | # Executing the method and returning the response is useful for further example updates |
| 414 | if method not in REGENERATING_RPCS: |
| 415 | return response |
| 416 | else: |
| 417 | method_examples['examples'].append({'request': req, 'response': response} if description is None else {'description': description, 'request': req, 'response': response}) |
| 418 | EXAMPLES_JSON[method] = method_examples |
| 419 | logger.info(f'Updated {method}#{method_id} example json') |
| 420 | return response |
| 421 | |
| 422 | |
| 423 | def setup_test_nodes(node_factory, bitcoind): |
no test coverage detected