Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADP-3344] Extend public Cardano.Write.Tx module #4812

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,6 @@ import Fmt
import GHC.Generics
( Generic
)
import Internal.Cardano.Write.Tx.Balance
( PartialTx (..)
, Redeemer (..)
)
import Internal.Cardano.Write.Tx.Sign
( TimelockKeyWitnessCounts
)
import Network.Ntp
( NtpClient
, getNtpStatus
Expand Down Expand Up @@ -887,6 +880,12 @@ import qualified Cardano.Write.Eras as Write
, RecentEra
, cardanoEraFromRecentEra
)
import qualified Cardano.Write.Tx as Write
( PartialTx (..)
, Redeemer (..)
, StakeKeyDepositLookup (..)
, TimelockKeyWitnessCounts (..)
)
import qualified Control.Concurrent.Concierge as Concierge
import qualified Data.ByteArray as BA
import qualified Data.ByteString as BS
Expand All @@ -908,10 +907,8 @@ import qualified Internal.Cardano.Write.Tx as Write
, toCardanoApiTx
, utxoFromTxOutsInRecentEra
)
import qualified Internal.Cardano.Write.Tx.Balance as Write
import qualified Internal.Cardano.Write.Tx.Sign as Write
( TimelockKeyWitnessCounts (..)
, estimateMinWitnessRequiredPerInput
( estimateMinWitnessRequiredPerInput
)
import qualified Network.Ntp as Ntp

Expand Down Expand Up @@ -2759,7 +2756,7 @@ constructTransaction api knownPools poolStatus apiWalletId body = do
wrk
pp
timeTranslation
PartialTx
Write.PartialTx
{ tx = Write.fromCardanoApiTx $ Cardano.Tx unbalancedTx []
, extraUTxO = mempty
, redeemers = mempty
Expand Down Expand Up @@ -3184,7 +3181,7 @@ constructSharedTransaction
wrk
pp
timeTranslation
PartialTx
Write.PartialTx
{ tx = Write.fromCardanoApiTx
$ Cardano.Tx unbalancedTx []
, extraUTxO = mempty
Expand Down Expand Up @@ -3401,7 +3398,7 @@ balanceTransaction ctx (ApiT wid) body = do
(fromApiRedeemer <$> body ^. #redeemers)
(Write.StakeKeyDepositMap mempty)
-- Stake key deposits will be queried by W.balanceTx
(mempty :: TimelockKeyWitnessCounts)
(mempty :: Write.TimelockKeyWitnessCounts)
Left e -> liftHandler $ throwE e

decodeTransaction
Expand Down Expand Up @@ -4880,14 +4877,14 @@ fromExternalInput ApiExternalInput
in
(inp, out)

fromApiRedeemer :: ApiRedeemer n -> Redeemer
fromApiRedeemer :: ApiRedeemer n -> Write.Redeemer
fromApiRedeemer = \case
ApiRedeemerSpending (ApiBytesT bytes) (ApiT i) ->
RedeemerSpending bytes (toLedger i)
Write.RedeemerSpending bytes (toLedger i)
ApiRedeemerMinting (ApiBytesT bytes) (ApiT p) ->
RedeemerMinting bytes (toLedger p)
Write.RedeemerMinting bytes (toLedger p)
ApiRedeemerRewarding (ApiBytesT bytes) (StakeAddress x y) ->
RedeemerRewarding bytes (Ledger.RewardAccount x y)
Write.RedeemerRewarding bytes (Ledger.RewardAccount x y)

sealWriteTx :: forall era. Write.IsRecentEra era => Write.Tx era -> W.SealedTx
sealWriteTx = W.sealedTxFromCardano
Expand Down
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
Loading