Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed Aug 10, 2022
1 parent f5e37cc commit 7ff6812
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions server/src/Api.hs
Expand Up @@ -38,6 +38,8 @@ import Types (
)

type Api =
-- Since @Script@ and @Data@ have @From/ToJSON@ instances, we can just
-- accept them in the body of a POST request
"apply-args"
:> ReqBody '[JSON] ApplyArgsRequest
:> Post '[JSON] AppliedScript
Expand Down
18 changes: 10 additions & 8 deletions src/Serialization/MinFee.purs
Expand Up @@ -6,15 +6,16 @@ import Prelude
import Cardano.Types.Transaction (_vkeys, _witnessSet)
import Cardano.Types.Transaction as T
import Cardano.Types.Value (Coin)
import Control.Monad.Error.Class (class MonadThrow, liftMaybe)
import Data.Array as Array
import Data.BigInt as BigInt
import Data.Lens ((.~))
import Data.Maybe (Maybe(Just), fromMaybe, maybe)
import Data.Maybe (Maybe(Just), fromMaybe)
import Data.Newtype (unwrap, wrap)
import Data.Tuple.Nested ((/\))
import Data.UInt as UInt
import Effect.Class (class MonadEffect, liftEffect)
import Effect.Exception (throw)
import Effect.Exception (Error, error)
import FfiHelpers (MaybeFfiHelper, maybeFfiHelper)
import QueryM.Ogmios (ProtocolParameters(ProtocolParameters))
import Serialization as Serialization
Expand All @@ -25,22 +26,23 @@ import Types.BigNum as BigNum
calculateMinFeeCsl
:: forall (m :: Type -> Type)
. MonadEffect m
=> MonadThrow Error m
=> ProtocolParameters
-> T.Transaction
-> m Coin
calculateMinFeeCsl (ProtocolParameters pparams) txNoSigs = do
let tx = addFakeSignatures txNoSigs
let txFeePerByte = BigInt.fromInt $ UInt.toInt pparams.txFeePerByte
let
tx = addFakeSignatures txNoSigs
txFeePerByte = BigInt.fromInt $ UInt.toInt pparams.txFeePerByte
cslTx <- liftEffect $ Serialization.convertTransaction tx
minFee <- maybe (liftEffect $ throw "Unable to calculate min_fee") pure $
minFee <- liftMaybe (error "Unable to calculate min_fee") $
BigNum.toBigInt =<< _minFee maybeFfiHelper cslTx
(BigNum.fromUInt pparams.txFeeFixed)
(BigNum.fromUInt pparams.txFeePerByte)
exUnitPrices <- maybe (liftEffect $ throw "Unable to get ExUnitPrices") pure $
pparams.prices
exUnitPrices <- liftMaybe (error "Unable to get ExUnitPrices") pparams.prices
exUnitPricesCsl <- liftEffect $ Serialization.convertExUnitPrices exUnitPrices
minScriptFee <-
maybe (liftEffect $ throw "Unable to calculate min_script_fee") pure $
liftMaybe (error "Unable to calculate min_script_fee") $
BigNum.toBigInt (_minScriptFee exUnitPricesCsl cslTx)
pure $ wrap $ minFee + minScriptFee + BigInt.fromInt 3 * txFeePerByte

Expand Down

0 comments on commit 7ff6812

Please sign in to comment.