Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit a665716

Browse files
author
Denis Shevchenko
authored
Merge pull request #3656 from input-output-hk/CO-391-tx-endpoints
[CO-391] API WIP-handlers for external transactions.
2 parents ece672d + 376ac6c commit a665716

File tree

16 files changed

+624
-322
lines changed

16 files changed

+624
-322
lines changed

wallet-new/src/Cardano/Wallet/API/V1/Handlers/Transactions.hs

+11-13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module Cardano.Wallet.API.V1.Handlers.Transactions (
66
, newTransaction
77
, getTransactionsHistory
88
, estimateFees
9+
-- | Helper converter.
10+
, txFromMeta
911
) where
1012

1113
import Universum
@@ -15,37 +17,29 @@ import Servant
1517
import Data.Coerce (coerce)
1618

1719
import Pos.Chain.Txp (TxId)
18-
import Pos.Client.Txp.Util (InputSelectionPolicy (..),
19-
defaultInputSelectionPolicy)
20+
import Pos.Client.Txp.Util (defaultInputSelectionPolicy)
2021
import Pos.Core (Address, Timestamp)
2122

2223
import Cardano.Wallet.API.Request
2324
import Cardano.Wallet.API.Response
2425
import qualified Cardano.Wallet.API.V1.Transactions as Transactions
2526
import Cardano.Wallet.API.V1.Types
2627
import Cardano.Wallet.Kernel.CoinSelection.FromGeneric
27-
(ExpenseRegulation (..), InputGrouping (..))
28+
(ExpenseRegulation (..))
2829
import Cardano.Wallet.Kernel.DB.HdWallet (UnknownHdAccount)
2930
import Cardano.Wallet.Kernel.DB.TxMeta (TxMeta)
3031
import qualified Cardano.Wallet.Kernel.Transactions as Kernel
3132
import Cardano.Wallet.WalletLayer (ActiveWalletLayer,
3233
NewPaymentError (..), PassiveWalletLayer)
3334
import qualified Cardano.Wallet.WalletLayer as WalletLayer
35+
import Cardano.Wallet.WalletLayer.Kernel.Conv (toInputGrouping)
3436

3537
handlers :: ActiveWalletLayer IO -> ServerT Transactions.API Handler
3638
handlers aw = newTransaction aw
3739
:<|> getTransactionsHistory (WalletLayer.walletPassiveLayer aw)
3840
:<|> estimateFees aw
3941
:<|> redeemAda aw
4042

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-
4943
-- | Given a 'Payment' as input, tries to generate a new 'Transaction', submitting
5044
-- it to the network eventually.
5145
newTransaction :: ActiveWalletLayer IO
@@ -55,8 +49,10 @@ newTransaction aw payment@Payment{..} = liftIO $ do
5549

5650
-- NOTE(adn) The 'SenderPaysFee' option will become configurable as part
5751
-- of CBR-291.
52+
let inputGrouping = toInputGrouping $ fromMaybe (V1 defaultInputSelectionPolicy)
53+
pmtGroupingPolicy
5854
res <- liftIO $ (WalletLayer.pay aw) (maybe mempty coerce pmtSpendingPassword)
59-
(toInputGrouping pmtGroupingPolicy)
55+
inputGrouping
6056
SenderPaysFee
6157
payment
6258
case res of
@@ -95,7 +91,9 @@ estimateFees :: ActiveWalletLayer IO
9591
-> Payment
9692
-> Handler (WalletResponse EstimatedFees)
9793
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
9997
SenderPaysFee
10098
payment
10199
case res of

wallet-new/src/Cardano/Wallet/API/V1/ReifyWalletError.hs

+19
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,20 @@ newPendingError e = case e of
237237
(NewPendingFailed e') ->
238238
V1.UnknownError $ (sformat build e')
239239

240+
noHdAddressForSrcAddress :: HD.UnknownHdAddress -> V1.WalletError
241+
noHdAddressForSrcAddress e = case e of
242+
(HD.UnknownHdAddressRoot _rootId) ->
243+
V1.WalletNotFound
244+
245+
ex@(HD.UnknownHdAddressAccount _accId) ->
246+
V1.UnknownError $ (sformat build ex)
247+
248+
(HD.UnknownHdAddress _addrId) ->
249+
V1.AddressNotFound
250+
251+
(HD.UnknownHdCardanoAddress _coreAddr) ->
252+
V1.AddressNotFound
253+
240254
newForeignError :: NewForeignError -> V1.WalletError
241255
newForeignError e = case e of
242256
(NewForeignUnknown e') ->
@@ -250,6 +264,9 @@ newTransactionError e = case e of
250264
(Kernel.NewTransactionUnknownAccount e') ->
251265
unknownHdAccount e'
252266

267+
(Kernel.NewTransactionUnknownAddress _addrId) ->
268+
V1.AddressNotFound
269+
253270
(Kernel.NewTransactionErrorCoinSelectionFailed e') -> case e' of
254271
CoinSelHardErrOutputCannotCoverFee _outputs _fee ->
255272
V1.NotEnoughMoney V1.ErrCannotCoverFee
@@ -333,6 +350,8 @@ newPaymentError e = case e of
333350
newPendingError e''
334351
ex@(Kernel.PaymentSubmissionMaxAttemptsReached) ->
335352
V1.UnknownError $ (sformat build ex)
353+
(Kernel.PaymentNoHdAddressForSrcAddress e'') ->
354+
noHdAddressForSrcAddress e''
336355

337356
ex@(NewPaymentTimeLimitReached _) ->
338357
V1.UnknownError $ (sformat build ex)

0 commit comments

Comments
 (0)