Skip to content

Commit

Permalink
add fee evaluation without wit count
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Sep 28, 2021
1 parent 6d22d89 commit 4beb322
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
16 changes: 9 additions & 7 deletions lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs
Expand Up @@ -77,6 +77,7 @@ module Cardano.Wallet.Shelley.Compatibility
, toCardanoStakeCredential
, toCardanoValue
, fromCardanoValue
, fromCardanoLovelace
, rewardAccountFromAddress
, fromShelleyPParams
, fromAlonzoPParams
Expand Down Expand Up @@ -1105,18 +1106,21 @@ fromAlonzoTx (Alonzo.ValidatedTx bod _wits (Alonzo.IsValid isValid) aux) =
then Just W.TxScriptValid
else Just W.TxScriptInvalid

-- Lovelace to coin. Quantities from ledger should always fit in Word64.
fromCardanoLovelace :: Cardano.Lovelace -> W.Coin
fromCardanoLovelace =
W.Coin . unsafeIntToWord . unQuantity . Cardano.lovelaceToQuantity
where
unQuantity (Cardano.Quantity q) = q

fromCardanoValue :: HasCallStack => Cardano.Value -> TokenBundle.TokenBundle
fromCardanoValue = uncurry TokenBundle.fromFlatList . extract
where
extract value =
( mkCoin $ Cardano.selectLovelace value
( fromCardanoLovelace $ Cardano.selectLovelace value
, mkBundle $ Cardano.valueToList value
)

-- Lovelace to coin. Quantities from ledger should always fit in Word64.
mkCoin :: Cardano.Lovelace -> W.Coin
mkCoin = W.Coin . unsafeIntToWord . unQuantity . Cardano.lovelaceToQuantity

-- Do Integer to Natural conversion. Quantities from ledger TxOuts can
-- never be negative (but unminted values could be negative).
mkQuantity :: Integer -> W.TokenQuantity
Expand All @@ -1134,8 +1138,6 @@ fromCardanoValue = uncurry TokenBundle.fromFlatList . extract
mkPolicyId = W.UnsafeTokenPolicyId . W.Hash . Cardano.serialiseToRawBytes
mkTokenName = W.UnsafeTokenName . Cardano.serialiseToRawBytes

unQuantity (Cardano.Quantity q) = q

fromShelleyWdrl :: SL.Wdrl crypto -> Map W.RewardAccount W.Coin
fromShelleyWdrl (SL.Wdrl wdrl) = Map.fromList $
bimap (fromStakeCredential . SL.getRwdCred) fromShelleyCoin
Expand Down
19 changes: 17 additions & 2 deletions lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs
Expand Up @@ -117,7 +117,8 @@ import Cardano.Wallet.Primitive.Types.Tx
, txSizeDistance
)
import Cardano.Wallet.Shelley.Compatibility
( fromCardanoTx
( fromCardanoLovelace
, fromCardanoTx
, fromLedgerExUnits
, toAllegraTxOut
, toAlonzoTxOut
Expand Down Expand Up @@ -480,7 +481,21 @@ _evaluateMinimumFee
:: Cardano.ProtocolParameters
-> SealedTx
-> Coin
_evaluateMinimumFee _ _ = undefined
_evaluateMinimumFee pp tx =
fromCardanoLovelace minFee
where
minFee = case getSealedTxBody tx of
InAnyCardanoEra ShelleyEra txbody ->
Cardano.evaluateTransactionFee @Cardano.ShelleyEra pp txbody (witsNum txbody) 0
InAnyCardanoEra AllegraEra txbody ->
Cardano.evaluateTransactionFee @Cardano.AllegraEra pp txbody (witsNum txbody) 0
InAnyCardanoEra MaryEra txbody ->
Cardano.evaluateTransactionFee @Cardano.MaryEra pp txbody (witsNum txbody) 0
InAnyCardanoEra AlonzoEra txbody ->
Cardano.evaluateTransactionFee @Cardano.AlonzoEra pp txbody (witsNum txbody) 0
InAnyCardanoEra ByronEra _ -> error "evaluation not supported for byron era"

witsNum _txbody = 0

_calcScriptExecutionCost
:: ProtocolParameters
Expand Down

0 comments on commit 4beb322

Please sign in to comment.