Skip to content

Commit

Permalink
Move OldEraNotSupported outside of ErrBalanceTx
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed May 26, 2023
1 parent cfd2847 commit e5ca221
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
7 changes: 6 additions & 1 deletion lib/wallet/api/http/Cardano/Wallet/Api/Http/Server/Error.hs
Expand Up @@ -82,6 +82,7 @@ import Cardano.Wallet
, ErrWithdrawalNotBeneficial (..)
, ErrWitnessTx (..)
, ErrWritePolicyPublicKey (..)
, ErrWriteTxEra (..)
, ErrWrongPassphrase (..)
, WalletException (..)
)
Expand Down Expand Up @@ -214,6 +215,7 @@ instance IsServerError WalletException where
ExceptionReadAccountPublicKey e -> toServerError e
ExceptionSignPayment e -> toServerError e
ExceptionBalanceTx e -> toServerError e
ExceptionWriteTxEra e -> toServerError e
ExceptionBalanceTxInternalError e -> toServerError e
ExceptionSubmitTransaction e -> toServerError e
ExceptionConstructTx e -> toServerError e
Expand Down Expand Up @@ -453,13 +455,16 @@ instance IsServerError ErrGetPolicyId where
, "from cosigner#0."
]

instance IsServerError ErrBalanceTx where
instance IsServerError ErrWriteTxEra where
toServerError = \case
ErrOldEraNotSupported (Cardano.AnyCardanoEra era) ->
apiError err403 BalanceTxEraNotSupported $ T.unwords
[ "Balancing in ", showT era, " "
, "is not supported."
]

instance IsServerError ErrBalanceTx where
toServerError = \case
ErrBalanceTxUpdateError (ErrExistingKeyWitnesses n) ->
apiError err403 BalanceTxExistingKeyWitnesses $ mconcat
[ "The transaction could not be balanced, because it contains "
Expand Down
6 changes: 3 additions & 3 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs
Expand Up @@ -3123,7 +3123,7 @@ balanceTransaction
mkRecentEra = case Cardano.cardanoEra @era of
Cardano.ConwayEra -> pure Write.RecentEraConway
Cardano.BabbageEra -> pure Write.RecentEraBabbage
_ -> liftHandler $ throwE $ Write.ErrOldEraNotSupported era
_ -> liftHandler $ throwE $ W.ErrOldEraNotSupported era

mkLedgerUTxO
:: [ApiExternalInput n]
Expand All @@ -3150,7 +3150,7 @@ balanceTransaction
(getState wallet)
partialTx

anyRecentTx <- maybeToHandler (Write.ErrOldEraNotSupported era)
anyRecentTx <- maybeToHandler (W.ErrOldEraNotSupported era)
. Write.asAnyRecentEra
. cardanoTxIdeallyNoLaterThan era
. getApiT $ body ^. #transaction
Expand Down Expand Up @@ -4250,7 +4250,7 @@ guardIsRecentEra (Cardano.AnyCardanoEra era) = case era of
Cardano.ShelleyEra -> liftE invalidEra
Cardano.ByronEra -> liftE invalidEra
where
invalidEra = Write.ErrOldEraNotSupported $ Cardano.AnyCardanoEra era
invalidEra = W.ErrOldEraNotSupported $ Cardano.AnyCardanoEra era

mkWithdrawal
:: forall n block
Expand Down
9 changes: 2 additions & 7 deletions lib/wallet/bench/restore-bench.hs
Expand Up @@ -51,11 +51,7 @@ import Cardano.BM.Trace
import Cardano.Mnemonic
( SomeMnemonic (..), entropyToMnemonic )
import Cardano.Wallet
( WalletException (..)
, WalletLayer (..)
, WalletWorkerLog (..)
, dummyChangeAddressGen
)
( WalletLayer (..), WalletWorkerLog (..), dummyChangeAddressGen )
import Cardano.Wallet.Address.Book
( AddressBookIso )
import Cardano.Wallet.Address.Derivation
Expand Down Expand Up @@ -253,7 +249,6 @@ import qualified Cardano.Wallet.Primitive.Types.UTxOStatistics as UTxOStatistics
import qualified Cardano.Wallet.Shelley.Compatibility as Cardano
import qualified Cardano.Wallet.Write.ProtocolParameters as Write
import qualified Cardano.Wallet.Write.Tx as Write
import qualified Cardano.Wallet.Write.Tx.Balance as Write
import qualified Data.Aeson as Aeson
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as B8
Expand Down Expand Up @@ -1015,7 +1010,7 @@ guardIsRecentEra (Cardano.AnyCardanoEra era) = case era of
Cardano.ShelleyEra -> invalidEra
Cardano.ByronEra -> invalidEra
where
invalidEra = throwIO $ ExceptionBalanceTx $ Write.ErrOldEraNotSupported $
invalidEra = throwIO $ W.ExceptionWriteTxEra $ W.ErrOldEraNotSupported $
Cardano.AnyCardanoEra era

withNonEmptyUTxO :: Wallet s -> Set Tx -> e -> IO a -> IO (Either e a)
Expand Down
6 changes: 6 additions & 0 deletions lib/wallet/src/Cardano/Wallet.hs
Expand Up @@ -195,6 +195,7 @@ module Cardano.Wallet
, ErrNoSuchTransaction (..)
, ErrStartTimeLaterThanEndTime (..)
, ErrWitnessTx (..)
, ErrWriteTxEra (..)

-- ** Root Key
, withRootKey
Expand Down Expand Up @@ -1866,6 +1867,10 @@ signTransaction key tl preferredLatestEra witCountCtx keyLookup mextraRewardAcc
type MakeRewardAccountBuilder k =
(k 'RootK XPrv, Passphrase "encryption") -> (XPrv, Passphrase "encryption")

data ErrWriteTxEra
= ErrOldEraNotSupported Cardano.AnyCardanoEra
deriving (Show, Eq)

-- | Build, Sign, Submit transaction.
--
-- Requires the encryption passphrase in order to decrypt the root private key.
Expand Down Expand Up @@ -3469,6 +3474,7 @@ data WalletException
| ExceptionReadAccountPublicKey ErrReadAccountPublicKey
| ExceptionSignPayment ErrSignPayment
| ExceptionBalanceTx ErrBalanceTx
| ExceptionWriteTxEra ErrWriteTxEra
| ExceptionBalanceTxInternalError ErrBalanceTxInternalError
| ExceptionSubmitTransaction ErrSubmitTransaction
| ExceptionConstructTx ErrConstructTx
Expand Down
1 change: 0 additions & 1 deletion lib/wallet/src/Cardano/Wallet/Write/Tx/Balance.hs
Expand Up @@ -299,7 +299,6 @@ data ErrBalanceTx
| ErrBalanceTxInternalError ErrBalanceTxInternalError
| ErrBalanceTxInputResolutionConflicts (NonEmpty (W.TxOut, W.TxOut))
| ErrBalanceTxUnresolvedInputs (NonEmpty W.TxIn)
| ErrOldEraNotSupported Cardano.AnyCardanoEra
deriving (Show, Eq)

-- | A 'PartialTx' is an an unbalanced 'SealedTx' along with the necessary
Expand Down

0 comments on commit e5ca221

Please sign in to comment.