DBOp
( FindProject,
ReadWorkIndex
),
MonadDB,
findAccountPaymentAddress,
findUserPaymentAddress,
liftdb,
raiseSubjectNotFound,
)
do
project' <-
let projectOp = FindProject pid
in maybe (raiseSubjectNotFound projectOp) pure =<< liftdb projectOp
widx <- liftdb $ ReadWorkIndex pid
pure $ TL.payouts (TL.toDepF $ project' ^. depRules) ptime widx
newtype MinPayout c = MinPayout c
if amt <= minAmt
then pure mempty
else do
-- Multiply the total by each payout fraction. This may fail, so traverse.
let scaled ws = note AmountInvalid $ cscale amt (ws ^. TL.wsShare)
payoutFractions <- except $ traverse scaled (payouts ^. TL.creditToShares)
fromListWith (<>) . join
<$> traverse (uncurry (getPayoutAmounts t currency mp)) (assocs payoutFractions)
case creditTo of
(TL.CreditToAccount aid) ->
fmap (,amt) . maybeToList <$> (lift . runMaybeT $ findAccountPaymentAddress aid network)
(TL.CreditToUser uid) ->
fmap (,amt) . maybeToList <$> (lift . runMaybeT $ findUserPaymentAddress uid network)
(TL.CreditToProject pid) -> do
payouts <- lift $ getProjectPayoutFractions t pid
assocs <$> getPayouts t network mp amt payouts
(