-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[23] add interface/structure for wallet creation
[23] Add getWallet and types in line with api spec [23] replace module define passphrase types with address derivation ones [23] Refining types and cutting superfluous code [23] Final fixes
- Loading branch information
1 parent
8ad13a9
commit c19da65
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |