Skip to content

Commit

Permalink
move class-constraints further down into the wallet layer interface
Browse files Browse the repository at this point in the history
This gives a better overview of which function requires which power
and would make a future split of the wallet layer features easier.
  • Loading branch information
KtorZ committed Jun 10, 2019
1 parent c115e0e commit 51fc07f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
34 changes: 17 additions & 17 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ import qualified Data.Text.IO as TIO

data WalletLayer s t = WalletLayer
{ createWallet
:: WalletId
:: (Show s, NFData s, IsOurs s, TxId t)
=> WalletId
-> WalletName
-> s
-> ExceptT ErrWalletAlreadyExists IO WalletId
Expand Down Expand Up @@ -218,7 +219,8 @@ data WalletLayer s t = WalletLayer
-- apply remaining blocks until failure or, the target slot is reached.

, listAddresses
:: WalletId
:: (IsOurs s, CompareDiscovery s, KnownAddresses s)
=> WalletId
-> ExceptT ErrNoSuchWallet IO [(Address, AddressState)]
-- ^ List all addresses of a wallet with their metadata. Addresses
-- are ordered from the most recently discovered to the oldest known.
Expand All @@ -234,7 +236,8 @@ data WalletLayer s t = WalletLayer
-- sign) an actual transaction, have a look at 'signTx'.

, signTx
:: WalletId
:: (Show s, NFData s, IsOwned s, GenChange s)
=> WalletId
-> Passphrase "encryption"
-> CoinSelection
-> ExceptT ErrSignTx IO (Tx, TxMeta, [TxWitness])
Expand All @@ -245,7 +248,8 @@ data WalletLayer s t = WalletLayer
-- 'submitTx'.

, submitTx
:: WalletId
:: (TxId t)
=> WalletId
-> (Tx, TxMeta, [TxWitness])
-> ExceptT ErrSubmitTx IO ()
-- ^ Broadcast a (signed) transaction to the network.
Expand Down Expand Up @@ -327,15 +331,7 @@ cancelWorker (WorkerRegistry mvar) wid =

-- | Create a new instance of the wallet layer.
newWalletLayer
:: forall s t.
( IsOwned s
, GenChange s
, KnownAddresses s
, CompareDiscovery s
, NFData s
, Show s
, TxId t
)
:: forall s t. ()
=> DBLayer IO s t
-> NetworkLayer t IO
-> TransactionLayer t
Expand All @@ -362,7 +358,8 @@ newWalletLayer db nw tl = do
---------------------------------------------------------------------------}

_createWallet
:: WalletId
:: (Show s, NFData s, IsOurs s, TxId t)
=> WalletId
-> WalletName
-> s
-> ExceptT ErrWalletAlreadyExists IO WalletId
Expand Down Expand Up @@ -532,7 +529,8 @@ newWalletLayer db nw tl = do
-- This implementation is rather inneficient and not intented for frequent
-- use, in particular for exchanges or "big-players".
_listAddresses
:: WalletId
:: (IsOurs s, CompareDiscovery s, KnownAddresses s)
=> WalletId
-> ExceptT ErrNoSuchWallet IO [(Address, AddressState)]
_listAddresses wid = do
(s, txs) <- DB.withLock db $ (,)
Expand Down Expand Up @@ -573,7 +571,8 @@ newWalletLayer db nw tl = do
adjustForFee feeOpts utxo' sel

_signTx
:: WalletId
:: (Show s, NFData s, IsOwned s, GenChange s)
=> WalletId
-> Passphrase "encryption"
-> CoinSelection
-> ExceptT ErrSignTx IO (Tx, TxMeta, [TxWitness])
Expand Down Expand Up @@ -606,7 +605,8 @@ newWalletLayer db nw tl = do
throwE $ ErrSignTx e

_submitTx
:: WalletId
:: (TxId t)
=> WalletId
-> (Tx, TxMeta, [TxWitness])
-> ExceptT ErrSubmitTx IO ()
_submitTx wid (tx, meta, wit) = do
Expand Down
21 changes: 15 additions & 6 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ start settings wl = Warp.runSettings settings
Wallets
-------------------------------------------------------------------------------}

wallets :: KeyToAddress t => WalletLayer (SeqState t) t -> Server Wallets
wallets
:: (TxId t, KeyToAddress t)
=> WalletLayer (SeqState t) t
-> Server Wallets
wallets w =
deleteWallet w
:<|> getWallet w
Expand Down Expand Up @@ -212,7 +215,7 @@ listWallets w = do
mapM (getWalletWithCreationTime w) (ApiT <$> wids)

postWallet
:: KeyToAddress t
:: (KeyToAddress t, TxId t)
=> WalletLayer (SeqState t) t
-> WalletPostData
-> Handler ApiWallet
Expand Down Expand Up @@ -257,11 +260,14 @@ putWalletPassphrase w (ApiT wid) body = do
Addresses
-------------------------------------------------------------------------------}

addresses :: WalletLayer (SeqState t) t -> Server (Addresses t)
addresses
:: KeyToAddress t
=> WalletLayer (SeqState t) t
-> Server (Addresses t)
addresses = listAddresses

listAddresses
:: forall t. ()
:: forall t. (KeyToAddress t)
=> WalletLayer (SeqState t) t
-> ApiT WalletId
-> Maybe (ApiT AddressState)
Expand All @@ -280,11 +286,14 @@ listAddresses w (ApiT wid) stateFilter = do
Transactions
-------------------------------------------------------------------------------}

transactions :: TxId t => WalletLayer (SeqState t) t -> Server (Transactions t)
transactions
:: (TxId t, KeyToAddress t)
=> WalletLayer (SeqState t) t
-> Server (Transactions t)
transactions = createTransaction

createTransaction
:: forall t. (TxId t)
:: forall t. (TxId t, KeyToAddress t)
=> WalletLayer (SeqState t) t
-> ApiT WalletId
-> PostTransactionData t
Expand Down

0 comments on commit 51fc07f

Please sign in to comment.