Skip to content

Commit

Permalink
Drop unneeded TxWitnessByronIcarusUTxO
Browse files Browse the repository at this point in the history
  • Loading branch information
Unisay committed May 23, 2023
1 parent 7319aa7 commit 2a329c1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 60 deletions.
7 changes: 4 additions & 3 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import Cardano.Wallet
, networkLayer
, normalizeDelegationAddress
, normalizeSharedAddress
, utxoAssumptionsForWallet
)
import Cardano.Wallet.Address.Derivation
( Depth (..), Role (..), delegationAddressS, paymentAddressS )
Expand Down Expand Up @@ -185,6 +186,8 @@ import Cardano.Wallet.Api.Types.Error
( ApiErrorInfo (..) )
import Cardano.Wallet.Api.Types.SchemaMetadata
( TxMetadataSchema (..), parseSimpleMetadataFlag )
import Cardano.Wallet.Flavor
( WalletFlavorS (..) )
import Cardano.Wallet.Pools
( StakePoolLayer (..) )
import Cardano.Wallet.Primitive.Types
Expand All @@ -195,8 +198,6 @@ import Cardano.Wallet.Shelley.BlockchainSource
( BlockchainSource (..) )
import Cardano.Wallet.Shelley.Compatibility
( inspectAddress, rewardAccountFromAddress )
import Cardano.Wallet.Write.Tx.Balance
( UTxOAssumptions (AllKeyPaymentCredentials) )
import Control.Applicative
( liftA2 )
import Control.Monad
Expand Down Expand Up @@ -347,7 +348,7 @@ server byron icarus shelley multisig spl ntp blockchainSource =
:<|> postTransactionOld shelley (delegationAddressS @n)
:<|> postTransactionFeeOld shelley
:<|> balanceTransaction
shelley (delegationAddressS @n) AllKeyPaymentCredentials
shelley (delegationAddressS @n) (utxoAssumptionsForWallet ShelleyWallet)
:<|> decodeTransaction shelley
:<|> submitTransaction @_ @_ @_ @n shelley

Expand Down
11 changes: 6 additions & 5 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ import Cardano.Wallet
, networkLayer
, readWalletMeta
, transactionLayer
, utxoAssumptionsForWallet
)
import Cardano.Wallet.Address.Book
( AddressBookIso )
Expand Down Expand Up @@ -2454,7 +2455,7 @@ constructTransaction api argGenChange knownPools poolStatus apiWalletId body = d
withWorkerCtx api walletId liftE liftE $ \wrk -> do
let db = wrk ^. dbLayer
netLayer = wrk ^. networkLayer
txLayer = wrk ^. transactionLayer @ShelleyKey @'CredFromKeyK
txLayer = wrk ^. transactionLayer @k @'CredFromKeyK
trWorker = MsgWallet >$< wrk ^. logger
pp <- liftIO $ NW.currentProtocolParameters netLayer
era <- liftIO $ NW.currentNodeEra netLayer
Expand All @@ -2465,7 +2466,7 @@ constructTransaction api argGenChange knownPools poolStatus apiWalletId body = d
withdrawal <- case body ^. #withdrawal of
Just SelfWithdraw -> liftIO $
W.shelleyOnlyMkSelfWithdrawal
netLayer (txWitnessTagFor @ShelleyKey) era db
netLayer (txWitnessTagFor @k) era db
_ -> pure NoWithdrawal

let transactionCtx0 = defaultTransactionCtx
Expand Down Expand Up @@ -2497,7 +2498,7 @@ constructTransaction api argGenChange knownPools poolStatus apiWalletId body = d
(ApiT scriptT)
(Just (ApiT tName))
(ApiMint (ApiMintData _ amt)) ->
toTokenMapAndScript @ShelleyKey
toTokenMapAndScript @k
scriptT
(Map.singleton (Cosigner 0) policyXPub)
tName
Expand All @@ -2508,7 +2509,7 @@ constructTransaction api argGenChange knownPools poolStatus apiWalletId body = d
(ApiT scriptT)
(Just (ApiT tName))
(ApiBurn (ApiBurnData amt)) ->
toTokenMapAndScript @ShelleyKey
toTokenMapAndScript @k
scriptT
(Map.singleton (Cosigner 0) policyXPub)
tName
Expand Down Expand Up @@ -2564,7 +2565,7 @@ constructTransaction api argGenChange knownPools poolStatus apiWalletId body = d
balanceTransaction
api
argGenChange
AllKeyPaymentCredentials
(utxoAssumptionsForWallet (walletFlavor @s))
apiWalletId
ApiBalanceTransactionPostData
{ transaction = ApiT (sealedTxFromCardanoBody unbalancedTx)
Expand Down
30 changes: 15 additions & 15 deletions lib/wallet/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ module Cardano.Wallet
, throttle
, guardHardIndex
, toBalanceTxPParams
, utxoAssumptionsForWallet

-- * Logging
, WalletWorkerLog (..)
Expand Down Expand Up @@ -344,6 +345,7 @@ import Cardano.Wallet.Flavor
, WalletFlavor (..)
, WalletFlavorS (..)
, keyFlavor
, keyOfWallet
)
import Cardano.Wallet.Logging
( BracketLog
Expand Down Expand Up @@ -512,7 +514,7 @@ import Cardano.Wallet.Write.Tx.Balance
import Cardano.Wallet.Write.Tx.TimeTranslation
( TimeTranslation )
import Control.Arrow
( first )
( first, (>>>) )
import Control.DeepSeq
( NFData )
import Control.Monad
Expand Down Expand Up @@ -2112,16 +2114,10 @@ buildTransactionPure
txCtx
(Left preSelection)

let utxoAssumptions =
case keyFlavor @s of
ByronKeyS -> AllByronKeyPaymentCredentials
IcarusKeyS -> AllByronKeyPaymentCredentials
ShelleyKeyS -> AllKeyPaymentCredentials

withExceptT Left $
balanceTransaction @_ @_ @s
nullTracer
utxoAssumptions
(utxoAssumptionsForWallet (walletFlavor @s))
pparams
timeTranslation
(constructUTxOIndex utxo)
Expand Down Expand Up @@ -2794,17 +2790,11 @@ transactionFee DBLayer{atomically, walletState} protocolParams txLayer
, redeemers = []
}

let utxoAssumptions =
case keyFlavor @s of
ByronKeyS -> AllByronKeyPaymentCredentials
IcarusKeyS -> AllByronKeyPaymentCredentials
ShelleyKeyS -> AllKeyPaymentCredentials

wrapErrSelectAssets $ calculateFeePercentiles $ do
res <- runExceptT $
balanceTransaction @_ @_ @s
nullTracer
utxoAssumptions
(utxoAssumptionsForWallet (walletFlavor @s))
protocolParams
timeTranslation
utxoIndex
Expand Down Expand Up @@ -3706,3 +3696,13 @@ dummyChangeAddressGen =
ChangeAddressGen
(maxLengthAddressFor (keyFlavor @s),)
(maxLengthAddressFor (keyFlavor @s))

utxoAssumptionsForWallet
:: forall s
. Excluding '[SharedKey] (KeyOf s)
=> WalletFlavorS s
-> UTxOAssumptions
utxoAssumptionsForWallet = keyOfWallet >>> \case
ByronKeyS -> AllByronKeyPaymentCredentials
IcarusKeyS -> AllByronKeyPaymentCredentials
ShelleyKeyS -> AllKeyPaymentCredentials
2 changes: 1 addition & 1 deletion lib/wallet/src/Cardano/Wallet/Address/Derivation/Icarus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ newtype IcarusKey (depth :: Depth) key =
instance NFData key => NFData (IcarusKey depth key)

instance TxWitnessTagFor IcarusKey where
txWitnessTagFor = TxWitnessByronIcarusUTxO
txWitnessTagFor = TxWitnessByronUTxO

-- | The minimum seed length for 'generateKeyFromSeed' and 'unsafeGenerateKeyFromSeed'.
minSeedLengthBytes :: Int
Expand Down
5 changes: 0 additions & 5 deletions lib/wallet/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,6 @@ signTransaction
mkShelleyWitness body (getRawKey k, pwd)
TxWitnessByronUTxO ->
mkByronWitness body networkId addr (getRawKey k, pwd)
TxWitnessByronIcarusUTxO ->
mkByronWitness body networkId addr (getRawKey k, pwd)

mkWdrlCertWitness :: RewardAccount -> Maybe (Cardano.KeyWitness era)
mkWdrlCertWitness a =
Expand Down Expand Up @@ -1745,7 +1743,6 @@ estimateTxSize era skeleton =
numberOf_VkeyWitnesses
= case txWitnessTag of
TxWitnessByronUTxO -> 0
TxWitnessByronIcarusUTxO -> 0
TxWitnessShelleyUTxO ->
if numberOf_ScriptVkeyWitnesses == 0 then
numberOf_Inputs
Expand All @@ -1761,7 +1758,6 @@ estimateTxSize era skeleton =
numberOf_BootstrapWitnesses
= case txWitnessTag of
TxWitnessByronUTxO -> numberOf_Inputs
TxWitnessByronIcarusUTxO -> numberOf_Inputs
TxWitnessShelleyUTxO -> 0

-- transaction =
Expand Down Expand Up @@ -1992,7 +1988,6 @@ estimateTxSize era skeleton =
sizeOf_ChangeAddress
= case txWitnessTag of
TxWitnessByronUTxO -> 85
TxWitnessByronIcarusUTxO -> 85
TxWitnessShelleyUTxO -> 59

-- value = coin / [coin,multiasset<uint>]
Expand Down
1 change: 0 additions & 1 deletion lib/wallet/src/Cardano/Wallet/TxWitnessTag.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Data.Kind

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

Expand Down
65 changes: 35 additions & 30 deletions lib/wallet/src/Cardano/Wallet/Write/Tx/Balance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ import Cardano.Tx.Balance.Internal.CoinSelection
)
import Cardano.Wallet.Primitive.Types
( TokenBundleMaxSize (TokenBundleMaxSize) )
import Cardano.Wallet.Primitive.Types.Address
( Address )
import Cardano.Wallet.Primitive.Types.Redeemer
( Redeemer )
import Cardano.Wallet.Primitive.Types.TokenBundle
Expand All @@ -96,7 +98,6 @@ import Cardano.Wallet.Shelley.Transaction
( KeyWitnessCount (..)
, TxFeeUpdate (..)
, TxUpdate (..)
, TxWitnessTag (..)
, assignScriptRedeemers
, calculateMinimumFee
, distributeSurplus
Expand All @@ -112,6 +113,8 @@ import Cardano.Wallet.Transaction
, TxFeeAndChange (..)
, defaultTransactionCtx
)
import Cardano.Wallet.TxWitnessTag
( TxWitnessTag (..) )
import Cardano.Wallet.Write.ProtocolParameters
( ProtocolParameters (..) )
import Cardano.Wallet.Write.Tx
Expand Down Expand Up @@ -333,6 +336,20 @@ instance Buildable (PartialTx era) where
cardanoTxF :: Cardano.Tx era -> Builder
cardanoTxF tx' = pretty $ pShow tx'

data UTxOIndex era = UTxOIndex
{ walletUTxO :: !W.UTxO
, walletUTxOIndex :: !(UTxOIndex.UTxOIndex WalletUTxO)
, cardanoUTxO :: !(Cardano.UTxO era)
}

constructUTxOIndex :: IsRecentEra era => W.UTxO -> UTxOIndex era
constructUTxOIndex walletUTxO =
UTxOIndex {walletUTxO, walletUTxOIndex, cardanoUTxO}
where
walletUTxOIndex = UTxOIndex.fromMap $ toInternalUTxOMap walletUTxO
cardanoUTxO = toCardanoUTxO Cardano.shelleyBasedEra walletUTxO


-- | Assumptions about the UTxO which are needed for coin-selection.
data UTxOAssumptions
= AllKeyPaymentCredentials
Expand All @@ -345,21 +362,21 @@ data UTxOAssumptions
-- Assumes all 'UTxO' entries have addresses with script
-- payment credentials, where the scripts are both derived
-- from the 'ScriptTemplate' and can be looked up using the given function.
ScriptTemplate
(W.Address -> CA.Script KeyHash)
!ScriptTemplate
!(Address -> CA.Script KeyHash)

data UTxOIndex era = UTxOIndex
{ walletUTxO :: !W.UTxO
, walletUTxOIndex :: !(UTxOIndex.UTxOIndex WalletUTxO)
, cardanoUTxO :: !(Cardano.UTxO era)
}
assumedInputScriptTemplate :: UTxOAssumptions -> Maybe ScriptTemplate
assumedInputScriptTemplate = \case
AllKeyPaymentCredentials -> Nothing
AllByronKeyPaymentCredentials -> Nothing
AllScriptPaymentCredentialsFrom scriptTemplate _ -> Just scriptTemplate

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

constructUTxOIndex :: IsRecentEra era => W.UTxO -> UTxOIndex era
constructUTxOIndex walletUTxO =
UTxOIndex {walletUTxO, walletUTxOIndex, cardanoUTxO}
where
walletUTxOIndex = UTxOIndex.fromMap $ toInternalUTxOMap walletUTxO
cardanoUTxO = toCardanoUTxO Cardano.shelleyBasedEra walletUTxO

balanceTransaction
:: forall era m changeState.
Expand Down Expand Up @@ -490,10 +507,10 @@ increaseZeroAdaOutputs era pp = modifyLedgerBody $

-- | Internal helper to 'balanceTransaction'
balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment
:: forall era m changeState
. ( MonadRandom m
, IsRecentEra era
)
:: forall era m changeState.
( MonadRandom m
, IsRecentEra era
)
=> Tracer m BalanceTxLog
-> UTxOAssumptions
-> ProtocolParameters era
Expand Down Expand Up @@ -1009,18 +1026,6 @@ selectAssets era (ProtocolParameters pp) utxoAssumptions outs redeemers
-- in the final stage of 'balanceTransaction'.
extraBytes = 8

assumedInputScriptTemplate :: UTxOAssumptions -> Maybe ScriptTemplate
assumedInputScriptTemplate = \case
AllKeyPaymentCredentials -> Nothing
AllByronKeyPaymentCredentials -> Nothing
AllScriptPaymentCredentialsFrom scriptTemplate _ -> Just scriptTemplate

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

data ChangeAddressGen s = ChangeAddressGen
{ getChangeAddressGen :: s -> (W.Address, s)

Expand Down

0 comments on commit 2a329c1

Please sign in to comment.