Skip to content

Commit

Permalink
fix fee calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Mar 25, 2022
1 parent 7a0f9fe commit effdcba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
31 changes: 16 additions & 15 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2251,21 +2251,6 @@ constructTransaction ctx genChange knownPools getPoolStatus (ApiT wid) body = do

(utxoAvailable, wallet, pendingTxs) <-
liftHandler $ W.readWalletUTxOIndex @_ @s @k wrk wid
let runSelection outs =
W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams transform
where
selectAssetsParams = W.SelectAssetsParams
{ outputs = outs
, pendingTxs
, randomSeed = Nothing
, txContext = txCtx
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toMap utxoAvailable
, wallet
, selectionStrategy = SelectionStrategyOptimal
}
txCtx' <-
if isJust mintingBurning then do
(policyXPub, _) <-
Expand Down Expand Up @@ -2317,6 +2302,22 @@ constructTransaction ctx genChange knownPools getPoolStatus (ApiT wid) body = do
else
pure txCtx

let runSelection outs =
W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams transform
where
selectAssetsParams = W.SelectAssetsParams
{ outputs = outs
, pendingTxs
, randomSeed = Nothing
, txContext = txCtx'
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toMap utxoAvailable
, wallet
, selectionStrategy = SelectionStrategyOptimal
}

(sel, sel', fee) <- do
outs <- case (body ^. #payments) of
Nothing -> pure []
Expand Down
8 changes: 5 additions & 3 deletions lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ import qualified Data.Sequence.Strict as StrictSeq
import qualified Data.Set as Set
import qualified Data.Text as T

import qualified Debug.Trace as TR

-- | Type encapsulating what we need to know to add things -- payloads,
-- certificates -- to a transaction.
Expand Down Expand Up @@ -1395,8 +1396,9 @@ mkTxSkeleton witness context skeleton = TxSkeleton
, txInputCount = view #skeletonInputCount skeleton
, txOutputs = view #skeletonOutputs skeleton
, txChange = view #skeletonChange skeleton
-- Until we actually support minting and burning, leave these as empty.
, txScripts = []
, txScripts = (<>)
(Map.elems (snd $ view #txAssetsToMint context))
(Map.elems (snd $ view #txAssetsToBurn context))
, txAssetsToMintOrBurn = (<>)
(TokenMap.getAssets (fst $ view #txAssetsToMint context))
(TokenMap.getAssets (fst $ view #txAssetsToBurn context))
Expand Down Expand Up @@ -1431,7 +1433,7 @@ estimateTxCost pp skeleton =
--
estimateTxSize :: TxSkeleton -> TxSize
estimateTxSize skeleton =
TxSize $ fromIntegral sizeOf_Transaction
TR.trace ("skeleton:"<> show skeleton) $ TxSize $ fromIntegral sizeOf_Transaction
where
TxSkeleton
{ txMetadata
Expand Down

0 comments on commit effdcba

Please sign in to comment.