Skip to content

Commit

Permalink
update TransactionCtx and TransactionSkeleton plus account execution …
Browse files Browse the repository at this point in the history
…costs

swagger rebase fix
  • Loading branch information
paweljakubas committed Sep 10, 2021
1 parent 8002b30 commit 7a8be8a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/core/src/Cardano/Wallet/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ data TransactionCtx = TransactionCtx
-- ^ Transaction expiry (TTL) slot.
, txDelegationAction :: Maybe DelegationAction
-- ^ An additional delegation to take.
, txPlutusScriptExecutionCost :: Coin
-- ^ An execution cost of plutus script determined by execution units
-- and prices obtained from network
} deriving (Show, Generic, Eq)

data Withdrawal
Expand All @@ -189,6 +192,7 @@ defaultTransactionCtx = TransactionCtx
, txMetadata = Nothing
, txTimeToLive = maxBound
, txDelegationAction = Nothing
, txPlutusScriptExecutionCost = Coin 0
}

-- | Whether the user is attempting any particular delegation action.
Expand Down
13 changes: 11 additions & 2 deletions lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
Expand Down Expand Up @@ -162,6 +163,8 @@ import Data.Word
( Word16, Word64, Word8 )
import Fmt
( Buildable, pretty )
import GHC.Generics
( Generic )
import GHC.Stack
( HasCallStack )
import Ouroboros.Network.Block
Expand Down Expand Up @@ -685,8 +688,9 @@ data TxSkeleton = TxSkeleton
-- multiple times, will appear multiple times in this list, once for each
-- mint or burn. For example if the caller "mints 3" of asset id "A", and
-- "burns 3" of asset id "A", "A" will appear twice in the list.
, txScriptExecutionCost :: !Coin
}
deriving (Eq, Show)
deriving (Eq, Show, Generic)

-- | Constructs an empty transaction skeleton.
--
Expand All @@ -703,6 +707,7 @@ emptyTxSkeleton txWitnessTag = TxSkeleton
, txChange = []
, txScripts = []
, txMintBurnAssets = []
, txScriptExecutionCost = Coin 0
}

-- | Constructs a transaction skeleton from wallet primitive types.
Expand All @@ -726,20 +731,24 @@ mkTxSkeleton witness context skeleton = TxSkeleton
-- Until we actually support minting and burning, leave these as empty.
, txScripts = []
, txMintBurnAssets = []
, txScriptExecutionCost = view #txPlutusScriptExecutionCost context
}

-- | Estimates the final cost of a transaction based on its skeleton.
--
estimateTxCost :: ProtocolParameters -> TxSkeleton -> Coin
estimateTxCost pp skeleton =
computeFee $ estimateTxSize skeleton
Coin.sumCoins [ computeFee $ estimateTxSize skeleton
, scriptExecutionCosts ]
where
LinearFee (Quantity a) (Quantity b) = getFeePolicy $ txParameters pp

computeFee :: TxSize -> Coin
computeFee (TxSize size) =
Coin $ ceiling (a + b * fromIntegral size)

scriptExecutionCosts = view #txScriptExecutionCost skeleton

-- | Estimates the final size of a transaction based on its skeleton.
--
-- This function uses the upper bounds of CBOR serialized objects as the basis
Expand Down
1 change: 0 additions & 1 deletion specifications/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,6 @@ x-executionUnitPrices: &executionUnitPrices
properties:
step_price: *rational
memory_unit_price: *rational
>>>>>>> 564064355 (extend ApiNetworkParameters, swagger and adjust testing)

#############################################################################
# #
Expand Down

0 comments on commit 7a8be8a

Please sign in to comment.