diff --git a/wallet-new/cardano-sl-wallet-new.cabal b/wallet-new/cardano-sl-wallet-new.cabal index d491df85361..a2005a7b5ea 100755 --- a/wallet-new/cardano-sl-wallet-new.cabal +++ b/wallet-new/cardano-sl-wallet-new.cabal @@ -124,7 +124,6 @@ library Cardano.Wallet.Util Cardano.Wallet.WalletLayer - Cardano.Wallet.WalletLayer.Types Cardano.Wallet.WalletLayer.ExecutionTimeLimit -- * Useful for testing, especially in the fixture side. Cardano.Wallet.WalletLayer.Kernel.Accounts @@ -133,11 +132,10 @@ library Cardano.Wallet.WalletLayer.Kernel.Conv Cardano.Wallet.WalletLayer.Kernel.Transactions Cardano.Wallet.WalletLayer.Kernel.Wallets - - other-modules: Cardano.Wallet.WalletLayer.Kernel - Cardano.Wallet.WalletLayer.Legacy + Cardano.Wallet.WalletLayer.Kernel Cardano.Wallet.WalletLayer.Error - Paths_cardano_sl_wallet_new + + other-modules: Paths_cardano_sl_wallet_new ghc-options: -Wall build-depends: base diff --git a/wallet-new/server/Main.hs b/wallet-new/server/Main.hs index 47988d8c754..1af75a08890 100644 --- a/wallet-new/server/Main.hs +++ b/wallet-new/server/Main.hs @@ -50,8 +50,8 @@ import Cardano.Wallet.Server.CLI (ChooseWalletBackend (..), WalletStartupOptions (..), getWalletNodeOptions, walletDbPath, walletFlushDb, walletRebuildDb) import qualified Cardano.Wallet.Server.Plugins as Plugins -import Cardano.Wallet.WalletLayer (PassiveWalletLayer, - bracketKernelPassiveWallet) +import Cardano.Wallet.WalletLayer (PassiveWalletLayer) +import qualified Cardano.Wallet.WalletLayer.Kernel as WalletLayer.Kernel -- | Default logger name when one is not provided on the command line defaultLoggerName :: LoggerName @@ -134,7 +134,7 @@ actionWithNewWallet pm txpConfig sscParams nodeParams params = userSecret <- readTVarIO (ncUserSecret $ nrContext nr) let nodeState = NodeStateAdaptor.newNodeStateAdaptor nr liftIO $ Keystore.bracketLegacyKeystore userSecret $ \keystore -> do - bracketKernelPassiveWallet logMessage' keystore nodeState $ \walletLayer passiveWallet -> do + WalletLayer.Kernel.bracketPassiveWallet logMessage' keystore nodeState $ \walletLayer passiveWallet -> do Kernel.init passiveWallet Kernel.Mode.runWalletMode pm txpConfig diff --git a/wallet-new/src/Cardano/Wallet/API/V1/Handlers.hs b/wallet-new/src/Cardano/Wallet/API/V1/Handlers.hs index 41cb944b757..a6a4965571e 100644 --- a/wallet-new/src/Cardano/Wallet/API/V1/Handlers.hs +++ b/wallet-new/src/Cardano/Wallet/API/V1/Handlers.hs @@ -9,8 +9,8 @@ import qualified Cardano.Wallet.API.V1.Handlers.Addresses as Addresses import qualified Cardano.Wallet.API.V1.Handlers.Transactions as Transactions import qualified Cardano.Wallet.API.V1.Handlers.Wallets as Wallets -import Cardano.Wallet.WalletLayer (ActiveWalletLayer) -import Cardano.Wallet.WalletLayer.Types (walletPassiveLayer) +import Cardano.Wallet.WalletLayer (ActiveWalletLayer, + walletPassiveLayer) handlers :: ActiveWalletLayer IO -> Server V1.API diff --git a/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Accounts.hs b/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Accounts.hs index 49172c9bd64..96e3cb33c66 100644 --- a/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Accounts.hs +++ b/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Accounts.hs @@ -14,8 +14,8 @@ import Cardano.Wallet.API.Response import qualified Cardano.Wallet.API.V1.Accounts as Accounts import Cardano.Wallet.API.V1.Types import qualified Cardano.Wallet.Kernel.DB.Util.IxSet as KernelIxSet -import Cardano.Wallet.WalletLayer.Types (PassiveWalletLayer) -import qualified Cardano.Wallet.WalletLayer.Types as WalletLayer +import Cardano.Wallet.WalletLayer (PassiveWalletLayer) +import qualified Cardano.Wallet.WalletLayer as WalletLayer handlers :: PassiveWalletLayer IO -> ServerT Accounts.API Handler handlers w = deleteAccount w diff --git a/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Addresses.hs b/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Addresses.hs index 420968c6326..89f6e124e3c 100644 --- a/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Addresses.hs +++ b/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Addresses.hs @@ -7,8 +7,8 @@ import Universum import Servant -import Cardano.Wallet.WalletLayer.Types (PassiveWalletLayer) -import qualified Cardano.Wallet.WalletLayer.Types as WalletLayer +import Cardano.Wallet.WalletLayer (PassiveWalletLayer) +import qualified Cardano.Wallet.WalletLayer as WalletLayer import Cardano.Wallet.API.Request import Cardano.Wallet.API.Response diff --git a/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Transactions.hs b/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Transactions.hs index 4ebb4b51e9a..00734ef046a 100644 --- a/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Transactions.hs +++ b/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Transactions.hs @@ -28,9 +28,9 @@ import Cardano.Wallet.Kernel.CoinSelection.FromGeneric (ExpenseRegulation (..), InputGrouping (..)) import Cardano.Wallet.Kernel.Util.Core (getCurrentTimestamp, paymentAmount) -import qualified Cardano.Wallet.WalletLayer as WalletLayer -import Cardano.Wallet.WalletLayer.Types (ActiveWalletLayer, +import Cardano.Wallet.WalletLayer (ActiveWalletLayer, PassiveWalletLayer) +import qualified Cardano.Wallet.WalletLayer as WalletLayer handlers :: ActiveWalletLayer IO -> ServerT Transactions.API Handler handlers aw = newTransaction aw diff --git a/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Wallets.hs b/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Wallets.hs index f5a17e3b6dd..370d85ea445 100644 --- a/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Wallets.hs +++ b/wallet-new/src/Cardano/Wallet/API/V1/Handlers/Wallets.hs @@ -8,7 +8,7 @@ import Cardano.Wallet.API.V1.Types as V1 import qualified Cardano.Wallet.API.V1.Wallets as Wallets import Cardano.Wallet.WalletLayer (PassiveWalletLayer (..)) -import qualified Cardano.Wallet.WalletLayer.Types as WalletLayer +import qualified Cardano.Wallet.WalletLayer as WalletLayer import qualified Cardano.Wallet.Kernel.DB.Util.IxSet as KernelIxSet import qualified Data.IxSet.Typed as IxSet diff --git a/wallet-new/src/Cardano/Wallet/Server/Plugins.hs b/wallet-new/src/Cardano/Wallet/Server/Plugins.hs index 7aeed47afc5..b3fb64c1d1e 100644 --- a/wallet-new/src/Cardano/Wallet/Server/Plugins.hs +++ b/wallet-new/src/Cardano/Wallet/Server/Plugins.hs @@ -30,7 +30,8 @@ import Cardano.Wallet.Server.CLI (NewWalletBackendParams (..), RunMode, WalletBackendParams (..), isDebugMode, walletAcidInterval, walletDbOptions) import Cardano.Wallet.WalletLayer (ActiveWalletLayer, - PassiveWalletLayer, bracketKernelActiveWallet) + PassiveWalletLayer) +import qualified Cardano.Wallet.WalletLayer.Kernel as WalletLayer.Kernel import qualified Pos.Wallet.Web.Error.Types as V0 import Control.Exception (fromException) @@ -203,7 +204,7 @@ walletBackend protocolMagic (NewWalletBackendParams WalletBackendParams{..}) (pa pure $ \diffusion -> do env <- ask let diffusion' = Kernel.fromDiffusion (lower env) diffusion - bracketKernelActiveWallet protocolMagic passiveLayer passiveWallet diffusion' $ \active _ -> do + WalletLayer.Kernel.bracketActiveWallet protocolMagic passiveLayer passiveWallet diffusion' $ \active _ -> do ctx <- view shutdownContext let portCallback :: Word16 -> IO () diff --git a/wallet-new/src/Cardano/Wallet/WalletLayer.hs b/wallet-new/src/Cardano/Wallet/WalletLayer.hs index 50a18a8e0dc..ff3751131e2 100644 --- a/wallet-new/src/Cardano/Wallet/WalletLayer.hs +++ b/wallet-new/src/Cardano/Wallet/WalletLayer.hs @@ -1,59 +1,587 @@ module Cardano.Wallet.WalletLayer - ( -- * Kernel - bracketKernelPassiveWallet - , bracketKernelActiveWallet - -- * Legacy - , bracketLegacyPassiveWallet - , bracketLegacyActiveWallet - -- * We re-export the types since we want all the dependencies - -- in this module, other modules shouldn't be touched. - , module Types + ( PassiveWalletLayer (..) + , ActiveWalletLayer (..) + -- * Getters + , createWallet + , getWallets + , getWallet + , updateWallet + , updateWalletPassword + , deleteWallet + + , createAccount + , getAccounts + , getAccount + , updateAccount + , deleteAccount + + , createAddress + , getAddresses + , validateAddress + + , getTransactions + + , applyBlocks + , rollbackBlocks + -- * Errors + , CreateWalletError(..) + , GetWalletError(..) + , UpdateWalletError(..) + , UpdateWalletPasswordError(..) + , DeleteWalletError(..) + , NewPaymentError(..) + , EstimateFeesError(..) + , RedeemAdaError(..) + , CreateAddressError(..) + , ValidateAddressError(..) + , CreateAccountError(..) + , GetAccountError(..) + , GetAccountsError(..) + , GetTxError(..) + , DeleteAccountError(..) + , UpdateAccountError(..) ) where import Universum -import System.Wlog (Severity) +import Control.Lens (makeLenses) +import Formatting (bprint, build, formatToString, (%)) +import qualified Formatting.Buildable +import qualified Prelude +import Test.QuickCheck (Arbitrary (..), oneof) -import Cardano.Wallet.Kernel.Diffusion (WalletDiffusion (..)) +import Pos.Chain.Block (Blund) +import Pos.Core (Coin) +import Pos.Core.Chrono (NE, NewestFirst (..), OldestFirst (..)) +import Pos.Core.Txp (Tx) +import Pos.Crypto (PassPhrase) -import Cardano.Wallet.Kernel (ActiveWallet, PassiveWallet) -import Cardano.Wallet.Kernel.Keystore (Keystore) -import Cardano.Wallet.Kernel.NodeStateAdaptor (NodeStateAdaptor) -import qualified Cardano.Wallet.WalletLayer.Kernel as Kernel -import qualified Cardano.Wallet.WalletLayer.Legacy as Legacy -import Cardano.Wallet.WalletLayer.Types as Types -import Pos.Core.Configuration (ProtocolMagic) +import Cardano.Wallet.API.Request (RequestParams (..)) +import Cardano.Wallet.API.Request.Filter (FilterOperations (..)) +import Cardano.Wallet.API.Request.Sort (SortOperations (..)) +import Cardano.Wallet.API.Response (SliceOf (..), WalletResponse) +import Cardano.Wallet.API.V1.Types (Account, AccountIndex, + AccountUpdate, Address, NewAccount, NewAddress, NewWallet, + PasswordUpdate, Payment, Redemption, Transaction, V1 (..), + Wallet, WalletAddress, WalletId, WalletUpdate) +import qualified Cardano.Wallet.Kernel.Accounts as Kernel +import qualified Cardano.Wallet.Kernel.Addresses as Kernel +import Cardano.Wallet.Kernel.CoinSelection.FromGeneric + (ExpenseRegulation, InputGrouping) +import qualified Cardano.Wallet.Kernel.DB.HdWallet as Kernel +import Cardano.Wallet.Kernel.DB.Util.IxSet (IxSet) +import qualified Cardano.Wallet.Kernel.Transactions as Kernel +import qualified Cardano.Wallet.Kernel.Wallets as Kernel +import Cardano.Wallet.WalletLayer.ExecutionTimeLimit + (TimeExecutionLimit) ------------------------------------------------------------ --- Kernel +-- Errors when manipulating wallets ------------------------------------------------------------ -bracketKernelPassiveWallet - :: forall m n a. (MonadIO m, MonadIO n, MonadMask n) - => (Severity -> Text -> IO ()) - -> Keystore - -> NodeStateAdaptor IO - -> (PassiveWalletLayer m -> PassiveWallet -> n a) -> n a -bracketKernelPassiveWallet = Kernel.bracketPassiveWallet -bracketKernelActiveWallet - :: forall m n a. (MonadIO n, MonadMask n, MonadIO m) - => ProtocolMagic - -> PassiveWalletLayer m - -> PassiveWallet - -> WalletDiffusion - -> (ActiveWalletLayer m -> ActiveWallet -> n a) -> n a -bracketKernelActiveWallet = Kernel.bracketActiveWallet +data CreateWalletError = + CreateWalletError Kernel.CreateWalletError + | CreateWalletFirstAccountCreationFailed Kernel.CreateAccountError + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show CreateWalletError where + show = formatToString build + +instance Exception CreateWalletError + +instance Arbitrary CreateWalletError where + arbitrary = oneof [ CreateWalletError <$> arbitrary + , CreateWalletFirstAccountCreationFailed <$> arbitrary + ] + +instance Buildable CreateWalletError where + build (CreateWalletError kernelError) = + bprint ("CreateWalletError " % build) kernelError + build (CreateWalletFirstAccountCreationFailed kernelError) = + bprint ("CreateWalletFirstAccountCreationFailed " % build) kernelError + +data GetWalletError = + GetWalletError (V1 Kernel.UnknownHdRoot) + | GetWalletErrorNotFound WalletId + -- ^ Error thrown by the legacy wallet layer, isomorphic to the one above, + -- which is new-data-layer specific. + | GetWalletWalletIdDecodingFailed Text + deriving Eq + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show GetWalletError where + show = formatToString build + +instance Exception GetWalletError + +instance Buildable GetWalletError where + build (GetWalletError (V1 kernelError)) = + bprint ("GetWalletError " % build) kernelError + build (GetWalletErrorNotFound walletId) = + bprint ("GetWalletErrorNotFound " % build) walletId + build (GetWalletWalletIdDecodingFailed txt) = + bprint ("GetWalletWalletIdDecodingFailed " % build) txt + +data UpdateWalletError = + UpdateWalletError (V1 Kernel.UnknownHdRoot) + | UpdateWalletErrorNotFound WalletId + -- ^ Error thrown by the legacy wallet layer, isomorphic to the one above, + -- which is new-data-layer specific. + | UpdateWalletWalletIdDecodingFailed Text + deriving Eq + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show UpdateWalletError where + show = formatToString build + +instance Exception UpdateWalletError + +instance Buildable UpdateWalletError where + build (UpdateWalletError (V1 kernelError)) = + bprint ("UpdateWalletError " % build) kernelError + build (UpdateWalletErrorNotFound walletId) = + bprint ("UpdateWalletErrorNotFound " % build) walletId + build (UpdateWalletWalletIdDecodingFailed txt) = + bprint ("UpdateWalletWalletIdDecodingFailed " % build) txt + +data UpdateWalletPasswordError = + UpdateWalletPasswordWalletIdDecodingFailed Text + | UpdateWalletPasswordError Kernel.UpdateWalletPasswordError + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show UpdateWalletPasswordError where + show = formatToString build + +instance Exception UpdateWalletPasswordError + +instance Buildable UpdateWalletPasswordError where + build (UpdateWalletPasswordWalletIdDecodingFailed txt) = + bprint ("UpdateWalletPasswordWalletIdDecodingFailed " % build) txt + build (UpdateWalletPasswordError kernelError) = + bprint ("UpdateWalletPasswordError " % build) kernelError + +data DeleteWalletError = + DeleteWalletWalletIdDecodingFailed Text + | DeleteWalletError (V1 Kernel.UnknownHdRoot) + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show DeleteWalletError where + show = formatToString build + +instance Exception DeleteWalletError + +instance Buildable DeleteWalletError where + build (DeleteWalletWalletIdDecodingFailed txt) = + bprint ("DeleteWalletWalletIdDecodingFailed " % build) txt + build (DeleteWalletError kernelError) = + bprint ("DeleteWalletError " % build) kernelError + +------------------------------------------------------------ +-- Errors when dealing with addresses +------------------------------------------------------------ + +data CreateAddressError = + CreateAddressError Kernel.CreateAddressError + | CreateAddressAddressDecodingFailed Text + -- ^ Decoding the input 'Text' as an 'Address' failed. + deriving Eq + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show CreateAddressError where + show = formatToString build +instance Exception CreateAddressError + +instance Arbitrary CreateAddressError where + arbitrary = oneof [ CreateAddressError <$> arbitrary + , pure (CreateAddressAddressDecodingFailed "Ae2tdPwUPEZ18ZjTLnLVr9CEvUEUX4eW1LBHbxxx") + ] + +instance Buildable CreateAddressError where + build (CreateAddressError kernelError) = + bprint ("CreateAddressError " % build) kernelError + build (CreateAddressAddressDecodingFailed txt) = + bprint ("CreateAddressAddressDecodingFailed " % build) txt + +data ValidateAddressError = + ValidateAddressDecodingFailed Text + -- ^ When trying to decode this raw 'Text' into a proper Cardano + -- 'Address' the decoding failed. Unfortunately we are not able to + -- provide a more accurate error description as 'decodeTextAddress' doesn't + -- offer such. + | ValidateAddressNotOurs Address + -- ^ The input address is a valid 'Cardano' address, but it doesn't + -- belong to us. + deriving Eq + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show ValidateAddressError where + show = formatToString build + +instance Exception ValidateAddressError + +instance Buildable ValidateAddressError where + build (ValidateAddressDecodingFailed rawText) = + bprint ("ValidateAddressDecodingFailed " % build) rawText + build (ValidateAddressNotOurs address) = + bprint ("ValidateAddressNotOurs " % build) address + +------------------------------------------------------------ +-- Errors when dealing with Accounts ------------------------------------------------------------ --- Legacy + +data CreateAccountError = + CreateAccountError Kernel.CreateAccountError + | CreateAccountWalletIdDecodingFailed Text + -- ^ Decoding the parent's 'WalletId' from a raw 'Text' failed. + | CreateAccountFirstAddressGenerationFailed Kernel.CreateAddressError + -- ^ When trying to create the first 'Address' to go in tandem with this + -- 'Account', the generation failed. + deriving Eq + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show CreateAccountError where + show = formatToString build + +instance Exception CreateAccountError + +instance Buildable CreateAccountError where + build (CreateAccountError kernelError) = + bprint ("CreateAccountError " % build) kernelError + build (CreateAccountWalletIdDecodingFailed txt) = + bprint ("CreateAccountWalletIdDecodingFailed " % build) txt + build (CreateAccountFirstAddressGenerationFailed kernelError) = + bprint ("CreateAccountFirstAddressGenerationFailed " % build) kernelError + +data GetAccountError = + GetAccountError (V1 Kernel.UnknownHdAccount) + | GetAccountWalletIdDecodingFailed Text + deriving Eq + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show GetAccountError where + show = formatToString build + +instance Exception GetAccountError + +instance Buildable GetAccountError where + build (GetAccountError kernelError) = + bprint ("GetAccountError " % build) kernelError + build (GetAccountWalletIdDecodingFailed txt) = + bprint ("GetAccountWalletIdDecodingFailed " % build) txt + +data DeleteAccountError = + DeleteAccountError (V1 Kernel.UnknownHdAccount) + | DeleteAccountWalletIdDecodingFailed Text + deriving Eq + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show DeleteAccountError where + show = formatToString build + +instance Exception DeleteAccountError + +instance Buildable DeleteAccountError where + build (DeleteAccountError kernelError) = + bprint ("DeleteAccountError " % build) kernelError + build (DeleteAccountWalletIdDecodingFailed txt) = + bprint ("DeleteAccountWalletIdDecodingFailed " % build) txt + +data GetAccountsError = + GetAccountsError Kernel.UnknownHdRoot + | GetAccountsWalletIdDecodingFailed Text + deriving Eq + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show GetAccountsError where + show = formatToString build + +instance Exception GetAccountsError + +instance Buildable GetAccountsError where + build (GetAccountsError kernelError) = + bprint ("GetAccountsError " % build) kernelError + build (GetAccountsWalletIdDecodingFailed txt) = + bprint ("GetAccountsWalletIdDecodingFailed " % build) txt + +data UpdateAccountError = + UpdateAccountError (V1 Kernel.UnknownHdAccount) + | UpdateAccountWalletIdDecodingFailed Text + deriving Eq + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show UpdateAccountError where + show = formatToString build + +instance Exception UpdateAccountError + +instance Buildable UpdateAccountError where + build (UpdateAccountError kernelError) = + bprint ("UpdateAccountError " % build) kernelError + build (UpdateAccountWalletIdDecodingFailed txt) = + bprint ("UpdateAccountWalletIdDecodingFailed " % build) txt + ------------------------------------------------------------ +-- Errors when getting Transactions +------------------------------------------------------------ + +data GetTxError = + GetTxMissingWalletIdError + | GetTxAddressDecodingFailed Text + | GetTxInvalidSortingOperaration String + +instance Show GetTxError where + show = formatToString build + +instance Buildable GetTxError where + build GetTxMissingWalletIdError = + bprint "GetTxMissingWalletIdError " + build (GetTxAddressDecodingFailed txt) = + bprint ("GetTxAddressDecodingFailed " % build) txt + build (GetTxInvalidSortingOperaration txt) = + bprint ("GetTxInvalidSortingOperaration " % build) txt + + +instance Arbitrary GetTxError where + arbitrary = oneof [ pure GetTxMissingWalletIdError + , pure (GetTxAddressDecodingFailed "by_amount") + , pure (GetTxInvalidSortingOperaration "123") + ] + +instance Exception GetTxError + +------------------------------------------------------------ +-- Passive wallet layer +------------------------------------------------------------ + +-- | The passive wallet (data) layer. See @PassiveWallet@. +data PassiveWalletLayer m = PassiveWalletLayer + { + -- * wallets + _pwlCreateWallet :: NewWallet -> m (Either CreateWalletError Wallet) + , _pwlGetWallets :: m (IxSet Wallet) + , _pwlGetWallet :: WalletId -> m (Either GetWalletError Wallet) + , _pwlUpdateWallet :: WalletId + -> WalletUpdate + -> m (Either UpdateWalletError Wallet) + , _pwlUpdateWalletPassword :: WalletId + -> PasswordUpdate + -> m (Either UpdateWalletPasswordError Wallet) + , _pwlDeleteWallet :: WalletId -> m (Either DeleteWalletError ()) + -- * accounts + , _pwlCreateAccount :: WalletId + -> NewAccount + -> m (Either CreateAccountError Account) + , _pwlGetAccounts :: WalletId + -> m (Either GetAccountsError (IxSet Account)) + , _pwlGetAccount :: WalletId + -> AccountIndex + -> m (Either GetAccountError Account) + , _pwlUpdateAccount :: WalletId + -> AccountIndex + -> AccountUpdate + -> m (Either UpdateAccountError Account) + , _pwlDeleteAccount :: WalletId + -> AccountIndex + -> m (Either DeleteAccountError ()) + -- * addresses + , _pwlCreateAddress :: NewAddress + -> m (Either CreateAddressError WalletAddress) + , _pwlGetAddresses :: RequestParams -> m (SliceOf WalletAddress) + , _pwlValidateAddress :: Text + -> m (Either ValidateAddressError WalletAddress) + + -- * transactions + , _pwlGetTransactions :: Maybe WalletId -> Maybe AccountIndex -> Maybe (V1 Address) + -> RequestParams -> FilterOperations Transaction -> SortOperations Transaction -> m (Either GetTxError (WalletResponse [Transaction])) + + -- * core API + , _pwlApplyBlocks :: OldestFirst NE Blund -> m () + , _pwlRollbackBlocks :: NewestFirst NE Blund -> m () + } + +makeLenses ''PassiveWalletLayer + +------------------------------------------------------------ +-- Passive wallet layer getters +------------------------------------------------------------ + +createWallet :: forall m. PassiveWalletLayer m + -> NewWallet + -> m (Either CreateWalletError Wallet) +createWallet pwl = pwl ^. pwlCreateWallet + +getWallets :: forall m. PassiveWalletLayer m -> m (IxSet Wallet) +getWallets pwl = pwl ^. pwlGetWallets + +getWallet :: forall m. PassiveWalletLayer m + -> WalletId + -> m (Either GetWalletError Wallet) +getWallet pwl = pwl ^. pwlGetWallet + +updateWallet :: forall m. PassiveWalletLayer m + -> WalletId + -> WalletUpdate + -> m (Either UpdateWalletError Wallet) +updateWallet pwl = pwl ^. pwlUpdateWallet + +updateWalletPassword :: forall m. PassiveWalletLayer m + -> WalletId + -> PasswordUpdate + -> m (Either UpdateWalletPasswordError Wallet) +updateWalletPassword pwl = pwl ^. pwlUpdateWalletPassword + +deleteWallet :: forall m. PassiveWalletLayer m + -> WalletId + -> m (Either DeleteWalletError ()) +deleteWallet pwl = pwl ^. pwlDeleteWallet + + +createAccount :: forall m. PassiveWalletLayer m + -> WalletId + -> NewAccount + -> m (Either CreateAccountError Account) +createAccount pwl = pwl ^. pwlCreateAccount + +getAccounts :: forall m. PassiveWalletLayer m + -> WalletId + -> m (Either GetAccountsError (IxSet Account)) +getAccounts pwl = pwl ^. pwlGetAccounts + +getAccount :: forall m. PassiveWalletLayer m + -> WalletId + -> AccountIndex + -> m (Either GetAccountError Account) +getAccount pwl = pwl ^. pwlGetAccount + +updateAccount :: forall m. PassiveWalletLayer m + -> WalletId + -> AccountIndex + -> AccountUpdate + -> m (Either UpdateAccountError Account) +updateAccount pwl = pwl ^. pwlUpdateAccount + +deleteAccount :: forall m. PassiveWalletLayer m + -> WalletId + -> AccountIndex + -> m (Either DeleteAccountError ()) +deleteAccount pwl = pwl ^. pwlDeleteAccount + +createAddress :: forall m. PassiveWalletLayer m + -> NewAddress + -> m (Either CreateAddressError WalletAddress) +createAddress pwl = pwl ^. pwlCreateAddress + +getAddresses :: forall m. PassiveWalletLayer m + -> RequestParams + -> m (SliceOf WalletAddress) +getAddresses pwl = pwl ^. pwlGetAddresses + +validateAddress :: forall m. PassiveWalletLayer m + -> Text + -> m (Either ValidateAddressError WalletAddress) +validateAddress pwl = pwl ^. pwlValidateAddress + +getTransactions :: forall m. PassiveWalletLayer m -> Maybe WalletId -> Maybe AccountIndex + -> Maybe (V1 Address) -> RequestParams -> FilterOperations Transaction -> SortOperations Transaction -> m (Either GetTxError (WalletResponse [Transaction])) +getTransactions pwl = pwl ^. pwlGetTransactions + +applyBlocks :: forall m. PassiveWalletLayer m -> OldestFirst NE Blund -> m () +applyBlocks pwl = pwl ^. pwlApplyBlocks + +rollbackBlocks :: forall m. PassiveWalletLayer m -> NewestFirst NE Blund -> m () +rollbackBlocks pwl = pwl ^. pwlRollbackBlocks + +------------------------------------------------------------ +-- Active wallet layer +------------------------------------------------------------ + +-- An active wallet layer. See @ActiveWallet@. +data ActiveWalletLayer m = ActiveWalletLayer { + -- | The underlying passive wallet layer + walletPassiveLayer :: PassiveWalletLayer m + + -- | Performs a payment. + , pay :: PassPhrase + -- ^ The \"spending password\" to decrypt the 'EncryptedSecretKey'. + -> InputGrouping + -- ^ An preference on how to group inputs during coin selection. + -> ExpenseRegulation + -- ^ Who pays the fee, if the sender or the receivers. + -> Payment + -- ^ The payment we need to perform. + -> m (Either NewPaymentError Tx) + + -- | Estimates the fees for a payment. + , estimateFees :: PassPhrase + -- ^ The \"spending password\" to decrypt the 'EncryptedSecretKey'. + -> InputGrouping + -- ^ An preference on how to group inputs during coin selection + -> ExpenseRegulation + -- ^ Who pays the fee, if the sender or the receivers. + -> Payment + -- ^ The payment we need to perform. + -> m (Either EstimateFeesError Coin) + + -- | Redeem ada + , redeemAda :: Redemption -> m (Either RedeemAdaError Tx) + } + +------------------------------------------------------------ +-- Active wallet errors +------------------------------------------------------------ + +data NewPaymentError = + NewPaymentError Kernel.PaymentError + | NewPaymentTimeLimitReached TimeExecutionLimit + | NewPaymentWalletIdDecodingFailed Text + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show NewPaymentError where + show = formatToString build + +instance Exception NewPaymentError + +instance Buildable NewPaymentError where + build (NewPaymentError kernelErr) = + bprint ("NewPaymentError " % build) kernelErr + build (NewPaymentTimeLimitReached ter) = + bprint ("NewPaymentTimeLimitReached " % build) ter + build (NewPaymentWalletIdDecodingFailed txt) = + bprint ("NewPaymentWalletIdDecodingFailed " % build) txt + + +data EstimateFeesError = + EstimateFeesError Kernel.EstimateFeesError + | EstimateFeesTimeLimitReached TimeExecutionLimit + | EstimateFeesWalletIdDecodingFailed Text + +-- | Unsound show instance needed for the 'Exception' instance. +instance Show EstimateFeesError where + show = formatToString build + +instance Exception EstimateFeesError + +instance Buildable EstimateFeesError where + build (EstimateFeesError kernelErr) = + bprint ("EstimateFeesError " % build) kernelErr + build (EstimateFeesTimeLimitReached ter) = + bprint ("EstimateFeesTimeLimitReached " % build) ter + build (EstimateFeesWalletIdDecodingFailed txt) = + bprint ("EstimateFeesWalletIdDecodingFailed " % build) txt + +instance Arbitrary EstimateFeesError where + arbitrary = oneof [ EstimateFeesError <$> arbitrary + , EstimateFeesTimeLimitReached <$> arbitrary + ] + +-- | TODO: Will need to be extended +data RedeemAdaError = RedeemAdaError + +instance Show RedeemAdaError where + show = formatToString build -bracketLegacyPassiveWallet - :: forall ctx m n a. (MonadMask n, Legacy.MonadLegacyWallet ctx m) - => (PassiveWalletLayer m -> n a) -> n a -bracketLegacyPassiveWallet = Legacy.bracketPassiveWallet +instance Exception RedeemAdaError -bracketLegacyActiveWallet - :: forall m n a. (MonadMask n) - => PassiveWalletLayer m -> WalletDiffusion -> (ActiveWalletLayer m -> n a) -> n a -bracketLegacyActiveWallet = Legacy.bracketActiveWallet +instance Buildable RedeemAdaError where + build RedeemAdaError = "RedeemAdaError" diff --git a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel.hs b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel.hs index ef7e88a4825..720ec3fcb2b 100644 --- a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel.hs +++ b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel.hs @@ -25,13 +25,13 @@ import Cardano.Wallet.Kernel.Keystore (Keystore) import Cardano.Wallet.Kernel.NodeStateAdaptor (NodeStateAdaptor) import Cardano.Wallet.Kernel.Types (RawResolvedBlock (..), fromRawResolvedBlock) +import Cardano.Wallet.WalletLayer (ActiveWalletLayer (..), + PassiveWalletLayer (..)) import qualified Cardano.Wallet.WalletLayer.Kernel.Accounts as Accounts import qualified Cardano.Wallet.WalletLayer.Kernel.Active as Active import qualified Cardano.Wallet.WalletLayer.Kernel.Addresses as Addresses import qualified Cardano.Wallet.WalletLayer.Kernel.Transactions as Transactions import qualified Cardano.Wallet.WalletLayer.Kernel.Wallets as Wallets -import Cardano.Wallet.WalletLayer.Types (ActiveWalletLayer (..), - PassiveWalletLayer (..)) -- | Initialize the passive wallet. -- The passive wallet cannot send new transactions. diff --git a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Accounts.hs b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Accounts.hs index b6b878a0c6a..e4c184222e1 100644 --- a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Accounts.hs +++ b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Accounts.hs @@ -24,10 +24,10 @@ import Cardano.Wallet.Kernel.DB.HdWallet.Read (readAccountsByRootId, import Cardano.Wallet.Kernel.DB.Util.IxSet (IxSet) import qualified Cardano.Wallet.Kernel.DB.Util.IxSet as IxSet import Cardano.Wallet.Kernel.Types (AccountId (..), WalletId (..)) -import Cardano.Wallet.WalletLayer.Kernel.Conv -import Cardano.Wallet.WalletLayer.Types (CreateAccountError (..), +import Cardano.Wallet.WalletLayer (CreateAccountError (..), DeleteAccountError (..), GetAccountError (..), GetAccountsError (..), UpdateAccountError (..)) +import Cardano.Wallet.WalletLayer.Kernel.Conv createAccount :: MonadIO m => Kernel.PassiveWallet diff --git a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Active.hs b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Active.hs index 3fa9df46c85..ab24f0d97ae 100644 --- a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Active.hs +++ b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Active.hs @@ -20,11 +20,11 @@ import Cardano.Wallet.Kernel.CoinSelection.FromGeneric InputGrouping, newOptions) import qualified Cardano.Wallet.Kernel.DB.HdWallet as HD import qualified Cardano.Wallet.Kernel.Transactions as Kernel +import Cardano.Wallet.WalletLayer (EstimateFeesError (..), + NewPaymentError (..), RedeemAdaError (..)) import Cardano.Wallet.WalletLayer.ExecutionTimeLimit (limitExecutionTimeTo) import Cardano.Wallet.WalletLayer.Kernel.Conv -import Cardano.Wallet.WalletLayer.Types (EstimateFeesError (..), - NewPaymentError (..), RedeemAdaError (..)) -- | Generates a new transaction @and submit it as pending@. pay :: MonadIO m diff --git a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Addresses.hs b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Addresses.hs index 7176b62a11c..0183ecdb45f 100644 --- a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Addresses.hs +++ b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Addresses.hs @@ -29,9 +29,9 @@ import Cardano.Wallet.Kernel.DB.Util.IxSet (AutoIncrementKey (..), Indexed (..), IxSet, ixedIndexed, (@>=<=)) import qualified Cardano.Wallet.Kernel.DB.Util.IxSet as IxSet import Cardano.Wallet.Kernel.Types (AccountId (..)) -import Cardano.Wallet.WalletLayer.Kernel.Conv -import Cardano.Wallet.WalletLayer.Types (CreateAddressError (..), +import Cardano.Wallet.WalletLayer (CreateAddressError (..), ValidateAddressError (..)) +import Cardano.Wallet.WalletLayer.Kernel.Conv createAddress :: MonadIO m => Kernel.PassiveWallet diff --git a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Transactions.hs b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Transactions.hs index 5f10a93c2a6..2f1fe18cb47 100644 --- a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Transactions.hs +++ b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Transactions.hs @@ -11,7 +11,7 @@ import qualified Cardano.Wallet.Kernel.DB.HdWallet as HD import Cardano.Wallet.Kernel.DB.InDb (InDb (..)) import Cardano.Wallet.Kernel.DB.TxMeta (TxMeta (..)) import qualified Cardano.Wallet.Kernel.DB.TxMeta as TxMeta -import Cardano.Wallet.WalletLayer.Types (GetTxError (..)) +import Cardano.Wallet.WalletLayer (GetTxError (..)) import Cardano.Wallet.API.Indices import Cardano.Wallet.API.Request diff --git a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Wallets.hs b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Wallets.hs index a44f75bdb49..86b808ebfc3 100644 --- a/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Wallets.hs +++ b/wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Wallets.hs @@ -29,10 +29,10 @@ import qualified Cardano.Wallet.Kernel.DB.Util.IxSet as IxSet import Cardano.Wallet.Kernel.Types (WalletId (..)) import Cardano.Wallet.Kernel.Util.Core (getCurrentTimestamp) import qualified Cardano.Wallet.Kernel.Wallets as Kernel -import Cardano.Wallet.WalletLayer.Kernel.Conv -import Cardano.Wallet.WalletLayer.Types (CreateWalletError (..), +import Cardano.Wallet.WalletLayer (CreateWalletError (..), DeleteWalletError (..), GetWalletError (..), UpdateWalletError (..), UpdateWalletPasswordError (..)) +import Cardano.Wallet.WalletLayer.Kernel.Conv createWallet :: MonadIO m => Kernel.PassiveWallet diff --git a/wallet-new/src/Cardano/Wallet/WalletLayer/Legacy.hs b/wallet-new/src/Cardano/Wallet/WalletLayer/Legacy.hs deleted file mode 100644 index 7fa493aff62..00000000000 --- a/wallet-new/src/Cardano/Wallet/WalletLayer/Legacy.hs +++ /dev/null @@ -1,341 +0,0 @@ -{-# LANGUAGE ConstraintKinds #-} -{-# LANGUAGE ScopedTypeVariables #-} - -module Cardano.Wallet.WalletLayer.Legacy - ( MonadLegacyWallet - , bracketPassiveWallet - , bracketActiveWallet - ) where - -import Universum - -import Control.Monad.Catch (catchAll) -import Control.Monad.IO.Unlift (MonadUnliftIO) -import Data.Coerce (coerce) - -import Cardano.Wallet.WalletLayer.Error (WalletLayerError (..)) -import Cardano.Wallet.WalletLayer.Types (ActiveWalletLayer (..), - CreateAccountError (..), CreateAddressError (..), - CreateWalletError, DeleteAccountError, - DeleteWalletError (..), GetAccountError, GetAccountsError, - GetTxError (..), GetWalletError (..), - PassiveWalletLayer (..), UpdateAccountError, - UpdateWalletError (..), UpdateWalletPasswordError, - ValidateAddressError) - -import Cardano.Wallet.API.Request -import Cardano.Wallet.API.Response -import Cardano.Wallet.API.V1.Migration (eitherMigrate, migrate) -import Cardano.Wallet.API.V1.Migration.Types () -import Cardano.Wallet.API.V1.Types (Account, AccountIndex, - AccountUpdate, Address, BackupPhrase (..), - NewAccount (..), NewAddress, NewWallet (..), - PasswordUpdate, Transaction (..), V1 (..), Wallet, - WalletAddress, WalletId, WalletOperation (..), - WalletUpdate) -import Cardano.Wallet.Kernel.DB.Util.IxSet (IxSet) -import qualified Cardano.Wallet.Kernel.DB.Util.IxSet as IxSet -import Cardano.Wallet.Kernel.Diffusion (WalletDiffusion (..)) - -import Pos.Client.KeyStorage (MonadKeys) -import Pos.Core (ChainDifficulty) -import Pos.Crypto (PassPhrase) - -import Pos.Util (HasLens') -import Pos.Wallet.Web.Account (GenSeed (..)) -import Pos.Wallet.Web.ClientTypes.Types (CBackupPhrase (..), - CWallet (..), CWalletInit (..), CWalletMeta (..)) -import qualified Pos.Wallet.Web.Error.Types as V0 -import Pos.Wallet.Web.Methods.Logic (MonadWalletLogicRead) -import qualified Pos.Wallet.Web.Methods.Logic as V0 -import Pos.Wallet.Web.Methods.Restore (newWallet, - restoreWalletFromSeed) -import Pos.Wallet.Web.State.State (WalletDbReader, askWalletDB, - askWalletSnapshot, setWalletMeta) -import Pos.Wallet.Web.State.Storage (getWalletInfo, getWalletInfos) -import Pos.Wallet.Web.Tracking.Types (SyncQueue) - -import Pos.Chain.Block (Blund) -import Pos.Core.Chrono (NE, NewestFirst (..), OldestFirst (..)) - - --- | Let's unify all the requirements for the legacy wallet. -type MonadLegacyWallet ctx m = - ( WalletDbReader ctx m - , HasLens' ctx SyncQueue - , MonadUnliftIO m - , MonadIO m - , MonadThrow m - , MonadWalletLogicRead ctx m - , MonadKeys m - ) - --- | Initialize the passive wallet. --- The passive wallet cannot send new transactions. -bracketPassiveWallet - :: forall ctx m n a. (MonadMask n, MonadLegacyWallet ctx m) - => (PassiveWalletLayer m -> n a) -> n a -bracketPassiveWallet = - bracket - (pure passiveWalletLayer) - (\_ -> return ()) - where - passiveWalletLayer :: PassiveWalletLayer m - passiveWalletLayer = PassiveWalletLayer - { _pwlCreateWallet = pwlCreateWallet - , _pwlGetWallets = pwlGetWallets - , _pwlGetWallet = pwlGetWallet - , _pwlUpdateWallet = pwlUpdateWallet - , _pwlUpdateWalletPassword = pwlUpdateWalletPassword - , _pwlDeleteWallet = pwlDeleteWallet - - , _pwlCreateAccount = pwlCreateAccount - , _pwlGetAccounts = pwlGetAccounts - , _pwlGetAccount = pwlGetAccount - , _pwlUpdateAccount = pwlUpdateAccount - , _pwlDeleteAccount = pwlDeleteAccount - - , _pwlCreateAddress = pwlCreateAddress - , _pwlGetAddresses = pwlGetAddresses - , _pwlValidateAddress = pwlValidateAddress - - , _pwlGetTransactions = pwlGetTransactions - - , _pwlApplyBlocks = pwlApplyBlocks - , _pwlRollbackBlocks = pwlRollbackBlocks - } - - --- | Initialize the active wallet. --- The active wallet is allowed all. -bracketActiveWallet - :: forall m n a. (MonadMask n) - => PassiveWalletLayer m - -> WalletDiffusion - -> (ActiveWalletLayer m -> n a) -> n a -bracketActiveWallet walletPassiveLayer _walletDiffusion = - bracket - (return activeWalletLayer) - (\_ -> return ()) - where - notUsed = "The activeWalletLayer is not used for the legacy handlers, " <> - "for historical reasons. However, if you wish to use it, simply " <> - "move the concrete implementation of your LegacyHandler(s) into " <> - "this function." - activeWalletLayer :: ActiveWalletLayer m - activeWalletLayer = ActiveWalletLayer { - walletPassiveLayer = walletPassiveLayer - , pay = \_ _ _ -> error notUsed - , estimateFees = \_ _ _ -> error notUsed - , redeemAda = \_ -> error notUsed - } - ------------------------------------------------------------- --- Wallet ------------------------------------------------------------- - -pwlCreateWallet - :: forall ctx m. (MonadLegacyWallet ctx m) - => NewWallet - -> m (Either CreateWalletError Wallet) -pwlCreateWallet NewWallet{..} = do - let spendingPassword = fromMaybe mempty $ coerce newwalSpendingPassword - let backupPhrase = CBackupPhrase $ unBackupPhrase newwalBackupPhrase - - initMeta <- CWalletMeta <$> pure newwalName - <*> migrate newwalAssuranceLevel - <*> pure 0 - - let walletInit = CWalletInit initMeta backupPhrase - - wallet <- newWalletHandler newwalOperation spendingPassword walletInit - `catch` rethrowDuplicateMnemonic - wId <- migrate $ cwId wallet - - -- Get wallet or throw if missing. - res <- pwlGetWallet wId - case res of - Left _ -> throwM (WalletNotFound wId) - Right w -> return $ Right w - where - -- | We have two functions which are very similar. - newWalletHandler :: WalletOperation -> PassPhrase -> CWalletInit -> m CWallet - newWalletHandler CreateWallet = newWallet - newWalletHandler RestoreWallet = restoreWalletFromSeed - -- NOTE: this is temporary solution until we get rid of V0 error handling and/or we lift error handling into types: - -- https://github.com/input-output-hk/cardano-sl/pull/2811#discussion_r183469153 - -- https://github.com/input-output-hk/cardano-sl/pull/2811#discussion_r183472103 - rethrowDuplicateMnemonic (e :: V0.WalletError) = - case e of - V0.RequestError "Wallet with that mnemonics already exists" -> throwM WalletAlreadyExists - _ -> throwM e - - -pwlGetWallets - :: forall ctx m. (MonadLegacyWallet ctx m) - => m (IxSet Wallet) -pwlGetWallets = do - ws <- askWalletSnapshot - let invariantViolated = error "Conversion between CId Wal -> WalletId failed." - let ids = map (either invariantViolated identity . eitherMigrate . fst) - (runReader getWalletInfos ws) - wss <- forM ids pwlGetWallet - case sequence wss of - Left _ -> return IxSet.emptyIxSet - Right xs -> return $ IxSet.fromList xs - -pwlGetWallet - :: forall ctx m. (MonadLegacyWallet ctx m) - => WalletId - -> m (Either GetWalletError Wallet) -pwlGetWallet wId = do - ws <- askWalletSnapshot - - cWId <- migrate wId - wallet <- V0.getWallet cWId - - let mbWallet = do walletInfo <- getWalletInfo cWId ws - migrate (wallet, walletInfo, Nothing @ChainDifficulty) - return $ case mbWallet of - Nothing -> Left (GetWalletErrorNotFound wId) - Just w -> Right w - ---instance Migrate (V0.CWallet, OldStorage.WalletInfo, Maybe Core.ChainDifficulty) V1.Wallet where - -pwlUpdateWallet - :: forall ctx m. (MonadLegacyWallet ctx m) - => WalletId - -> WalletUpdate - -> m (Either UpdateWalletError Wallet) -pwlUpdateWallet wId wUpdate = do - walletDB <- askWalletDB - - cWId <- migrate wId - cWMeta <- migrate wUpdate - - -- Update the data - setWalletMeta walletDB cWId cWMeta - - -- Get wallet or throw if missing. - res <- pwlGetWallet wId - case res of - Left _ -> throwM (UpdateWalletErrorNotFound wId) - Right w -> return (Right w) - -pwlUpdateWalletPassword - :: WalletId - -> PasswordUpdate - -> m (Either UpdateWalletPasswordError Wallet) -pwlUpdateWalletPassword _ _ = error "Unused and deprecated. See [CBR-227]" - --- | Seems silly, but we do need some sort of feedback from --- the DB. -pwlDeleteWallet - :: forall ctx m. (MonadLegacyWallet ctx m) - => WalletId - -> m (Either DeleteWalletError ()) -pwlDeleteWallet wId = do - cWId <- migrate wId - -- Ignore exceptions for the old wallet as we have no way to track - -- precisely what could go wrong there, and this legacy layer is not - -- even actually used. - Right <$> void (V0.deleteWallet cWId) - ------------------------------------------------------------- --- Account ------------------------------------------------------------- - -pwlCreateAccount - :: forall ctx m. (MonadLegacyWallet ctx m) - => WalletId - -> NewAccount - -> m (Either CreateAccountError Account) -pwlCreateAccount wId newAcc@NewAccount{..} = do - - let spendingPassword = fromMaybe mempty . fmap coerce $ naccSpendingPassword - - accInit <- migrate (wId, newAcc) - cAccount <- V0.newAccount RandomSeed spendingPassword accInit - - Right <$> migrate cAccount - -pwlGetAccounts - :: forall ctx m. (MonadLegacyWallet ctx m) - => WalletId - -> m (Either GetAccountsError (IxSet Account)) -pwlGetAccounts wId = do - cWId <- migrate wId - cAccounts <- V0.getAccounts $ Just cWId - Right . IxSet.fromList <$> migrate cAccounts - -pwlGetAccount - :: forall ctx m. (MonadLegacyWallet ctx m) - => WalletId - -> AccountIndex - -> m (Either GetAccountError Account) -pwlGetAccount wId aId = do - accId <- migrate (wId, aId) - account <- V0.getAccount accId - Right <$> migrate account - -pwlUpdateAccount - :: forall ctx m. (MonadLegacyWallet ctx m) - => WalletId - -> AccountIndex - -> AccountUpdate - -> m (Either UpdateAccountError Account) -pwlUpdateAccount wId accIdx accUpdate = do - newAccId <- migrate (wId, accIdx) - accMeta <- migrate accUpdate - cAccount <- V0.updateAccount newAccId accMeta - Right <$> migrate cAccount - -pwlDeleteAccount - :: forall ctx m. (MonadLegacyWallet ctx m) - => WalletId - -> AccountIndex - -> m (Either DeleteAccountError ()) -pwlDeleteAccount wId accIdx = do - accId <- migrate (wId, accIdx) - _ <- catchAll (const True <$> V0.deleteAccount accId) (const . pure $ False) - return $ Right () - ------------------------------------------------------------- --- Address ------------------------------------------------------------- - -pwlCreateAddress :: NewAddress -> m (Either CreateAddressError WalletAddress) -pwlCreateAddress = error "Not implemented!" - -pwlGetAddresses :: RequestParams -> m (SliceOf WalletAddress) -pwlGetAddresses = error "Not implemented!" - -pwlValidateAddress :: Text -> m (Either ValidateAddressError WalletAddress) -pwlValidateAddress = error "Not implemented!" - ------------------------------------------------------------- --- Transaction ------------------------------------------------------------- - -pwlGetTransactions :: Maybe WalletId - -> Maybe AccountIndex - -> Maybe (V1 Address) - -> RequestParams - -> FilterOperations Transaction - -> SortOperations Transaction - -> m (Either GetTxError (WalletResponse [Transaction])) -pwlGetTransactions = error "Not implemented!" - ------------------------------------------------------------- --- Apply Block ------------------------------------------------------------- - -pwlApplyBlocks :: OldestFirst NE Blund -> m () -pwlApplyBlocks = error "Not implemented!" - ------------------------------------------------------------- --- Rollback Block ------------------------------------------------------------- - -pwlRollbackBlocks :: NewestFirst NE Blund -> m () -pwlRollbackBlocks = error "Not implemented!" diff --git a/wallet-new/src/Cardano/Wallet/WalletLayer/Types.hs b/wallet-new/src/Cardano/Wallet/WalletLayer/Types.hs deleted file mode 100644 index 50a0610b420..00000000000 --- a/wallet-new/src/Cardano/Wallet/WalletLayer/Types.hs +++ /dev/null @@ -1,587 +0,0 @@ -module Cardano.Wallet.WalletLayer.Types - ( PassiveWalletLayer (..) - , ActiveWalletLayer (..) - -- * Getters - , createWallet - , getWallets - , getWallet - , updateWallet - , updateWalletPassword - , deleteWallet - - , createAccount - , getAccounts - , getAccount - , updateAccount - , deleteAccount - - , createAddress - , getAddresses - , validateAddress - - , getTransactions - - , applyBlocks - , rollbackBlocks - -- * Errors - , CreateWalletError(..) - , GetWalletError(..) - , UpdateWalletError(..) - , UpdateWalletPasswordError(..) - , DeleteWalletError(..) - , NewPaymentError(..) - , EstimateFeesError(..) - , RedeemAdaError(..) - , CreateAddressError(..) - , ValidateAddressError(..) - , CreateAccountError(..) - , GetAccountError(..) - , GetAccountsError(..) - , GetTxError(..) - , DeleteAccountError(..) - , UpdateAccountError(..) - ) where - -import Universum - -import Control.Lens (makeLenses) -import Formatting (bprint, build, formatToString, (%)) -import qualified Formatting.Buildable -import qualified Prelude -import Test.QuickCheck (Arbitrary (..), oneof) - -import Pos.Chain.Block (Blund) -import Pos.Core (Coin) -import Pos.Core.Chrono (NE, NewestFirst (..), OldestFirst (..)) -import Pos.Core.Txp (Tx) -import Pos.Crypto (PassPhrase) - -import Cardano.Wallet.API.Request (RequestParams (..)) -import Cardano.Wallet.API.Request.Filter (FilterOperations (..)) -import Cardano.Wallet.API.Request.Sort (SortOperations (..)) -import Cardano.Wallet.API.Response (SliceOf (..), WalletResponse) -import Cardano.Wallet.API.V1.Types (Account, AccountIndex, - AccountUpdate, Address, NewAccount, NewAddress, NewWallet, - PasswordUpdate, Payment, Redemption, Transaction, V1 (..), - Wallet, WalletAddress, WalletId, WalletUpdate) -import qualified Cardano.Wallet.Kernel.Accounts as Kernel -import qualified Cardano.Wallet.Kernel.Addresses as Kernel -import Cardano.Wallet.Kernel.CoinSelection.FromGeneric - (ExpenseRegulation, InputGrouping) -import qualified Cardano.Wallet.Kernel.DB.HdWallet as Kernel -import Cardano.Wallet.Kernel.DB.Util.IxSet (IxSet) -import qualified Cardano.Wallet.Kernel.Transactions as Kernel -import qualified Cardano.Wallet.Kernel.Wallets as Kernel -import Cardano.Wallet.WalletLayer.ExecutionTimeLimit - (TimeExecutionLimit) - ------------------------------------------------------------- --- Errors when manipulating wallets ------------------------------------------------------------- - -data CreateWalletError = - CreateWalletError Kernel.CreateWalletError - | CreateWalletFirstAccountCreationFailed Kernel.CreateAccountError - --- | Unsound show instance needed for the 'Exception' instance. -instance Show CreateWalletError where - show = formatToString build - -instance Exception CreateWalletError - -instance Arbitrary CreateWalletError where - arbitrary = oneof [ CreateWalletError <$> arbitrary - , CreateWalletFirstAccountCreationFailed <$> arbitrary - ] - -instance Buildable CreateWalletError where - build (CreateWalletError kernelError) = - bprint ("CreateWalletError " % build) kernelError - build (CreateWalletFirstAccountCreationFailed kernelError) = - bprint ("CreateWalletFirstAccountCreationFailed " % build) kernelError - -data GetWalletError = - GetWalletError (V1 Kernel.UnknownHdRoot) - | GetWalletErrorNotFound WalletId - -- ^ Error thrown by the legacy wallet layer, isomorphic to the one above, - -- which is new-data-layer specific. - | GetWalletWalletIdDecodingFailed Text - deriving Eq - --- | Unsound show instance needed for the 'Exception' instance. -instance Show GetWalletError where - show = formatToString build - -instance Exception GetWalletError - -instance Buildable GetWalletError where - build (GetWalletError (V1 kernelError)) = - bprint ("GetWalletError " % build) kernelError - build (GetWalletErrorNotFound walletId) = - bprint ("GetWalletErrorNotFound " % build) walletId - build (GetWalletWalletIdDecodingFailed txt) = - bprint ("GetWalletWalletIdDecodingFailed " % build) txt - -data UpdateWalletError = - UpdateWalletError (V1 Kernel.UnknownHdRoot) - | UpdateWalletErrorNotFound WalletId - -- ^ Error thrown by the legacy wallet layer, isomorphic to the one above, - -- which is new-data-layer specific. - | UpdateWalletWalletIdDecodingFailed Text - deriving Eq - --- | Unsound show instance needed for the 'Exception' instance. -instance Show UpdateWalletError where - show = formatToString build - -instance Exception UpdateWalletError - -instance Buildable UpdateWalletError where - build (UpdateWalletError (V1 kernelError)) = - bprint ("UpdateWalletError " % build) kernelError - build (UpdateWalletErrorNotFound walletId) = - bprint ("UpdateWalletErrorNotFound " % build) walletId - build (UpdateWalletWalletIdDecodingFailed txt) = - bprint ("UpdateWalletWalletIdDecodingFailed " % build) txt - -data UpdateWalletPasswordError = - UpdateWalletPasswordWalletIdDecodingFailed Text - | UpdateWalletPasswordError Kernel.UpdateWalletPasswordError - --- | Unsound show instance needed for the 'Exception' instance. -instance Show UpdateWalletPasswordError where - show = formatToString build - -instance Exception UpdateWalletPasswordError - -instance Buildable UpdateWalletPasswordError where - build (UpdateWalletPasswordWalletIdDecodingFailed txt) = - bprint ("UpdateWalletPasswordWalletIdDecodingFailed " % build) txt - build (UpdateWalletPasswordError kernelError) = - bprint ("UpdateWalletPasswordError " % build) kernelError - -data DeleteWalletError = - DeleteWalletWalletIdDecodingFailed Text - | DeleteWalletError (V1 Kernel.UnknownHdRoot) - --- | Unsound show instance needed for the 'Exception' instance. -instance Show DeleteWalletError where - show = formatToString build - -instance Exception DeleteWalletError - -instance Buildable DeleteWalletError where - build (DeleteWalletWalletIdDecodingFailed txt) = - bprint ("DeleteWalletWalletIdDecodingFailed " % build) txt - build (DeleteWalletError kernelError) = - bprint ("DeleteWalletError " % build) kernelError - ------------------------------------------------------------- --- Errors when dealing with addresses ------------------------------------------------------------- - -data CreateAddressError = - CreateAddressError Kernel.CreateAddressError - | CreateAddressAddressDecodingFailed Text - -- ^ Decoding the input 'Text' as an 'Address' failed. - deriving Eq - --- | Unsound show instance needed for the 'Exception' instance. -instance Show CreateAddressError where - show = formatToString build - -instance Exception CreateAddressError - -instance Arbitrary CreateAddressError where - arbitrary = oneof [ CreateAddressError <$> arbitrary - , pure (CreateAddressAddressDecodingFailed "Ae2tdPwUPEZ18ZjTLnLVr9CEvUEUX4eW1LBHbxxx") - ] - -instance Buildable CreateAddressError where - build (CreateAddressError kernelError) = - bprint ("CreateAddressError " % build) kernelError - build (CreateAddressAddressDecodingFailed txt) = - bprint ("CreateAddressAddressDecodingFailed " % build) txt - -data ValidateAddressError = - ValidateAddressDecodingFailed Text - -- ^ When trying to decode this raw 'Text' into a proper Cardano - -- 'Address' the decoding failed. Unfortunately we are not able to - -- provide a more accurate error description as 'decodeTextAddress' doesn't - -- offer such. - | ValidateAddressNotOurs Address - -- ^ The input address is a valid 'Cardano' address, but it doesn't - -- belong to us. - deriving Eq - --- | Unsound show instance needed for the 'Exception' instance. -instance Show ValidateAddressError where - show = formatToString build - -instance Exception ValidateAddressError - -instance Buildable ValidateAddressError where - build (ValidateAddressDecodingFailed rawText) = - bprint ("ValidateAddressDecodingFailed " % build) rawText - build (ValidateAddressNotOurs address) = - bprint ("ValidateAddressNotOurs " % build) address - ------------------------------------------------------------- --- Errors when dealing with Accounts ------------------------------------------------------------- - -data CreateAccountError = - CreateAccountError Kernel.CreateAccountError - | CreateAccountWalletIdDecodingFailed Text - -- ^ Decoding the parent's 'WalletId' from a raw 'Text' failed. - | CreateAccountFirstAddressGenerationFailed Kernel.CreateAddressError - -- ^ When trying to create the first 'Address' to go in tandem with this - -- 'Account', the generation failed. - deriving Eq - --- | Unsound show instance needed for the 'Exception' instance. -instance Show CreateAccountError where - show = formatToString build - -instance Exception CreateAccountError - -instance Buildable CreateAccountError where - build (CreateAccountError kernelError) = - bprint ("CreateAccountError " % build) kernelError - build (CreateAccountWalletIdDecodingFailed txt) = - bprint ("CreateAccountWalletIdDecodingFailed " % build) txt - build (CreateAccountFirstAddressGenerationFailed kernelError) = - bprint ("CreateAccountFirstAddressGenerationFailed " % build) kernelError - -data GetAccountError = - GetAccountError (V1 Kernel.UnknownHdAccount) - | GetAccountWalletIdDecodingFailed Text - deriving Eq - --- | Unsound show instance needed for the 'Exception' instance. -instance Show GetAccountError where - show = formatToString build - -instance Exception GetAccountError - -instance Buildable GetAccountError where - build (GetAccountError kernelError) = - bprint ("GetAccountError " % build) kernelError - build (GetAccountWalletIdDecodingFailed txt) = - bprint ("GetAccountWalletIdDecodingFailed " % build) txt - -data DeleteAccountError = - DeleteAccountError (V1 Kernel.UnknownHdAccount) - | DeleteAccountWalletIdDecodingFailed Text - deriving Eq - --- | Unsound show instance needed for the 'Exception' instance. -instance Show DeleteAccountError where - show = formatToString build - -instance Exception DeleteAccountError - -instance Buildable DeleteAccountError where - build (DeleteAccountError kernelError) = - bprint ("DeleteAccountError " % build) kernelError - build (DeleteAccountWalletIdDecodingFailed txt) = - bprint ("DeleteAccountWalletIdDecodingFailed " % build) txt - -data GetAccountsError = - GetAccountsError Kernel.UnknownHdRoot - | GetAccountsWalletIdDecodingFailed Text - deriving Eq - --- | Unsound show instance needed for the 'Exception' instance. -instance Show GetAccountsError where - show = formatToString build - -instance Exception GetAccountsError - -instance Buildable GetAccountsError where - build (GetAccountsError kernelError) = - bprint ("GetAccountsError " % build) kernelError - build (GetAccountsWalletIdDecodingFailed txt) = - bprint ("GetAccountsWalletIdDecodingFailed " % build) txt - -data UpdateAccountError = - UpdateAccountError (V1 Kernel.UnknownHdAccount) - | UpdateAccountWalletIdDecodingFailed Text - deriving Eq - --- | Unsound show instance needed for the 'Exception' instance. -instance Show UpdateAccountError where - show = formatToString build - -instance Exception UpdateAccountError - -instance Buildable UpdateAccountError where - build (UpdateAccountError kernelError) = - bprint ("UpdateAccountError " % build) kernelError - build (UpdateAccountWalletIdDecodingFailed txt) = - bprint ("UpdateAccountWalletIdDecodingFailed " % build) txt - ------------------------------------------------------------- --- Errors when getting Transactions ------------------------------------------------------------- - -data GetTxError = - GetTxMissingWalletIdError - | GetTxAddressDecodingFailed Text - | GetTxInvalidSortingOperaration String - -instance Show GetTxError where - show = formatToString build - -instance Buildable GetTxError where - build GetTxMissingWalletIdError = - bprint "GetTxMissingWalletIdError " - build (GetTxAddressDecodingFailed txt) = - bprint ("GetTxAddressDecodingFailed " % build) txt - build (GetTxInvalidSortingOperaration txt) = - bprint ("GetTxInvalidSortingOperaration " % build) txt - - -instance Arbitrary GetTxError where - arbitrary = oneof [ pure GetTxMissingWalletIdError - , pure (GetTxAddressDecodingFailed "by_amount") - , pure (GetTxInvalidSortingOperaration "123") - ] - -instance Exception GetTxError - ------------------------------------------------------------- --- Passive wallet layer ------------------------------------------------------------- - --- | The passive wallet (data) layer. See @PassiveWallet@. -data PassiveWalletLayer m = PassiveWalletLayer - { - -- * wallets - _pwlCreateWallet :: NewWallet -> m (Either CreateWalletError Wallet) - , _pwlGetWallets :: m (IxSet Wallet) - , _pwlGetWallet :: WalletId -> m (Either GetWalletError Wallet) - , _pwlUpdateWallet :: WalletId - -> WalletUpdate - -> m (Either UpdateWalletError Wallet) - , _pwlUpdateWalletPassword :: WalletId - -> PasswordUpdate - -> m (Either UpdateWalletPasswordError Wallet) - , _pwlDeleteWallet :: WalletId -> m (Either DeleteWalletError ()) - -- * accounts - , _pwlCreateAccount :: WalletId - -> NewAccount - -> m (Either CreateAccountError Account) - , _pwlGetAccounts :: WalletId - -> m (Either GetAccountsError (IxSet Account)) - , _pwlGetAccount :: WalletId - -> AccountIndex - -> m (Either GetAccountError Account) - , _pwlUpdateAccount :: WalletId - -> AccountIndex - -> AccountUpdate - -> m (Either UpdateAccountError Account) - , _pwlDeleteAccount :: WalletId - -> AccountIndex - -> m (Either DeleteAccountError ()) - -- * addresses - , _pwlCreateAddress :: NewAddress - -> m (Either CreateAddressError WalletAddress) - , _pwlGetAddresses :: RequestParams -> m (SliceOf WalletAddress) - , _pwlValidateAddress :: Text - -> m (Either ValidateAddressError WalletAddress) - - -- * transactions - , _pwlGetTransactions :: Maybe WalletId -> Maybe AccountIndex -> Maybe (V1 Address) - -> RequestParams -> FilterOperations Transaction -> SortOperations Transaction -> m (Either GetTxError (WalletResponse [Transaction])) - - -- * core API - , _pwlApplyBlocks :: OldestFirst NE Blund -> m () - , _pwlRollbackBlocks :: NewestFirst NE Blund -> m () - } - -makeLenses ''PassiveWalletLayer - ------------------------------------------------------------- --- Passive wallet layer getters ------------------------------------------------------------- - -createWallet :: forall m. PassiveWalletLayer m - -> NewWallet - -> m (Either CreateWalletError Wallet) -createWallet pwl = pwl ^. pwlCreateWallet - -getWallets :: forall m. PassiveWalletLayer m -> m (IxSet Wallet) -getWallets pwl = pwl ^. pwlGetWallets - -getWallet :: forall m. PassiveWalletLayer m - -> WalletId - -> m (Either GetWalletError Wallet) -getWallet pwl = pwl ^. pwlGetWallet - -updateWallet :: forall m. PassiveWalletLayer m - -> WalletId - -> WalletUpdate - -> m (Either UpdateWalletError Wallet) -updateWallet pwl = pwl ^. pwlUpdateWallet - -updateWalletPassword :: forall m. PassiveWalletLayer m - -> WalletId - -> PasswordUpdate - -> m (Either UpdateWalletPasswordError Wallet) -updateWalletPassword pwl = pwl ^. pwlUpdateWalletPassword - -deleteWallet :: forall m. PassiveWalletLayer m - -> WalletId - -> m (Either DeleteWalletError ()) -deleteWallet pwl = pwl ^. pwlDeleteWallet - - -createAccount :: forall m. PassiveWalletLayer m - -> WalletId - -> NewAccount - -> m (Either CreateAccountError Account) -createAccount pwl = pwl ^. pwlCreateAccount - -getAccounts :: forall m. PassiveWalletLayer m - -> WalletId - -> m (Either GetAccountsError (IxSet Account)) -getAccounts pwl = pwl ^. pwlGetAccounts - -getAccount :: forall m. PassiveWalletLayer m - -> WalletId - -> AccountIndex - -> m (Either GetAccountError Account) -getAccount pwl = pwl ^. pwlGetAccount - -updateAccount :: forall m. PassiveWalletLayer m - -> WalletId - -> AccountIndex - -> AccountUpdate - -> m (Either UpdateAccountError Account) -updateAccount pwl = pwl ^. pwlUpdateAccount - -deleteAccount :: forall m. PassiveWalletLayer m - -> WalletId - -> AccountIndex - -> m (Either DeleteAccountError ()) -deleteAccount pwl = pwl ^. pwlDeleteAccount - -createAddress :: forall m. PassiveWalletLayer m - -> NewAddress - -> m (Either CreateAddressError WalletAddress) -createAddress pwl = pwl ^. pwlCreateAddress - -getAddresses :: forall m. PassiveWalletLayer m - -> RequestParams - -> m (SliceOf WalletAddress) -getAddresses pwl = pwl ^. pwlGetAddresses - -validateAddress :: forall m. PassiveWalletLayer m - -> Text - -> m (Either ValidateAddressError WalletAddress) -validateAddress pwl = pwl ^. pwlValidateAddress - -getTransactions :: forall m. PassiveWalletLayer m -> Maybe WalletId -> Maybe AccountIndex - -> Maybe (V1 Address) -> RequestParams -> FilterOperations Transaction -> SortOperations Transaction -> m (Either GetTxError (WalletResponse [Transaction])) -getTransactions pwl = pwl ^. pwlGetTransactions - -applyBlocks :: forall m. PassiveWalletLayer m -> OldestFirst NE Blund -> m () -applyBlocks pwl = pwl ^. pwlApplyBlocks - -rollbackBlocks :: forall m. PassiveWalletLayer m -> NewestFirst NE Blund -> m () -rollbackBlocks pwl = pwl ^. pwlRollbackBlocks - ------------------------------------------------------------- --- Active wallet layer ------------------------------------------------------------- - --- An active wallet layer. See @ActiveWallet@. -data ActiveWalletLayer m = ActiveWalletLayer { - -- | The underlying passive wallet layer - walletPassiveLayer :: PassiveWalletLayer m - - -- | Performs a payment. - , pay :: PassPhrase - -- ^ The \"spending password\" to decrypt the 'EncryptedSecretKey'. - -> InputGrouping - -- ^ An preference on how to group inputs during coin selection. - -> ExpenseRegulation - -- ^ Who pays the fee, if the sender or the receivers. - -> Payment - -- ^ The payment we need to perform. - -> m (Either NewPaymentError Tx) - - -- | Estimates the fees for a payment. - , estimateFees :: PassPhrase - -- ^ The \"spending password\" to decrypt the 'EncryptedSecretKey'. - -> InputGrouping - -- ^ An preference on how to group inputs during coin selection - -> ExpenseRegulation - -- ^ Who pays the fee, if the sender or the receivers. - -> Payment - -- ^ The payment we need to perform. - -> m (Either EstimateFeesError Coin) - - -- | Redeem ada - , redeemAda :: Redemption -> m (Either RedeemAdaError Tx) - } - ------------------------------------------------------------- --- Active wallet errors ------------------------------------------------------------- - -data NewPaymentError = - NewPaymentError Kernel.PaymentError - | NewPaymentTimeLimitReached TimeExecutionLimit - | NewPaymentWalletIdDecodingFailed Text - --- | Unsound show instance needed for the 'Exception' instance. -instance Show NewPaymentError where - show = formatToString build - -instance Exception NewPaymentError - -instance Buildable NewPaymentError where - build (NewPaymentError kernelErr) = - bprint ("NewPaymentError " % build) kernelErr - build (NewPaymentTimeLimitReached ter) = - bprint ("NewPaymentTimeLimitReached " % build) ter - build (NewPaymentWalletIdDecodingFailed txt) = - bprint ("NewPaymentWalletIdDecodingFailed " % build) txt - - -data EstimateFeesError = - EstimateFeesError Kernel.EstimateFeesError - | EstimateFeesTimeLimitReached TimeExecutionLimit - | EstimateFeesWalletIdDecodingFailed Text - --- | Unsound show instance needed for the 'Exception' instance. -instance Show EstimateFeesError where - show = formatToString build - -instance Exception EstimateFeesError - -instance Buildable EstimateFeesError where - build (EstimateFeesError kernelErr) = - bprint ("EstimateFeesError " % build) kernelErr - build (EstimateFeesTimeLimitReached ter) = - bprint ("EstimateFeesTimeLimitReached " % build) ter - build (EstimateFeesWalletIdDecodingFailed txt) = - bprint ("EstimateFeesWalletIdDecodingFailed " % build) txt - -instance Arbitrary EstimateFeesError where - arbitrary = oneof [ EstimateFeesError <$> arbitrary - , EstimateFeesTimeLimitReached <$> arbitrary - ] - --- | TODO: Will need to be extended -data RedeemAdaError = RedeemAdaError - -instance Show RedeemAdaError where - show = formatToString build - -instance Exception RedeemAdaError - -instance Buildable RedeemAdaError where - build RedeemAdaError = "RedeemAdaError" diff --git a/wallet-new/test/Cardano/Wallet/WalletLayer/QuickCheck.hs b/wallet-new/test/Cardano/Wallet/WalletLayer/QuickCheck.hs index 77debe99e86..78b86437fbb 100644 --- a/wallet-new/test/Cardano/Wallet/WalletLayer/QuickCheck.hs +++ b/wallet-new/test/Cardano/Wallet/WalletLayer/QuickCheck.hs @@ -10,7 +10,7 @@ import Universum import Cardano.Wallet.Kernel.Diffusion (WalletDiffusion (..)) import Cardano.Wallet.Orphans.Arbitrary () -import Cardano.Wallet.WalletLayer.Types (ActiveWalletLayer (..), +import Cardano.Wallet.WalletLayer (ActiveWalletLayer (..), CreateAccountError (..), DeleteAccountError (..), DeleteWalletError (..), GetAccountError (..), GetAccountsError (..), GetWalletError (..), diff --git a/wallet-new/test/unit/Test/Spec/Accounts.hs b/wallet-new/test/unit/Test/Spec/Accounts.hs index d44a3205810..c9d45a6e385 100644 --- a/wallet-new/test/unit/Test/Spec/Accounts.hs +++ b/wallet-new/test/unit/Test/Spec/Accounts.hs @@ -16,8 +16,8 @@ import Cardano.Wallet.Kernel.Accounts (CreateAccountError (..)) import qualified Cardano.Wallet.Kernel.DB.HdWallet as Kernel import qualified Cardano.Wallet.Kernel.Internal as Internal import qualified Cardano.Wallet.Kernel.Keystore as Keystore +import Cardano.Wallet.WalletLayer (PassiveWalletLayer) import qualified Cardano.Wallet.WalletLayer as WalletLayer -import Cardano.Wallet.WalletLayer.Types (PassiveWalletLayer) import qualified Cardano.Wallet.API.Request as API import qualified Cardano.Wallet.API.Request.Pagination as API diff --git a/wallet-new/test/unit/Test/Spec/Fixture.hs b/wallet-new/test/unit/Test/Spec/Fixture.hs index 691b1c04d7b..ca8446cd47c 100644 --- a/wallet-new/test/unit/Test/Spec/Fixture.hs +++ b/wallet-new/test/unit/Test/Spec/Fixture.hs @@ -27,7 +27,7 @@ import qualified Cardano.Wallet.Kernel.Keystore as Keystore import Cardano.Wallet.Kernel.NodeStateAdaptor (nodeStateUnavailable) import Cardano.Wallet.WalletLayer (ActiveWalletLayer, PassiveWalletLayer) -import qualified Cardano.Wallet.WalletLayer as WalletLayer +import qualified Cardano.Wallet.WalletLayer.Kernel as WalletLayer.Kernel -- | Do not pollute the test runner output with logs. devNull :: Severity -> Text -> IO () @@ -42,7 +42,7 @@ withLayer :: MonadIO m -> PropertyM IO a withLayer cc = do liftIO $ Keystore.bracketTestKeystore $ \keystore -> do - WalletLayer.bracketKernelPassiveWallet devNull keystore nodeStateUnavailable $ \layer wallet -> do + WalletLayer.Kernel.bracketPassiveWallet devNull keystore nodeStateUnavailable $ \layer wallet -> do cc layer wallet type GenPassiveWalletFixture x = PropertyM IO (PassiveWallet -> IO x) @@ -55,7 +55,7 @@ withPassiveWalletFixture :: MonadIO m withPassiveWalletFixture prepareFixtures cc = do generateFixtures <- prepareFixtures liftIO $ Keystore.bracketTestKeystore $ \keystore -> do - WalletLayer.bracketKernelPassiveWallet devNull keystore nodeStateUnavailable $ \layer wallet -> do + WalletLayer.Kernel.bracketPassiveWallet devNull keystore nodeStateUnavailable $ \layer wallet -> do fixtures <- generateFixtures wallet cc keystore layer wallet fixtures @@ -66,9 +66,9 @@ withActiveWalletFixture :: MonadIO m withActiveWalletFixture prepareFixtures cc = do generateFixtures <- prepareFixtures liftIO $ Keystore.bracketTestKeystore $ \keystore -> do - WalletLayer.bracketKernelPassiveWallet devNull keystore nodeStateUnavailable $ \passiveLayer passiveWallet -> do + WalletLayer.Kernel.bracketPassiveWallet devNull keystore nodeStateUnavailable $ \passiveLayer passiveWallet -> do withDefConfiguration $ \pm -> do - WalletLayer.bracketKernelActiveWallet pm passiveLayer passiveWallet diffusion $ \activeLayer activeWallet -> do + WalletLayer.Kernel.bracketActiveWallet pm passiveLayer passiveWallet diffusion $ \activeLayer activeWallet -> do fixtures <- generateFixtures keystore activeWallet cc keystore activeLayer activeWallet fixtures where diff --git a/wallet-new/test/unit/Test/Spec/GetTransactions.hs b/wallet-new/test/unit/Test/Spec/GetTransactions.hs index ce5ec41d0db..4ae34bf0884 100644 --- a/wallet-new/test/unit/Test/Spec/GetTransactions.hs +++ b/wallet-new/test/unit/Test/Spec/GetTransactions.hs @@ -30,8 +30,8 @@ import qualified Cardano.Wallet.Kernel.Keystore as Keystore -- import qualified Cardano.Wallet.Kernel.Transactions as Kernel import Cardano.Wallet.Kernel.Types (AccountId (..), WalletId (..)) -- import Cardano.Wallet.WalletLayer (PassiveWalletLayer) +import Cardano.Wallet.WalletLayer (walletPassiveLayer) import qualified Cardano.Wallet.WalletLayer as WalletLayer -import Cardano.Wallet.WalletLayer.Types import Cardano.Wallet.API.Response import qualified Cardano.Wallet.API.V1.Types as V1 @@ -175,5 +175,3 @@ spec = case eiResp of Left l -> expectationFailure $ "returned " <> show l Right resp -> check resp - -