import json
import requests


def _send_jsonrpc_request(parity_url, request, getter):
    """
    Send a bunch of requests to parity node

    Parameters
    ----------
    parity_url : str
        URL of parity node JSONRPC API
    request : list
        All parity requests to send
    getter : function
        Function to get target field from response

    Returns
    -------
    list
        List of all responses.
        Responses with errors will be skipped
    """
    request_string = json.dumps(request)
    responses = requests.post(
        parity_url,
        data=request_string,
        headers={"content-type": "application/json"}
    ).json()
    full_response = []
    assert type(responses) == list
    for response in responses:
        try:
            full_response += getter(response)
        except Exception as e:
            print("Exception while processing response:")
            print(e)
    return full_response