@@ -21,7 +21,6 @@ import Control.Exception (IOException)
21
21
import Control.Monad.Class.MonadThrow (Handler (Handler ), catches )
22
22
import Control.Tracer (Tracer , traceWith )
23
23
import GHC.IO.Exception (IOErrorType (ResourceExhausted ), IOException (ioe_type ))
24
- import Hydra.Cardano.Api.Pretty (renderTx )
25
24
import Hydra.Chain.CardanoClient (queryProtocolParameters )
26
25
import Hydra.Chain.Direct.ScriptRegistry (
27
26
publishHydraScripts ,
@@ -107,39 +106,24 @@ returnFundsToFaucet ::
107
106
RunningNode ->
108
107
Actor ->
109
108
IO ()
110
- returnFundsToFaucet tracer node @ RunningNode {networkId, nodeSocket} sender = do
109
+ returnFundsToFaucet tracer RunningNode {networkId, nodeSocket} sender = do
111
110
(faucetVk, _) <- keysFor Faucet
112
111
let faucetAddress = mkVkAddress networkId faucetVk
113
112
114
113
(senderVk, senderSk) <- keysFor sender
115
114
utxo <- queryUTxOFor networkId nodeSocket QueryTip senderVk
116
- traceShowM (" RemainingFunds utxo:" <> renderUTxO utxo)
117
115
retryOnExceptions tracer $ do
118
116
let utxoValue = balance @ Tx utxo
119
117
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
134
119
submitTransaction networkId nodeSocket tx
135
120
void $ awaitTransaction networkId nodeSocket tx
136
- traceWith tracer $ ReturnedFunds {actor = actorName sender, returnAmount = returnBalance }
121
+ traceWith tracer $ ReturnedFunds {actor = actorName sender, returnAmount = allLovelace }
137
122
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
143
127
144
128
-- Use the Faucet utxo to create the output at specified address
145
129
createOutputAtAddress ::
0 commit comments