sortUtxos method

List<Utxo> sortUtxos(
  1. UtxoSelectionStrategy utxoSelectionStrategy
)

Implementation

List<Utxo> sortUtxos(UtxoSelectionStrategy utxoSelectionStrategy) {
  List<Utxo> sortedUtxos;
  switch (utxoSelectionStrategy) {
    case UtxoSelectionStrategy.Random:
      {
        sortedUtxos = shuffleUtxos();
      }
      break;
    case UtxoSelectionStrategy.LargeFirst:
      {
        sortedUtxos = map.values.toList()
          ..sort((e1, e2) {
            var diff = e2.value.compareTo(e1.value);
            if (diff == 0) diff = e2.value.compareTo(e1.value);
            return diff;
          });
      }
      break;
    case UtxoSelectionStrategy.SmallFirst:
      {
        sortedUtxos = map.values.toList()
          ..sort((e1, e2) {
            var diff = e1.value.compareTo(e2.value);
            if (diff == 0) diff = e1.value.compareTo(e2.value);
            return diff;
          });
      }
  }
  return sortedUtxos;
}