Skip to content

Commit

Permalink
Merge pull request #62 from input-output-hk/paweljakubas/23/sketch-wa…
Browse files Browse the repository at this point in the history
…llet-layer

Add very preliminary interface/structure for wallet getter and creation
  • Loading branch information
KtorZ committed Mar 14, 2019
2 parents 8ad13a9 + c19da65 commit 847da46
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
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)
}

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)

0 comments on commit 847da46

Please sign in to comment.