Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit 744b171

Browse files
Merge pull request input-output-hk/cardano-sl#3635 from input-output-hk/adinapoli/cbr-440
[CBR-440] Do not require the spending password for the estimation of the fees
2 parents 504ab33 + 67b0f11 commit 744b171

File tree

7 files changed

+191
-101
lines changed

7 files changed

+191
-101
lines changed

src/Cardano/Wallet/API/V1/Handlers/Transactions.hs

+1-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ estimateFees :: ActiveWalletLayer IO
9595
-> Payment
9696
-> Handler (WalletResponse EstimatedFees)
9797
estimateFees aw payment@Payment{..} = do
98-
let spendingPassword = maybe mempty coerce pmtSpendingPassword
99-
res <- liftIO $ (WalletLayer.estimateFees aw) spendingPassword
100-
(toInputGrouping pmtGroupingPolicy)
98+
res <- liftIO $ (WalletLayer.estimateFees aw) (toInputGrouping pmtGroupingPolicy)
10199
SenderPaysFee
102100
payment
103101
case res of

src/Cardano/Wallet/API/V1/Swagger.hs

+10
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,15 @@ endpoint is during API integration testing. Note also that this will fail by
10421042
default unless the node is running in debug mode.
10431043
|]
10441044

1045+
estimateFeesDescription :: Text
1046+
estimateFeesDescription = [text|
1047+
Estimate the fees which would incur from the input payment. This endpoint
1048+
**does not** require a _spending password_ to be supplied as it generates
1049+
under the hood an unsigned transaction. Therefore, callers can simply set
1050+
the `spendingPassword` field to `null` as that won't influence the fee
1051+
calculation.
1052+
|]
1053+
10451054

10461055
--
10471056
-- The API
@@ -1077,3 +1086,4 @@ api (compileInfo, curSoftwareVersion) walletAPI mkDescription = toSwagger wallet
10771086
& paths %~ (POST, "/api/internal/apply-update") `setDescription` applyUpdateDescription
10781087
& paths %~ (POST, "/api/internal/postpone-update") `setDescription` postponeUpdateDescription
10791088
& paths %~ (DELETE, "/api/internal/reset-wallet-state") `setDescription` resetWalletStateDescription
1089+
& paths %~ (POST, "/api/v1/transactions/fees") `setDescription` estimateFeesDescription

src/Cardano/Wallet/Kernel/CoinSelection/FromGeneric.hs

+32-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ module Cardano.Wallet.Kernel.CoinSelection.FromGeneric (
1212
, newOptions
1313
-- * Transaction building
1414
, CoinSelFinalResult(..)
15+
, UnsignedTx -- opaque
16+
, utxOwnedInputs
17+
, utxOutputs
18+
, utxChange
1519
, mkStdTx
20+
, mkStdUnsignedTx
1621
-- * Coin selection policies
1722
, random
1823
, largestFirst
@@ -178,6 +183,27 @@ feeOptions CoinSelectionOptions{..} = FeeOptions{
178183
Building transactions
179184
-------------------------------------------------------------------------------}
180185

186+
-- | Our notion of @unsigned transaction@. Unfortunately we cannot reuse
187+
-- directly the 'Tx' from @Core@ as that discards the information about
188+
-- "ownership" of inputs, which is instead required when dealing with the
189+
-- Core Txp.Util API.
190+
data UnsignedTx = UnsignedTx {
191+
utxOwnedInputs :: NonEmpty (Core.TxIn, Core.TxOutAux)
192+
, utxOutputs :: NonEmpty Core.TxOutAux
193+
, utxChange :: [Core.Coin]
194+
}
195+
196+
-- | Creates a "standard" unsigned transaction.
197+
mkStdUnsignedTx :: NonEmpty (Core.TxIn, Core.TxOutAux)
198+
-- ^ Selected inputs
199+
-> NonEmpty Core.TxOutAux
200+
-- ^ Selected outputs
201+
-> [Core.Coin]
202+
-- ^ Change coins
203+
-> UnsignedTx
204+
mkStdUnsignedTx inps outs change = UnsignedTx inps outs change
205+
206+
181207
-- | Build a transaction
182208

183209
-- | Construct a standard transaction
@@ -200,11 +226,12 @@ mkStdTx :: Monad m
200226
mkStdTx pm shuffle hdwSigners inps outs change = do
201227
allOuts <- shuffle $ foldl' (flip NE.cons) outs change
202228
return $ CTxp.makeMPubKeyTxAddrs pm hdwSigners (fmap repack inps) allOuts
203-
where
204-
-- Repack a utxo-derived tuple into a format suitable for
205-
-- 'TxOwnedInputs'.
206-
repack :: (Core.TxIn, Core.TxOutAux) -> (Core.TxOut, Core.TxIn)
207-
repack (txIn, aux) = (Core.toaOut aux, txIn)
229+
230+
-- | Repacks a utxo-derived tuple into a format suitable for
231+
-- 'TxOwnedInputs'.
232+
repack :: (Core.TxIn, Core.TxOutAux) -> (Core.TxOut, Core.TxIn)
233+
repack (txIn, aux) = (Core.toaOut aux, txIn)
234+
208235

209236
{-------------------------------------------------------------------------------
210237
Coin selection policy top-level entry point

0 commit comments

Comments
 (0)