@@ -6,6 +6,8 @@ module Cardano.Wallet.API.V1.Handlers.Transactions (
6
6
, newTransaction
7
7
, getTransactionsHistory
8
8
, estimateFees
9
+ -- | Helper converter.
10
+ , txFromMeta
9
11
) where
10
12
11
13
import Universum
@@ -15,37 +17,29 @@ import Servant
15
17
import Data.Coerce (coerce )
16
18
17
19
import Pos.Chain.Txp (TxId )
18
- import Pos.Client.Txp.Util (InputSelectionPolicy (.. ),
19
- defaultInputSelectionPolicy )
20
+ import Pos.Client.Txp.Util (defaultInputSelectionPolicy )
20
21
import Pos.Core (Address , Timestamp )
21
22
22
23
import Cardano.Wallet.API.Request
23
24
import Cardano.Wallet.API.Response
24
25
import qualified Cardano.Wallet.API.V1.Transactions as Transactions
25
26
import Cardano.Wallet.API.V1.Types
26
27
import Cardano.Wallet.Kernel.CoinSelection.FromGeneric
27
- (ExpenseRegulation (.. ), InputGrouping ( .. ) )
28
+ (ExpenseRegulation (.. ))
28
29
import Cardano.Wallet.Kernel.DB.HdWallet (UnknownHdAccount )
29
30
import Cardano.Wallet.Kernel.DB.TxMeta (TxMeta )
30
31
import qualified Cardano.Wallet.Kernel.Transactions as Kernel
31
32
import Cardano.Wallet.WalletLayer (ActiveWalletLayer ,
32
33
NewPaymentError (.. ), PassiveWalletLayer )
33
34
import qualified Cardano.Wallet.WalletLayer as WalletLayer
35
+ import Cardano.Wallet.WalletLayer.Kernel.Conv (toInputGrouping )
34
36
35
37
handlers :: ActiveWalletLayer IO -> ServerT Transactions. API Handler
36
38
handlers aw = newTransaction aw
37
39
:<|> getTransactionsHistory (WalletLayer. walletPassiveLayer aw)
38
40
:<|> estimateFees aw
39
41
:<|> redeemAda aw
40
42
41
- -- Matches the input InputGroupingPolicy with the Kernel's 'InputGrouping'
42
- toInputGrouping :: Maybe (V1 InputSelectionPolicy ) -> InputGrouping
43
- toInputGrouping v1GroupingPolicy =
44
- let (V1 policy) = fromMaybe (V1 defaultInputSelectionPolicy) v1GroupingPolicy
45
- in case policy of
46
- OptimizeForSecurity -> PreferGrouping
47
- OptimizeForHighThroughput -> IgnoreGrouping
48
-
49
43
-- | Given a 'Payment' as input, tries to generate a new 'Transaction', submitting
50
44
-- it to the network eventually.
51
45
newTransaction :: ActiveWalletLayer IO
@@ -55,8 +49,10 @@ newTransaction aw payment@Payment{..} = liftIO $ do
55
49
56
50
-- NOTE(adn) The 'SenderPaysFee' option will become configurable as part
57
51
-- of CBR-291.
52
+ let inputGrouping = toInputGrouping $ fromMaybe (V1 defaultInputSelectionPolicy)
53
+ pmtGroupingPolicy
58
54
res <- liftIO $ (WalletLayer. pay aw) (maybe mempty coerce pmtSpendingPassword)
59
- (toInputGrouping pmtGroupingPolicy)
55
+ inputGrouping
60
56
SenderPaysFee
61
57
payment
62
58
case res of
@@ -95,7 +91,9 @@ estimateFees :: ActiveWalletLayer IO
95
91
-> Payment
96
92
-> Handler (WalletResponse EstimatedFees )
97
93
estimateFees aw payment@ Payment {.. } = do
98
- res <- liftIO $ (WalletLayer. estimateFees aw) (toInputGrouping pmtGroupingPolicy)
94
+ let inputGrouping = toInputGrouping $ fromMaybe (V1 defaultInputSelectionPolicy)
95
+ pmtGroupingPolicy
96
+ res <- liftIO $ (WalletLayer. estimateFees aw) inputGrouping
99
97
SenderPaysFee
100
98
payment
101
99
case res of
0 commit comments