chooseCoinsSink :: (Monad m, Coin c)
                => Word64 -- ^ Target price to pay.
                -> Word64 -- ^ Fee price per 1000 bytes.
                -> Bool   -- ^ Try to find better solution when one is found
                -> Sink c m (Either String ([c], Word64))
                   -- ^ Coin selection result and change amount.
chooseCoinsSink target kbfee continue
    | target > 0 =
        maybeToEither err <$> greedyAddSink target (getFee kbfee) continue
    | otherwise = return $ Left "chooseCoins: Target must be > 0"
  where
    err = "chooseCoins: No solution found"

-- | Coin selection algorithm for multisignature transactions. This function
-- returns the selected coins together with the amount of change to send back
-- to yourself, taking the fee into account. This function assumes all the
-- coins are script hash outputs that send funds to a multisignature address.
chooseCoinsSink :: (Monad m, Coin c)
                => Word64 -- ^ Target price to pay.
                -> Word64 -- ^ Fee price per 1000 bytes.
                -> Bool   -- ^ Try to find better solution when one is found
                -> Sink c m (Either String ([c], Word64))
chooseCoinsSink target kbfee continue
    | target > 0 =
        maybeToEither err <$> greedyAddSink target (getFee kbfee) continue
    | otherwise = return $ Left "chooseCoins: Target must be > 0"
  where
    err = "chooseCoins: No solution found"

-- | Coin selection algorithm for multisignature transactions. This function
-- returns the selected coins together with the amount of change to send back
-- to yourself, taking the fee into account. This function assumes all the
-- coins are script hash outputs that send funds to a multisignature address.
chooseCoinsSink target kbfee continue
    | target > 0 =
        maybeToEither err <$> greedyAddSink target (getFee kbfee) continue
    | otherwise = return $ Left "chooseCoins: Target must be > 0"
  where
    err = "chooseCoins: No solution found"

-- | Coin selection algorithm for multisignature transactions. This function
-- returns the selected coins together with the amount of change to send back
-- to yourself, taking the fee into account. This function assumes all the
-- coins are script hash outputs that send funds to a multisignature address.