# All files / src/utils unspentForAddress.js

100% Statements 5/5
100% Branches 5/5
100% Functions 4/4
100% Lines 5/5

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24

    12x
    4x

    9x

    4x

    1x

     /**
     * Copyright (c) 2018-present, Leap DAO (leapdao.org)
     *
     * This source code is licensed under the Mozilla Public License Version 2.0
     * found in the LICENSE file in the root directory of this source tree.
     */

    module.exports = function unspentForAddress(unspent, address, color) {
      return Object.keys(unspent)
        .filter(
          k =>
            unspent[k] &&
            unspent[k].address.toLowerCase() === address.toLowerCase() &&
            (color !== undefined ? unspent[k].color === color : true)
        )
        .map(k => ({
          outpoint: k,
          output: unspent[k],
        }))
        .sort((a, b) => {
          return a.output.value - b.output.value;
        });
    };