Skip to content

Commit 62ad10a

Browse files
committed
Remove fee calculation
Let the makeTransactionBodyAutoBalance do its work.
1 parent 98432c5 commit 62ad10a

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

hydra-cluster/src/Hydra/Cluster/Faucet.hs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import Control.Exception (IOException)
2121
import Control.Monad.Class.MonadThrow (Handler (Handler), catches)
2222
import Control.Tracer (Tracer, traceWith)
2323
import GHC.IO.Exception (IOErrorType (ResourceExhausted), IOException (ioe_type))
24-
import Hydra.Cardano.Api.Pretty (renderTx)
2524
import Hydra.Chain.CardanoClient (queryProtocolParameters)
2625
import Hydra.Chain.Direct.ScriptRegistry (
2726
publishHydraScripts,
@@ -107,39 +106,24 @@ returnFundsToFaucet ::
107106
RunningNode ->
108107
Actor ->
109108
IO ()
110-
returnFundsToFaucet tracer node@RunningNode{networkId, nodeSocket} sender = do
109+
returnFundsToFaucet tracer RunningNode{networkId, nodeSocket} sender = do
111110
(faucetVk, _) <- keysFor Faucet
112111
let faucetAddress = mkVkAddress networkId faucetVk
113112

114113
(senderVk, senderSk) <- keysFor sender
115114
utxo <- queryUTxOFor networkId nodeSocket QueryTip senderVk
116-
traceShowM ("RemainingFunds utxo:" <> renderUTxO utxo)
117115
retryOnExceptions tracer $ do
118116
let utxoValue = balance @Tx utxo
119117
let allLovelace = selectLovelace utxoValue
120-
traceShowM ("allLovelace:" <> show allLovelace)
121-
-- select tokens other than ADA here so we can burn it afterwards
122-
let otherTokens = filterValue (/= AdaAssetId) utxoValue
123-
traceShowM ("otherTokens:" <> renderValue otherTokens)
124-
-- XXX: Using a hard-coded high-enough value to satisfy the min utxo value.
125-
-- NOTE: We use the faucet address as the change deliberately here.
126-
fee <- calculateTxFee node senderSk utxo faucetAddress 1_000_000
127-
traceShowM ("fee:" <> show fee)
128-
let returnBalance = allLovelace - fee
129-
traceShowM ("returnBalance:" <> show returnBalance)
130-
returnTxBody <- buildTxBody utxo faucetAddress returnBalance otherTokens
131-
traceShowM ("returnTxBody:" <> show returnTxBody)
132-
let tx = sign senderSk returnTxBody
133-
traceShowM ("tx:" <> renderTx tx)
118+
tx <- sign senderSk <$> buildTxBody utxo faucetAddress
134119
submitTransaction networkId nodeSocket tx
135120
void $ awaitTransaction networkId nodeSocket tx
136-
traceWith tracer $ ReturnedFunds{actor = actorName sender, returnAmount = returnBalance}
121+
traceWith tracer $ ReturnedFunds{actor = actorName sender, returnAmount = allLovelace}
137122
where
138-
buildTxBody utxo faucetAddress lovelace otherTokens =
139-
let theOutput = TxOut faucetAddress (lovelaceToValue lovelace <> negateValue otherTokens) TxOutDatumNone ReferenceScriptNone
140-
in buildTransaction networkId nodeSocket faucetAddress utxo [] [theOutput] >>= \case
141-
Left e -> throwIO $ FaucetFailedToBuildTx{reason = e}
142-
Right body -> pure body
123+
buildTxBody utxo faucetAddress =
124+
buildTransaction networkId nodeSocket faucetAddress utxo [] [] >>= \case
125+
Left e -> throwIO $ FaucetFailedToBuildTx{reason = e}
126+
Right body -> pure body
143127

144128
-- Use the Faucet utxo to create the output at specified address
145129
createOutputAtAddress ::

0 commit comments

Comments
 (0)