diff --git a/lib/core/src/Cardano/Wallet/DB/Sqlite.hs b/lib/core/src/Cardano/Wallet/DB/Sqlite.hs index 6a80942b7c4..6c82aa4b350 100644 --- a/lib/core/src/Cardano/Wallet/DB/Sqlite.hs +++ b/lib/core/src/Cardano/Wallet/DB/Sqlite.hs @@ -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 @@ -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 @@ -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 } @@ -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 @@ -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 @@ -366,7 +366,9 @@ 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 ] @@ -374,7 +376,9 @@ mkWalletMetadataUpdate meta = 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) } diff --git a/lib/core/src/Cardano/Wallet/DB/SqliteTypes.hs b/lib/core/src/Cardano/Wallet/DB/SqliteTypes.hs index 3552dbabb9f..8f32e1ebe32 100644 --- a/lib/core/src/Cardano/Wallet/DB/SqliteTypes.hs +++ b/lib/core/src/Cardano/Wallet/DB/SqliteTypes.hs @@ -9,7 +9,8 @@ module Cardano.Wallet.DB.SqliteTypes where import Prelude import Cardano.Wallet.Primitive.Types - ( Coin (..) + ( Address (..) + , Coin (..) , Direction (..) , Hash (..) , SlotId (..) @@ -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 diff --git a/lib/core/test/unit/Cardano/Wallet/DB/SqliteSpec.hs b/lib/core/test/unit/Cardano/Wallet/DB/SqliteSpec.hs index 76216b352b3..5a5882d2ad2 100644 --- a/lib/core/test/unit/Cardano/Wallet/DB/SqliteSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/DB/SqliteSpec.hs @@ -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 (..) @@ -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 @@ -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 } @@ -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 }