oss_server/base/utils.py
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 []
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.
    
Return a list of utxo sum up to the specified amount.
Return a list of utxo sum up to the specified amount .
def select_utxo(utxos, sum):
    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 []
def select_utxo ( utxos , sum ) : 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 [ ]
Return a list of utxo sum up to the specified amount.
Return a list of utxo sum up to the specified amount .
"""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.
    """
utxos
A list of dict with following format.
A list of dict with following format .
sum
The sum of the returned utxos' total value.
The sum of the returned utxos ' total value .