Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add very preliminary interface/structure for wallet getter and creation #62

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ library
Cardano.Wallet.Binary
Cardano.Wallet.Binary.Packfile
Cardano.Wallet.BlockSyncer
Cardano.WalletLayer
Cardano.Wallet.Mnemonic
Cardano.Wallet.Primitive
Servant.Extra.ContentTypes
Expand Down
95 changes: 95 additions & 0 deletions src/Cardano/WalletLayer.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}

-- |
-- Copyright: © 2018-2019 IOHK
-- License: MIT
--
-- | Module provides wallet layer api that is used by API layer
-- | and uses both DB and Networking layer to realize its role
-- | as being intermediary between the three.


module Cardano.WalletLayer where

import Prelude

import Cardano.Wallet
( Wallet )
import Cardano.Wallet.AddressDerivation
( Depth (..), Key, Passphrase, XPub )
import Cardano.Wallet.AddressDiscovery
( AddressPoolGap )
import Cardano.Wallet.Mnemonic
( Mnemonic )
import Control.Monad.Except
( ExceptT )
import Data.Text
( Text )
import Data.Time.Units
( Microsecond )
import GHC.Generics
( Generic )



-- | Errors
data CreateWalletError

data GetWalletError

-- | Types
data WalletLayer m s = WalletLayer
{ createWallet :: CreateWallet -> ExceptT CreateWalletError m (Wallet s)
, getWallet :: WalletId -> ExceptT GetWalletError m (Wallet s)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have separate error types for the different functions. I am not expecting getWallet to throw anything related to the creation of a wallet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


data CreateWallet =
CreateWallet NewWallet
| ImportWallet (Key 'AccountK XPub)

data NewWallet = NewWallet
{
mnemonicSentence
:: !(Mnemonic 15)
, mnemonicSentencePassphrase
:: !(Maybe (Mnemonic 9))
, name
:: !WalletName
, passphrase
:: !(Passphrase "encryption")
, addressPoolGap
:: !AddressPoolGap
} deriving (Show, Generic)

newtype WalletName = WalletName Text
deriving (Eq, Show)

newtype WalletId = WalletId Text
deriving (Eq, Show)

newtype WalletTimestamp = WalletTimestamp Microsecond
deriving (Eq, Ord, Show)

data WalletMode = Ready | Restoring deriving (Eq, Show)

data Delegation = Delegated | NotDelegated deriving (Eq, Show)

newtype PassphraseInfo = PassphraseInfo { lastUpdated :: WalletTimestamp }
deriving (Eq, Show)

data WalletMetadata = WalletMetadata {
id
:: !WalletId
, name
:: !WalletName
, addressPoolGap
:: !AddressPoolGap
, passphraseInfo
:: !PassphraseInfo
, state
:: !WalletMode
, delegation
:: !Delegation
} deriving (Eq, Show, Generic)