Skip to content

Commit

Permalink
Use Void type in function signTx for added safety.
Browse files Browse the repository at this point in the history
This function is currently only used in contexts where all change outputs
have been assigned with addresses and are included in the set of ordinary
outputs. We use the 'Void' type here to prevent callers from accidentally
passing change values into this function.
  • Loading branch information
jonathanknowles committed Oct 16, 2020
1 parent 66667b6 commit d406c93
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ import Data.Type.Equality
( (:~:) (..), testEquality )
import Data.Vector.Shuffle
( shuffle )
import Data.Void
( Void )
import Data.Word
( Word16, Word64 )
import Fmt
Expand Down Expand Up @@ -1622,7 +1624,7 @@ signPayment ctx wid argGenChange mkRewardAccount pwd md cs = db & \DBLayer{..} -

-- | Very much like 'signPayment', but doesn't not generate change addresses.
signTx
:: forall ctx s t k input output change.
:: forall ctx s t k input output.
( HasTransactionLayer t k ctx
, HasDBLayer s k ctx
, HasNetworkLayer t ctx
Expand All @@ -1638,7 +1640,11 @@ signTx
-> WalletId
-> Passphrase "raw"
-> Maybe TxMetadata
-> UnsignedTx input output change
-- This function is currently only used in contexts where all change outputs
-- have been assigned with addresses and are included in the set of ordinary
-- outputs. We use the 'Void' type here to prevent callers from accidentally
-- passing change values into this function:
-> UnsignedTx input output Void
-> ExceptT ErrSignPayment IO (Tx, TxMeta, UTCTime, SealedTx)
signTx ctx wid pwd md (UnsignedTx inpsNE outsNE _change) = db & \DBLayer{..} ->
withRootKey @_ @s ctx wid pwd ErrSignPaymentWithRootKey $ \xprv scheme -> do
Expand Down

0 comments on commit d406c93

Please sign in to comment.