Skip to content

Commit

Permalink
Move Write.Tx modules to cardano-balance-tx
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Sep 13, 2023
1 parent a4c61f9 commit 5daa2ec
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 52 deletions.
37 changes: 37 additions & 0 deletions lib/balance-tx/cardano-balance-tx.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,33 @@ library
build-depends:
, base
, cardano-coin-selection
, cardano-slotting
, ouroboros-consensus
, cardano-wallet-primitive
, cardano-strict-containers
, cardano-ledger-shelley
, cardano-ledger-core
, cardano-api
, cardano-ledger-conway
, cardano-ledger-binary
, cardano-ledger-api
, text
, lens
, serialise
, cborg
, monoid-subclasses
, pretty-simple
, random
, std-gen-seed
, cardano-ledger-mary
, cardano-ledger-babbage
, cardano-ledger-alonzo
, cardano-ledger-allegra
, cardano-crypto-class
, ouroboros-consensus-cardano
, int-cast
, cardano-addresses
, bytestring
, cardano-wallet-test-utils
, containers
, deepseq
Expand All @@ -54,6 +80,17 @@ library
Cardano.Tx.Balance
Cardano.Tx.Balance.Internal.CoinSelection
Cardano.Tx.Balance.Internal.CoinSelection.Gen
Cardano.Wallet.Write.ProtocolParameters
Cardano.Wallet.Write.Tx
Cardano.Wallet.Write.Tx.Balance
Cardano.Wallet.Write.Tx.Balance.TokenBundleSize
Cardano.Wallet.Write.Tx.Gen
Cardano.Wallet.Write.Tx.Redeemers
Cardano.Wallet.Write.Tx.Sign
Cardano.Wallet.Write.Tx.SizeEstimation
Cardano.Wallet.Write.Tx.TimeTranslation
Cardano.Wallet.Write.UTxOAssumptions
Cardano.Wallet.Shelley.Compatibility.Ledger

test-suite test
import: language, opts-exe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import Cardano.Address.Script
( KeyHash (..), KeyRole (..), Script (..) )
import Cardano.Crypto.Hash
( hashFromBytes, hashToBytes )
import Cardano.Slotting.Slot
( SlotNo (..) )
import Cardano.Wallet.Primitive.Types.Address
( Address (..) )
import Cardano.Wallet.Primitive.Types.Coin
Expand Down Expand Up @@ -116,7 +118,6 @@ import qualified Cardano.Wallet.Primitive.Types.TokenBundle as TokenBundle
import qualified Cardano.Wallet.Primitive.Types.TokenMap as TokenMap
import qualified Data.Map.Strict as Map
import qualified Data.Sequence.Strict as StrictSeq
import qualified Ouroboros.Network.Block as O

--------------------------------------------------------------------------------
-- Roundtrip conversion between wallet types and ledger specification types
Expand Down Expand Up @@ -378,9 +379,9 @@ toWalletScript tokeyrole = fromLedgerScript
RequireAnyOf $ map fromLedgerScript $ toList contents
fromLedgerScript (Scripts.RequireMOf num contents) =
RequireSomeOf (fromIntegral num) $ fromLedgerScript <$> toList contents
fromLedgerScript (Scripts.RequireTimeExpire (O.SlotNo slot)) =
fromLedgerScript (Scripts.RequireTimeExpire (SlotNo slot)) =
ActiveUntilSlot $ fromIntegral slot
fromLedgerScript (Scripts.RequireTimeStart (O.SlotNo slot)) =
fromLedgerScript (Scripts.RequireTimeStart (SlotNo slot)) =
ActiveFromSlot $ fromIntegral slot

toWalletScriptFromShelley
Expand Down Expand Up @@ -427,8 +428,8 @@ toLedgerTimelockScript s = case s of
Scripts.RequireTimeStart
(convertSlotNo slot)
where
convertSlotNo :: Natural -> O.SlotNo
convertSlotNo x = O.SlotNo $ fromMaybe err $ intCastMaybe x
convertSlotNo :: Natural -> SlotNo
convertSlotNo x = SlotNo $ fromMaybe err $ intCastMaybe x
where
err = error $ unwords
[ "toLedgerTimelockScript:"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ import Cardano.Wallet.Primitive.Types.Tx
( SealedTx, sealedTxFromCardano )
import Cardano.Wallet.Primitive.Types.Tx.Constraints
( TxSize (..), txOutMaxCoin, txOutMaxTokenQuantity )
import Cardano.Wallet.Read.Primitive.Tx.Features.Outputs
( fromCardanoValue )
import Cardano.Wallet.Write.ProtocolParameters
( ProtocolParameters (..) )
import Cardano.Wallet.Write.Tx
Expand Down Expand Up @@ -156,11 +154,11 @@ import Cardano.Wallet.Write.Tx.Redeemers
import Cardano.Wallet.Write.Tx.Sign
( estimateKeyWitnessCount, estimateSignedTxSize )
import Cardano.Wallet.Write.Tx.SizeEstimation
( TxSkeleton (..), estimateTxCost )
( TxSkeleton (..), assumedTxWitnessTag, estimateTxCost )
import Cardano.Wallet.Write.Tx.TimeTranslation
( TimeTranslation )
import Cardano.Wallet.Write.UTxOAssumptions
( UTxOAssumptions (..), assumedInputScriptTemplate, assumedTxWitnessTag )
( UTxOAssumptions (..), assumedInputScriptTemplate )
import Control.Arrow
( left )
import Control.Monad
Expand Down Expand Up @@ -1606,3 +1604,6 @@ validateTxOutputAdaQuantity constraints output
(constraints ^. #computeMinimumAdaQuantity)
(fst output)
(snd output ^. #tokens)

fromCardanoValue :: Cardano.Value -> W.TokenBundle
fromCardanoValue = W.toWalletTokenBundle . Cardano.toMaryValue
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ module Cardano.Wallet.Write.Tx.SizeEstimation
, estimateTxCost
, TxSkeleton (..)

-- ** Needed for balance migration
-- ** TxWitnessTag
, TxWitnessTag (..)
, assumedTxWitnessTag

-- * Needed for balance migration
, txConstraints

-- ** Needed for estimateSignedTxSize
-- * Needed for estimateSignedTxSize
, sizeOf_BootstrapWitnesses

-- ** For the wallet
-- * For the wallet
, _txRewardWithdrawalCost
)

Expand Down Expand Up @@ -65,8 +69,6 @@ import Cardano.Wallet.Primitive.Types.Tx.Constraints
( TxConstraints (..), TxSize (..), txOutMaxCoin )
import Cardano.Wallet.Shelley.Compatibility.Ledger
( Convert (..) )
import Cardano.Wallet.TxWitnessTag
( TxWitnessTag (..) )
import Cardano.Wallet.Write.ProtocolParameters
( ProtocolParameters (..) )
import Cardano.Wallet.Write.Tx
Expand All @@ -82,6 +84,8 @@ import Cardano.Wallet.Write.Tx
)
import Cardano.Wallet.Write.Tx.Sign
( estimateMaxWitnessRequiredPerInput )
import Cardano.Wallet.Write.UTxOAssumptions
( UTxOAssumptions (..) )
import Control.Lens
( (^.) )
import Data.Generics.Internal.VL.Lens
Expand Down Expand Up @@ -697,3 +701,14 @@ mkLedgerTxOut txOutEra address bundle =
RecentEraConway -> W.toConwayTxOut txOut
where
txOut = W.TxOut address bundle

data TxWitnessTag
= TxWitnessByronUTxO
| TxWitnessShelleyUTxO
deriving (Show, Eq)

assumedTxWitnessTag :: UTxOAssumptions -> TxWitnessTag
assumedTxWitnessTag = \case
AllKeyPaymentCredentials -> TxWitnessShelleyUTxO
AllByronKeyPaymentCredentials -> TxWitnessByronUTxO
AllScriptPaymentCredentialsFrom {} -> TxWitnessShelleyUTxO
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Cardano.Wallet.Write.UTxOAssumptions
-- * UTxOAssumptions
UTxOAssumptions (..)
, assumedInputScriptTemplate
, assumedTxWitnessTag

-- * Validation
, validateAddress
Expand All @@ -21,8 +20,6 @@ import Prelude

import Cardano.Ledger.Shelley.API
( Addr (..), Credential (..) )
import Cardano.Wallet.TxWitnessTag
( TxWitnessTag (..) )
import Cardano.Wallet.Write.Tx
( Address )

Expand Down Expand Up @@ -50,12 +47,6 @@ assumedInputScriptTemplate = \case
AllByronKeyPaymentCredentials -> Nothing
AllScriptPaymentCredentialsFrom scriptTemplate _ -> Just scriptTemplate

assumedTxWitnessTag :: UTxOAssumptions -> TxWitnessTag
assumedTxWitnessTag = \case
AllKeyPaymentCredentials -> TxWitnessShelleyUTxO
AllByronKeyPaymentCredentials -> TxWitnessByronUTxO
AllScriptPaymentCredentialsFrom {} -> TxWitnessShelleyUTxO

validateAddress :: UTxOAssumptions -> Address -> Bool
validateAddress = valid
where
Expand Down
13 changes: 1 addition & 12 deletions lib/wallet/cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ library
Cardano.Wallet.Registry
Cardano.Wallet.Shelley.BlockchainSource
Cardano.Wallet.Shelley.Compatibility
Cardano.Wallet.Shelley.Compatibility.Ledger
Cardano.Wallet.Shelley.Network
Cardano.Wallet.Shelley.Network.Node
Cardano.Wallet.Shelley.Transaction
Expand All @@ -350,20 +349,9 @@ library
Cardano.Wallet.TokenMetadata
Cardano.Wallet.Transaction
Cardano.Wallet.Transaction.Built
Cardano.Wallet.TxWitnessTag
Cardano.Wallet.TypeLevel
Cardano.Wallet.Version
Cardano.Wallet.Version.TH
Cardano.Wallet.Write.ProtocolParameters
Cardano.Wallet.Write.Tx
Cardano.Wallet.Write.Tx.Balance
Cardano.Wallet.Write.Tx.Balance.TokenBundleSize
Cardano.Wallet.Write.Tx.Gen
Cardano.Wallet.Write.Tx.Redeemers
Cardano.Wallet.Write.Tx.Sign
Cardano.Wallet.Write.Tx.SizeEstimation
Cardano.Wallet.Write.Tx.TimeTranslation
Cardano.Wallet.Write.UTxOAssumptions
Control.Concurrent.Concierge
Control.Monad.Exception.Unchecked
Control.Monad.Fail.Extended
Expand Down Expand Up @@ -1068,6 +1056,7 @@ benchmark db
, cardano-wallet-primitive
, cardano-wallet-read
, cardano-wallet-test-utils
, cardano-balance-tx
, containers
, contra-tracer
, criterion
Expand Down
4 changes: 1 addition & 3 deletions lib/wallet/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,6 @@ import Cardano.Wallet.Transaction
)
import Cardano.Wallet.Transaction.Built
( BuiltTx (..) )
import Cardano.Wallet.TxWitnessTag
( TxWitnessTag (..) )
import Cardano.Wallet.Write.Tx
( recentEra )
import Cardano.Wallet.Write.Tx.Balance
Expand All @@ -523,7 +521,7 @@ import Cardano.Wallet.Write.Tx.Balance
, constructUTxOIndex
)
import Cardano.Wallet.Write.Tx.SizeEstimation
( _txRewardWithdrawalCost )
( TxWitnessTag (..), _txRewardWithdrawalCost )
import Cardano.Wallet.Write.Tx.TimeTranslation
( TimeTranslation )
import Control.Arrow
Expand Down
4 changes: 2 additions & 2 deletions lib/wallet/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ import Cardano.Wallet.Transaction
, WitnessCountCtx (..)
, selectionDelta
)
import Cardano.Wallet.TxWitnessTag
( TxWitnessTag (..) )
import Cardano.Wallet.Util
( HasCallStack, internalError )
import Cardano.Wallet.Write.Tx.SizeEstimation
( TxWitnessTag (..) )
import Control.Arrow
( left, second )
import Control.Lens
Expand Down
4 changes: 2 additions & 2 deletions lib/wallet/src/Cardano/Wallet/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ import Cardano.Wallet.Primitive.Types.Tx.TxIn
( TxIn (..) )
import Cardano.Wallet.Primitive.Types.Tx.TxOut
( TxOut (..) )
import Cardano.Wallet.TxWitnessTag
( TxWitnessTag )
import Control.DeepSeq
( NFData (..) )
import Data.List.NonEmpty
Expand All @@ -122,6 +120,8 @@ import qualified Cardano.Api as Cardano
import qualified Cardano.Wallet.Primitive.Types.TokenMap as TokenMap
import qualified Cardano.Wallet.Primitive.Types.Tx.TxOut as TxOut
import qualified Cardano.Wallet.Write.Tx as Write
import Cardano.Wallet.Write.Tx.SizeEstimation
( TxWitnessTag )
import qualified Data.Foldable as F
import qualified Data.List as L
import qualified Data.Map.Strict as Map
Expand Down
8 changes: 0 additions & 8 deletions lib/wallet/src/Cardano/Wallet/TxWitnessTag.hs

This file was deleted.

4 changes: 2 additions & 2 deletions lib/wallet/test/unit/Cardano/WalletSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ import Cardano.Wallet.Transaction
)
import Cardano.Wallet.Transaction.Built
( BuiltTx (..) )
import Cardano.Wallet.TxWitnessTag
( TxWitnessTag (TxWitnessShelleyUTxO) )
import Cardano.Wallet.Unsafe
( unsafeRunExceptT )
import Cardano.Wallet.Util
( HasCallStack )
import Cardano.Wallet.Write.Tx.Balance
( ErrBalanceTx (..), ErrBalanceTxAssetsInsufficientError (..) )
import Cardano.Wallet.Write.Tx.SizeEstimation
( TxWitnessTag (..) )
import Control.DeepSeq
( NFData (..) )
import Control.Monad
Expand Down

0 comments on commit 5daa2ec

Please sign in to comment.