Skip to content

Commit

Permalink
Extend public module Cardano.Write.Tx
Browse files Browse the repository at this point in the history
with the necessary types to be able to call `balanceTx`.
  • Loading branch information
HeinrichApfelmus committed Oct 18, 2024
1 parent 0d2adc1 commit 10ebb5f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 35 deletions.
1 change: 1 addition & 0 deletions lib/balance-tx/cardano-balance-tx.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ library
hs-source-dirs: lib/main
build-depends:
, cardano-balance-tx:internal
, cardano-ledger-api
exposed-modules:
Cardano.Write.Eras
Cardano.Write.Tx
Expand Down
51 changes: 38 additions & 13 deletions lib/balance-tx/lib/main/Cardano/Write/Tx.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
-- |
-- Copyright: © 2023 Cardano Foundation
-- Copyright: © 2023-2024 Cardano Foundation
-- License: Apache-2.0
--
--
module Cardano.Write.Tx
(
-- * Balancing transactions
balanceTx
-- * UTxO
UTxO (..)

-- * Tx
, Tx
, TxBody

-- ** PartialTx
, PartialTx (..)
, Redeemer (..)
, StakeKeyDepositLookup (..)
, TimelockKeyWitnessCounts (..)

-- ** Balancing
, balanceTx
, UTxOAssumptions (..)
, UTxOIndex
, constructUTxOIndex
, ChangeAddressGen (..)

-- ** Balancing Errors
, ErrAssignRedeemers (..)
, ErrBalanceTx (..)
, ErrBalanceTxAssetsInsufficientError (..)
Expand All @@ -14,28 +34,33 @@ module Cardano.Write.Tx
, ErrBalanceTxOutputError (..)
, ErrBalanceTxOutputErrorInfo (..)
, ErrBalanceTxUnableToCreateChangeError (..)

-- * UTxO-related types and functions
, UTxO
, UTxOAssumptions
, UTxOIndex
, constructUTxOIndex
) where

import Internal.Cardano.Write.Tx
( UTxO
import Cardano.Ledger.Api
( Tx
, TxBody
)
import Cardano.Ledger.Api.UTxO
( UTxO (..)
)
import Internal.Cardano.Write.Tx.Balance
( ErrAssignRedeemers (..)
( ChangeAddressGen (..)
, ErrAssignRedeemers (..)
, ErrBalanceTx (..)
, ErrBalanceTxAssetsInsufficientError (..)
, ErrBalanceTxInsufficientCollateralError (..)
, ErrBalanceTxInternalError (..)
, ErrBalanceTxOutputError (..)
, ErrBalanceTxOutputErrorInfo (..)
, ErrBalanceTxUnableToCreateChangeError (..)
, UTxOAssumptions
, PartialTx (..)
, Redeemer (..)
, StakeKeyDepositLookup (..)
, UTxOAssumptions (..)
, UTxOIndex
, balanceTx
, constructUTxOIndex
)
import Internal.Cardano.Write.Tx.Sign
( TimelockKeyWitnessCounts (..)
)
45 changes: 23 additions & 22 deletions lib/wallet/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ import Cardano.Write.Eras
, recentEra
)
import Cardano.Write.Tx
( ErrBalanceTx (..)
( ChangeAddressGen (..)
, ErrBalanceTx (..)
, ErrBalanceTxUnableToCreateChangeError (..)
)
import Control.Arrow
Expand Down Expand Up @@ -810,10 +811,7 @@ import Internal.Cardano.Write.Tx
( toRecentEraGADT
)
import Internal.Cardano.Write.Tx.Balance
( ChangeAddressGen (..)
, PartialTx (..)
, UTxOAssumptions (..)
, stakeCredentialsWithRefunds
( stakeCredentialsWithRefunds
)
import Internal.Cardano.Write.Tx.SizeEstimation
( TxWitnessTag (..)
Expand Down Expand Up @@ -875,6 +873,16 @@ import qualified Cardano.Write.Eras as Write
, RecentEra (..)
, cardanoEraFromRecentEra
)
import qualified Cardano.Write.Tx as Write
( PartialTx (..)
, StakeKeyDepositLookup (..)
, Tx
, UTxO (UTxO)
, UTxOAssumptions (..)
, UTxOIndex
, balanceTx
, constructUTxOIndex
)
import qualified Data.ByteArray as BA
import qualified Data.Delta.Update as Delta
import qualified Data.Foldable as F
Expand All @@ -888,8 +896,6 @@ import qualified Internal.Cardano.Write.Tx as Write
, FeePerByte
, PParams
, PParamsInAnyRecentEra (PParamsInAnyRecentEra)
, Tx
, UTxO (UTxO)
, feeOfBytes
, forceUTxOToEra
, fromCardanoApiTx
Expand All @@ -898,12 +904,7 @@ import qualified Internal.Cardano.Write.Tx as Write
, toCardanoApiTx
)
import qualified Internal.Cardano.Write.Tx.Balance as Write
( PartialTx
, StakeKeyDepositLookup (StakeKeyDepositAssumeCurrent, StakeKeyDepositMap)
, UTxOIndex
, balanceTx
, constructUTxOIndex
, fromWalletUTxO
( fromWalletUTxO
)

-- $Development
Expand Down Expand Up @@ -2186,7 +2187,7 @@ balanceTx
=> WalletLayer IO s
-> Write.PParams era
-> TimeTranslation
-> PartialTx era
-> Write.PartialTx era
-> IO (Write.Tx era)
balanceTx wrk pp timeTranslation partialTx = do
(utxo, wallet, _txs) <- liftIO $ readWalletUTxO wrk
Expand All @@ -2206,8 +2207,8 @@ balanceTx wrk pp timeTranslation partialTx = do
<$> getStakeDelegDeposits netLayer deregCreds

let utxoAssumptions = case walletFlavor @s of
ShelleyWallet -> AllKeyPaymentCredentials
SharedWallet -> AllScriptPaymentCredentialsFrom
ShelleyWallet -> Write.AllKeyPaymentCredentials
SharedWallet -> Write.AllScriptPaymentCredentialsFrom
(Shared.paymentTemplate (getState wallet))
(sharedWalletScriptLookup (getState wallet)
. Convert.toWalletAddress)
Expand Down Expand Up @@ -2553,7 +2554,7 @@ buildTransactionPure
utxoIndex
changeAddrGen
(getState wallet)
PartialTx
Write.PartialTx
{ tx = Write.fromCardanoApiTx (Cardano.Tx unsignedTxBody [])
, extraUTxO = Write.UTxO mempty
, redeemers = []
Expand Down Expand Up @@ -3248,7 +3249,7 @@ transactionFee DBLayer{atomically, walletState} protocolParams
(Left preSelection)

let ptx :: Write.PartialTx era
ptx = PartialTx
ptx = Write.PartialTx
{ tx = Write.fromCardanoApiTx (Cardano.Tx unsignedTxBody [])
, extraUTxO = Write.UTxO mempty
, redeemers = []
Expand Down Expand Up @@ -4174,8 +4175,8 @@ utxoAssumptionsForWallet
:: forall s
. (Excluding '[SharedKey] (KeyOf s))
=> WalletFlavorS s
-> UTxOAssumptions
-> Write.UTxOAssumptions
utxoAssumptionsForWallet = keyOfWallet >>> \case
ByronKeyS -> AllByronKeyPaymentCredentials
IcarusKeyS -> AllByronKeyPaymentCredentials
ShelleyKeyS -> AllKeyPaymentCredentials
ByronKeyS -> Write.AllByronKeyPaymentCredentials
IcarusKeyS -> Write.AllByronKeyPaymentCredentials
ShelleyKeyS -> Write.AllKeyPaymentCredentials

0 comments on commit 10ebb5f

Please sign in to comment.