def select_utxo(utxos, sum):
    """Return a list of utxo sum up to the specified amount.

    Args:
        utxos: A list of dict with following format.
                   [{
                       txid: ''
                       value: 0,
                       vout: 0,
                       scriptPubKey: '',
                    },
                    {
                       txid: ''
                       value: 0,
                       vout: 0,
                       scriptPubKey: '',
                    }]
        sum: The sum of the returned utxos' total value.

    Returns: A list of utxo with value add up to `sum`. If the given utxo can't add up to `sum`,
             an empty list is returned. This function returns as many utxo as possible, that is,
             utxo with small value will get picked first.
    """
    if not utxos:
        return []

    utxos = sorted(utxos, key=lambda utxo: utxo['value'])

    value = 0
    for i, utxo in enumerate(utxos):
        value += utxo['value']
        if value >= sum:
            return utxos[:i + 1]
    return []