Skip to content

Commit

Permalink
Last estetic bits
Browse files Browse the repository at this point in the history
Concluding import fixes

Typo fix
  • Loading branch information
paweljakubas committed May 11, 2019
1 parent 385d65c commit ca6be91
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
9 changes: 8 additions & 1 deletion lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ import Data.Time.Clock
import Data.Word
( Word32 )
import Database.Persist.TH
( mkMigrate
, mkPersist
, mpsPrefixFields
, persistLowerCase
, share
, sqlSettings
)
import GHC.Generics
( Generic (..) )

Expand Down Expand Up @@ -62,7 +69,7 @@ PrivateKey sql=private_key
-- blocks).
--
-- TxMeta is specific to a wallet because multiple wallets may have the same
-- transaction with different metdata values. The associated inputs and outputs
-- transaction with different metadata values. The associated inputs and outputs
-- of the transaction are in the TxIn and TxOut tables.
TxMeta
txMetaTableTxId TxId sql=tx_id
Expand Down
43 changes: 26 additions & 17 deletions lib/core/src/Cardano/Wallet/DB/SqliteTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,29 @@ module Cardano.Wallet.DB.SqliteTypes where

import Prelude

import Cardano.Wallet.Primitive.Types
( Coin (..)
, Direction (..)
, Hash (..)
, SlotId (..)
, TxStatus (..)
, WalletId (..)
, WalletState (..)
, flatSlot
, fromFlatSlot
, isValidCoin
)
import Control.Monad
( (>=>) )
import Data.Aeson
( FromJSON (..)
, ToJSON (..)
, Value (..)
, defaultOptions
, genericParseJSON
, genericToJSON
, withText
)
import Data.Aeson.Types
( Parser )
import Data.Bifunctor
Expand All @@ -35,23 +55,12 @@ import Database.Persist.Sqlite
import GHC.Generics
( Generic )
import Web.HttpApiData
( FromHttpApiData (..), ToHttpApiData (..) )
import Web.PathPieces
( PathPiece (..) )

import qualified Data.Text as T

import Cardano.Wallet.Primitive.Types
( Coin (..)
, Direction (..)
, Hash (..)
, SlotId (..)
, TxStatus (..)
, WalletId (..)
, WalletState (..)
, flatSlot
, fromFlatSlot
, isValidCoin
)

----------------------------------------------------------------------------
-- Helper functions

Expand Down Expand Up @@ -117,7 +126,6 @@ instance PathPiece WalletId where
fromPathPiece = fromTextMaybe
toPathPiece = toText


----------------------------------------------------------------------------
-- AddressScheme

Expand All @@ -137,7 +145,7 @@ instance FromText AddressScheme where
"any" -> Right Any
_ ->
Left . TextDecodingError $ show txt
<> " is neither \"sequential\", \"random\", nor \"any\""
<> " is neither \"sequential\", \"random\", nor \"any\""

instance ToText AddressScheme where
toText Sequential = "sequential"
Expand Down Expand Up @@ -231,8 +239,9 @@ instance PersistFieldSql TxStatus where
-- Coin

mkCoin :: Word64 -> Either Text Coin
mkCoin n | isValidCoin c = Right c
| otherwise = Left . T.pack $ "not a valid coin: " <> show n
mkCoin n
| isValidCoin c = Right c
| otherwise = Left . T.pack $ "not a valid coin: " <> show n
where c = Coin n

instance PersistField Coin where
Expand Down
6 changes: 3 additions & 3 deletions lib/text-class/test/unit/Data/Text/ClassSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ spec = do
$ property $ \(i :: Int) -> (fromText . toText) i === pure i
it "fromText ~ fromTextMaybe" $
property $ \(Digits t) ->
classify (isNothing (fromTextMaybe @Int t)) "invalid" $
classify ((compare 0 <$> fromTextMaybe @Int t) == Just GT) "valid negative" $
toList (fromTextMaybe @Int t) === toList (fromText t)
classify (isNothing (fromTextMaybe @Int t)) "invalid" $
classify ((compare 0 <$> fromTextMaybe @Int t) == Just GT) "valid negative" $
toList (fromTextMaybe @Int t) === toList (fromText t)

describe "Text" $ do
it "fromText \"patate\"" $
Expand Down

0 comments on commit ca6be91

Please sign in to comment.