Skip to content

Commit

Permalink
Use ExceptT in validateWitnessCounts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed May 16, 2024
1 parent 5b7add5 commit ac48c37
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3709,19 +3709,20 @@ toOut ((TxOut addr (TokenBundle c tmap)), (Just path)) =
}

validateWitnessCounts
:: Int
:: Monad m
=> Int
-- ^ expected number of key witnesses
-> Int
-- ^ detected number of key witnesses
-> Either ErrSubmitTransaction ()
-> ExceptT ErrSubmitTransaction m ()
validateWitnessCounts expected detected
| expected > detected = Left $
| expected > detected = throwE $
ErrSubmitTransactionMissingWitnesses $
ErrSubmitTransactionMissingWitnessCounts
{ expectedNumberOfKeyWits = toNatural expected
, detectedNumberOfKeyWits = toNatural detected
}
| otherwise = Right ()
| otherwise = pure ()
where
toNatural :: Int -> Natural
toNatural = fromJustNote "validateWitnessCounts.toNatural" . intCastMaybe
Expand Down Expand Up @@ -3772,9 +3773,7 @@ submitTransaction ctx apiw@(ApiT wid) apitx = do
when (countJoinsQuits (apiDecoded ^. #certificates) > 1) $
liftHandler $ throwE ErrSubmitTransactionMultidelegationNotSupported

liftHandler $ except $ validateWitnessCounts
witsRequiredForInputs
totalNumberOfWits
liftHandler $ validateWitnessCounts witsRequiredForInputs totalNumberOfWits

void $ withWorkerCtx ctx wid liftE liftE $ \wrk -> do
let tx = walletTx $ decodeTx tl era sealedTx
Expand Down Expand Up @@ -3921,9 +3920,7 @@ submitSharedTransaction ctx apiw@(ApiT wid) apitx = do
fromIntegral pWitsPerInput * witsRequiredForInputs
let allWitsRequired =
paymentWitsRequired + fromIntegral delegationWitsRequired
liftHandler $ except $ validateWitnessCounts
allWitsRequired
totalNumberOfWits
liftHandler $ validateWitnessCounts allWitsRequired totalNumberOfWits

let txCtx = defaultTransactionCtx
{ txValidityInterval = (Nothing, ttl)
Expand Down

0 comments on commit ac48c37

Please sign in to comment.