Skip to content

Commit

Permalink
Factor out common type expression into ApiTxOutput type synonym.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Apr 27, 2022
1 parent 2fc0a28 commit f7b1137
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ data ApiSelectCoinsData (n :: NetworkDiscriminant)
deriving (Eq, Generic, Show, Typeable)

data ApiSelectCoinsPayments (n :: NetworkDiscriminant) = ApiSelectCoinsPayments
{ payments :: NonEmpty (AddressAmount (ApiT Address, Proxy n))
{ payments :: NonEmpty (ApiTxOutput n)
, withdrawal :: !(Maybe ApiWithdrawalPostData)
, metadata :: !(Maybe (ApiT TxMetadata))
} deriving (Eq, Generic, Show, Typeable)
Expand Down Expand Up @@ -1000,7 +1000,7 @@ data ApiSignTransactionPostData = ApiSignTransactionPostData

-- | Legacy transaction API.
data PostTransactionOldData (n :: NetworkDiscriminant) = PostTransactionOldData
{ payments :: !(NonEmpty (AddressAmount (ApiT Address, Proxy n)))
{ payments :: !(NonEmpty (ApiTxOutput n))
, passphrase :: !(ApiT (Passphrase "lenient"))
, withdrawal :: !(Maybe ApiWithdrawalPostData)
, metadata :: !(Maybe (ApiT TxMetadata))
Expand All @@ -1009,7 +1009,7 @@ data PostTransactionOldData (n :: NetworkDiscriminant) = PostTransactionOldData

-- | Legacy transaction API.
data PostTransactionFeeOldData (n :: NetworkDiscriminant) = PostTransactionFeeOldData
{ payments :: (NonEmpty (AddressAmount (ApiT Address, Proxy n)))
{ payments :: !(NonEmpty (ApiTxOutput n))
, withdrawal :: !(Maybe ApiWithdrawalPostData)
, metadata :: !(Maybe (ApiT TxMetadata))
, timeToLive :: !(Maybe (Quantity "second" NominalDiffTime))
Expand Down Expand Up @@ -1132,6 +1132,10 @@ newtype ApiTxId = ApiTxId
deriving anyclass NFData
deriving Show via (Quiet ApiTxId)

-- | A helper type to reduce the amount of repetition.
--
type ApiTxOutput n = AddressAmount (ApiT Address, Proxy n)

data ApiTransaction (n :: NetworkDiscriminant) = ApiTransaction
{ id :: !(ApiT (Hash "Tx"))
, amount :: !(Quantity "lovelace" Natural)
Expand All @@ -1144,11 +1148,10 @@ data ApiTransaction (n :: NetworkDiscriminant) = ApiTransaction
, depth :: !(Maybe (Quantity "block" Natural))
, direction :: !(ApiT Direction)
, inputs :: ![ApiTxInput n]
, outputs :: ![AddressAmount (ApiT Address, Proxy n)]
, outputs :: ![ApiTxOutput n]
, collateral :: ![ApiTxCollateral n]
, collateralOutputs ::
!(ApiAsArray "collateral_outputs"
(Maybe (AddressAmount (ApiT Address, Proxy n))))
!(ApiAsArray "collateral_outputs" (Maybe (ApiTxOutput n)))
, withdrawals :: ![ApiWithdrawal n]
, mint :: !(ApiT W.TokenMap)
, status :: !(ApiT TxStatus)
Expand Down Expand Up @@ -1194,7 +1197,7 @@ data ApiWalletOutput (n :: NetworkDiscriminant) = ApiWalletOutput
deriving anyclass NFData

data ApiTxOutputGeneral (n :: NetworkDiscriminant) =
ExternalOutput (AddressAmount (ApiT Address, Proxy n))
ExternalOutput (ApiTxOutput n)
| WalletOutput (ApiWalletOutput n)
deriving (Eq, Generic, Show, Typeable)
deriving anyclass NFData
Expand Down Expand Up @@ -1317,7 +1320,7 @@ data ApiWithdrawalPostData
deriving anyclass NFData

data ApiTxInput (n :: NetworkDiscriminant) = ApiTxInput
{ source :: !(Maybe (AddressAmount (ApiT Address, Proxy n)))
{ source :: !(Maybe (ApiTxOutput n))
, input :: !(ApiT TxIn)
} deriving (Eq, Generic, Show, Typeable)
deriving anyclass NFData
Expand Down Expand Up @@ -3268,7 +3271,7 @@ instance
case derPathM of
Nothing -> do
xs <- parseJSON obj
:: Aeson.Parser (AddressAmount (ApiT Address, Proxy n))
:: Aeson.Parser (ApiTxOutput n)
pure $ ExternalOutput xs
Just _ -> do
xs <- parseJSON obj
Expand Down

0 comments on commit f7b1137

Please sign in to comment.