Skip to content

Commit

Permalink
Populate the change field of ApiCoinSelection.
Browse files Browse the repository at this point in the history
Populate the `change` field of `ApiCoinSelection` within
`mkApiCoinSelection`.
  • Loading branch information
jonathanknowles committed Oct 19, 2020
1 parent cd47985 commit 9d57a66
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -167,6 +167,7 @@ import Cardano.Wallet.Api.Types
, ApiByronWallet (..)
, ApiByronWalletBalance (..)
, ApiCoinSelection (..)
, ApiCoinSelectionChange (..)
, ApiCoinSelectionInput (..)
, ApiEpochInfo (ApiEpochInfo)
, ApiErrorCode (..)
Expand Down Expand Up @@ -297,6 +298,7 @@ import Cardano.Wallet.Primitive.Types
, SortOrder (..)
, TransactionInfo (TransactionInfo)
, Tx (..)
, TxChange (..)
, TxIn (..)
, TxOut (..)
, TxStatus (..)
Expand Down Expand Up @@ -1895,15 +1897,16 @@ mkApiCoinSelection
:: forall n input output change.
( input ~ (TxIn, TxOut, NonEmpty DerivationIndex)
, output ~ TxOut
, change ~ TxChange (NonEmpty DerivationIndex)
)
=> Maybe (DelegationAction, NonEmpty DerivationIndex)
-> UnsignedTx input output change
-> ApiCoinSelection n
mkApiCoinSelection mcerts (UnsignedTx inputs outputs _) =
mkApiCoinSelection mcerts (UnsignedTx inputs outputs change) =
ApiCoinSelection
(mkApiCoinSelectionInput <$> inputs)
(mkAddressAmount <$> outputs)
[]
(mkApiCoinSelectionChange <$> change)
(fmap (uncurry mkCertificates) mcerts)
where
mkCertificates
Expand Down Expand Up @@ -1941,6 +1944,17 @@ mkApiCoinSelection mcerts (UnsignedTx inputs outputs _) =
, derivationPath = ApiT <$> path
}

mkApiCoinSelectionChange :: change -> ApiCoinSelectionChange n
mkApiCoinSelectionChange txChange =
ApiCoinSelectionChange
{ address =
(ApiT $ view #address txChange, Proxy @n)
, amount =
Quantity $ fromIntegral $ getCoin $ view #amount txChange
, derivationPath =
ApiT <$> view #derivationPath txChange
}

mkApiTransaction
:: forall n m. Monad m
=> TimeInterpreter m
Expand Down

0 comments on commit 9d57a66

Please sign in to comment.