Skip to content

Commit

Permalink
Fix PassphraseInfo
Browse files Browse the repository at this point in the history
clean imports
  • Loading branch information
paweljakubas committed May 11, 2019
1 parent a2f5650 commit 53739ab
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 43 deletions.
36 changes: 20 additions & 16 deletions lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ module Cardano.Wallet.DB.Sqlite

import Prelude

import Cardano.Wallet.DB
( DBLayer (..), ErrNoSuchWallet (..), PrimaryKey (..) )
import Cardano.Wallet.DB.SqliteTypes
( AddressScheme (..), TxId (..) )
import Cardano.Wallet.Primitive.Types
( WalletMetadata (..) )
import Conduit
( runResourceT )
import Control.Exception
Expand All @@ -33,12 +39,10 @@ import Control.Monad.Logger
( runNoLoggingT )
import Control.Monad.Trans.Except
( ExceptT (..) )
import qualified Data.ByteString.Char8 as B8
import Data.Generics.Internal.VL.Lens
( (^.) )
import Data.Text
( Text )
import qualified Data.Text as T
import Data.Time.Clock
( UTCTime )
import Data.Word
Expand Down Expand Up @@ -75,18 +79,12 @@ import System.IO
import System.Log.FastLogger
( fromLogStr )

import qualified Data.Set as Set
import qualified Database.Sqlite as Sqlite

import Cardano.Wallet.DB
( DBLayer (..), ErrNoSuchWallet (..), PrimaryKey (..) )
import Cardano.Wallet.DB.SqliteTypes
( AddressScheme (..), TxId (..) )
import Cardano.Wallet.Primitive.Types
( WalletMetadata (..) )

import qualified Cardano.Wallet.Primitive.Model as W
import qualified Cardano.Wallet.Primitive.Types as W
import qualified Data.ByteString.Char8 as B8
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Database.Sqlite as Sqlite

share
[ mkPersist sqlSettings { mpsPrefixFields = False }
Expand All @@ -98,7 +96,7 @@ share
Wallet
walTableId W.WalletId sql=wallet_id
walTableName Text sql=name
walTablePassphraseLastUpdatedAt UTCTime sql=passphrase_last_updated_at
walTablePassphraseLastUpdatedAt UTCTime Maybe sql=passphrase_last_updated_at
walTableStatus W.WalletState sql=status
walTableDelegation Text Maybe sql=delegation
walTableAddressScheme AddressScheme sql=address_discovery
Expand Down Expand Up @@ -357,7 +355,9 @@ mkWalletEntity :: W.WalletId -> W.WalletMetadata -> Wallet
mkWalletEntity wid meta = Wallet
{ walTableId = wid
, walTableName = meta ^. #name . to W.getWalletName
, walTablePassphraseLastUpdatedAt = meta ^. #passphraseInfo . to W.lastUpdatedAt
, walTablePassphraseLastUpdatedAt = case meta ^. #passphraseInfo of
Nothing -> Nothing
Just (W.WalletPassphraseInfo passInfo) -> Just passInfo
, walTableStatus = meta ^. #status
, walTableDelegation = meta ^. #delegation . to delegationToText
, walTableAddressScheme = Sequential -- fixme: depends on wallet
Expand All @@ -366,15 +366,19 @@ mkWalletEntity wid meta = Wallet
mkWalletMetadataUpdate :: W.WalletMetadata -> [Update Wallet]
mkWalletMetadataUpdate meta =
[ WalTableName =. meta ^. #name . to W.getWalletName
, WalTablePassphraseLastUpdatedAt =. meta ^. #passphraseInfo . to W.lastUpdatedAt
, WalTablePassphraseLastUpdatedAt =. case meta ^. #passphraseInfo of
Nothing -> Nothing
Just (W.WalletPassphraseInfo passInfo) -> Just passInfo
, WalTableStatus =. meta ^. #status
, WalTableDelegation =. meta ^. #delegation . to delegationToText
]

metadataFromEntity :: Wallet -> W.WalletMetadata
metadataFromEntity wal = W.WalletMetadata
{ name = W.WalletName (walTableName wal)
, passphraseInfo = W.WalletPassphraseInfo (walTablePassphraseLastUpdatedAt wal)
, passphraseInfo = case walTablePassphraseLastUpdatedAt wal of
Just time -> Just $ W.WalletPassphraseInfo time
Nothing -> Nothing
, status = walTableStatus wal
, delegation = delegationFromText (walTableDelegation wal)
}
Expand Down
16 changes: 2 additions & 14 deletions lib/core/src/Cardano/Wallet/DB/SqliteTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module Cardano.Wallet.DB.SqliteTypes where
import Prelude

import Cardano.Wallet.Primitive.Types
( Coin (..)
( Address (..)
, Coin (..)
, Direction (..)
, Hash (..)
, SlotId (..)
Expand Down Expand Up @@ -61,19 +62,6 @@ import Web.PathPieces

import qualified Data.Text as T

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

Expand Down
26 changes: 13 additions & 13 deletions lib/core/test/unit/Cardano/Wallet/DB/SqliteSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,12 @@ module Cardano.Wallet.DB.SqliteSpec

import Prelude

import Cardano.Wallet.DB.Sqlite
( newDBLayer )
import Crypto.Hash
( hash )
import Data.ByteString
( ByteString )
import Data.Time.Clock
( getCurrentTime )
import Test.Hspec
( Spec, describe, it, shouldReturn )

import Cardano.Wallet
( unsafeRunExceptT )
import Cardano.Wallet.DB
( DBLayer (..), PrimaryKey (..) )
import Cardano.Wallet.DB.Sqlite
( newDBLayer )
import Cardano.Wallet.Primitive.Types
( WalletDelegation (..)
, WalletId (..)
Expand All @@ -33,6 +25,14 @@ import Cardano.Wallet.Primitive.Types
, WalletPassphraseInfo (..)
, WalletState (..)
)
import Crypto.Hash
( hash )
import Data.ByteString
( ByteString )
import Data.Time.Clock
( getCurrentTime )
import Test.Hspec
( Spec, describe, it, shouldReturn )

spec :: Spec
spec = do
Expand All @@ -43,7 +43,7 @@ spec = do
let wid = PrimaryKey (WalletId (hash ("test" :: ByteString)))
md = WalletMetadata
{ name = WalletName "test wallet"
, passphraseInfo = WalletPassphraseInfo now
, passphraseInfo = Just $ WalletPassphraseInfo now
, status = Ready
, delegation = NotDelegating
}
Expand All @@ -56,7 +56,7 @@ spec = do
let wid = PrimaryKey (WalletId (hash ("test" :: ByteString)))
md = WalletMetadata
{ name = WalletName "test wallet"
, passphraseInfo = WalletPassphraseInfo now
, passphraseInfo = Just $ WalletPassphraseInfo now
, status = Ready
, delegation = NotDelegating
}
Expand Down

0 comments on commit 53739ab

Please sign in to comment.