Skip to content

Commit

Permalink
Replace Coin with Quantity "lovelace" in a few places
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Jan 15, 2021
1 parent ca6ebfe commit 2e65af8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -223,6 +223,8 @@ import Cardano.Wallet.Api.Types
, WalletPostData (..)
, WalletPutData (..)
, WalletPutPassphraseData (..)
, coinFromQuantity
, coinToQuantity
, getApiMnemonicT
, toApiEpochInfo
, toApiNetworkParameters
Expand Down Expand Up @@ -2020,8 +2022,7 @@ mkApiCoinSelection deps mcerts (UnsignedTx inputs outputs change) =
{ id = ApiT txid
, index = index
, address = (ApiT addr, Proxy @n)
, amount = Quantity $
fromIntegral $ unCoin $ TokenBundle.getCoin tokens
, amount = coinToQuantity $ TokenBundle.getCoin tokens
, derivationPath = ApiT <$> path
}

Expand Down Expand Up @@ -2162,8 +2163,8 @@ mkApiWithdrawal (acct, c) =
coerceCoin
:: forall (n :: NetworkDiscriminant). AddressAmount (ApiT Address, Proxy n)
-> TxOut
coerceCoin (AddressAmount (ApiT addr, _) (Quantity c) (ApiT assets)) =
TxOut addr (TokenBundle.TokenBundle (Coin $ fromIntegral c) assets)
coerceCoin (AddressAmount (ApiT addr, _) c (ApiT assets)) =
TxOut addr (TokenBundle.TokenBundle (coinFromQuantity c) assets)

natural :: Quantity q Word32 -> Quantity q Natural
natural = Quantity . fromIntegral . getQuantity
Expand Down
8 changes: 8 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Expand Up @@ -114,6 +114,8 @@ module Cardano.Wallet.Api.Types
, ApiWithdrawal (..)
, ApiWalletSignData (..)
, ApiVerificationKey (..)
, coinToQuantity
, coinFromQuantity

-- * API Types (Byron)
, ApiByronWallet (..)
Expand Down Expand Up @@ -830,6 +832,12 @@ data AddressAmount addr = AddressAmount
} deriving (Eq, Generic, Show)
deriving anyclass NFData

coinToQuantity :: Integral n => Coin -> Quantity "lovelace" n
coinToQuantity = Quantity . fromIntegral . unCoin

coinFromQuantity :: Integral n => Quantity "lovelace" n -> Coin
coinFromQuantity = Coin . fromIntegral . getQuantity

newtype ApiAddressInspect = ApiAddressInspect
{ unApiAddressInspect :: Aeson.Value }
deriving (Eq, Generic, Show)
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/DB/Sqlite/TH.hs
Expand Up @@ -107,7 +107,7 @@ TxMeta
txMetaDirection W.Direction sql=direction
txMetaSlot SlotNo sql=slot
txMetaBlockHeight Word32 sql=block_height
txMetaAmount Natural sql=amount
txMetaAmount W.Coin sql=amount
txMetadata W.TxMetadata Maybe sql=data
txMetaSlotExpires SlotNo Maybe sql=slot_expires
txMetaFee Natural Maybe sql=fee
Expand Down

0 comments on commit 2e65af8

Please sign in to comment.