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

Refactor in preparation to reuse balanceTransaction within quitStakePool. #3555

Merged
merged 30 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4f2d9fb
rename Cardano.Wallet.Shelley.Pools to Cardano.Wallet.Pools
Unisay Oct 25, 2022
192af55
chore: quitStakePool readability improvements
Unisay Oct 26, 2022
9ff1c9f
chore: inline "where" bindings to improve local reasoning
Unisay Oct 26, 2022
3710aa9
chore: reflow comment to fit line width
Unisay Nov 1, 2022
9b3bd04
chore: refactor - remove unnecessary parenthesis
Unisay Nov 1, 2022
e66521d
replace errors with exceptions
Unisay Nov 1, 2022
ae9d163
refactor: inline queryRewardBalance
Unisay Nov 1, 2022
9a6b0c7
refactor: remove unused ErrMintBurnAssets
Unisay Nov 1, 2022
00e6cf4
chore: formatting and syntax improvements
Unisay Nov 1, 2022
61f092f
remove unnecessary polymorphism
Unisay Nov 1, 2022
dfc9d36
refactor: break mkRewardAccountBuilder into smaller functions
Unisay Nov 1, 2022
a66f249
refactor: mkApiTransaction uses fields not lenses
Unisay Nov 1, 2022
83d4162
refactor: quitStakePool renamed to validatedQuitStakePoolAction
Unisay Nov 1, 2022
df898b2
refactor: rename getTxExpiry to transactionExpirySlot
Unisay Nov 1, 2022
5c7b620
refactor: quitStakePool builds TransactionCtx
Unisay Nov 1, 2022
d878465
Use Refl instead of an irrefutable pattern.
Unisay Nov 3, 2022
d4c67eb
remove unnecessary polymorphism
Unisay Nov 3, 2022
fe09015
remove unnecessary polymorphism
Unisay Nov 7, 2022
2916b9c
WalletException gets converted to ServerError in hoistServer
Unisay Nov 7, 2022
7a083a4
refactor: rename `c` to `coin`
Unisay Nov 7, 2022
2620043
WalletException gets converted to ServerError in hoistServer
Unisay Nov 7, 2022
5848c76
Replace throw with throwIO
Unisay Nov 7, 2022
239d8fc
chore: reorder imports
Unisay Nov 7, 2022
fe4adf5
refactor: simplify handleWalletExceptions
Unisay Nov 8, 2022
bec7ecc
Split mkRewardAccoundBuilder into smaller builders
Unisay Nov 8, 2022
7cdc038
chore: reorder import
Unisay Nov 9, 2022
b1f3300
fix: zero reward is not worth withdrawing
Unisay Nov 9, 2022
c072c2b
self withdrawal won't throw if its not worth
Unisay Nov 11, 2022
eee2269
fixup! remove unnecessary polymorphism
Unisay Nov 11, 2022
6116528
Touch CI
Unisay Nov 13, 2022
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
23 changes: 12 additions & 11 deletions lib/wallet/api/http/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ import Cardano.Wallet.DB
( DBFactory, DBLayer )
import Cardano.Wallet.Network
( NetworkLayer )
import Cardano.Wallet.Pools
( StakePool )
import Cardano.Wallet.Primitive.AddressDerivation
( Depth, DerivationIndex, Role )
import Cardano.Wallet.Primitive.Types
Expand Down Expand Up @@ -308,8 +310,6 @@ import Servant.API.Verbs
)

import qualified Cardano.Wallet.Primitive.Types as W
import Cardano.Wallet.Shelley.Pools
( StakePool )

type ApiV2 n = "v2" :> Api n

Expand Down Expand Up @@ -1164,15 +1164,16 @@ type PostExternalTransaction = "proxy"

data ApiLayer s (k :: Depth -> Type -> Type) ktype
= ApiLayer
(Tracer IO TxSubmitLog)
(Tracer IO (WorkerLog WalletId WalletWorkerLog))
(Block, NetworkParameters)
(NetworkLayer IO Block)
(TransactionLayer k ktype SealedTx)
(DBFactory IO s k)
(WorkerRegistry WalletId (DBLayer IO s k))
(Concierge IO WalletLock)
(TokenMetadataClient IO)
{ tracerTxSubmit :: Tracer IO TxSubmitLog
, tracerWalletWorker :: Tracer IO (WorkerLog WalletId WalletWorkerLog)
, netParams :: (Block, NetworkParameters)
, netLayer :: NetworkLayer IO Block
, txLayer :: TransactionLayer k ktype SealedTx
, _dbFactory :: DBFactory IO s k
, _workerRegistry :: WorkerRegistry WalletId (DBLayer IO s k)
, concierge :: Concierge IO WalletLock
, _tokenMetadataClient :: TokenMetadataClient IO
}
deriving (Generic)

-- | Locks that are held by the wallet in order to enforce
Expand Down
4 changes: 2 additions & 2 deletions lib/wallet/api/http/Cardano/Wallet/Api/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ import Cardano.Wallet.Api.Types
)
import Cardano.Wallet.Api.Types.SchemaMetadata
( TxMetadataSchema, toSimpleMetadataFlag )
import Cardano.Wallet.Pools
( StakePool )
import Cardano.Wallet.Primitive.Types
( SortOrder, WalletId )
import Cardano.Wallet.Primitive.Types.Address
Expand All @@ -122,8 +124,6 @@ import Servant.Client
import UnliftIO.Exception
( throwString )

import Cardano.Wallet.Shelley.Pools
( StakePool )
import qualified Data.Aeson as Aeson

{-------------------------------------------------------------------------------
Expand Down
13 changes: 8 additions & 5 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ import Cardano.Wallet.Api.Types.Error
( ApiErrorInfo (..) )
import Cardano.Wallet.Api.Types.SchemaMetadata
( TxMetadataSchema (..), parseSimpleMetadataFlag )
import Cardano.Wallet.Pools
( StakePoolLayer (..) )
import Cardano.Wallet.Primitive.AddressDerivation
( DelegationAddress (..), Depth (..), PaymentAddress (..), Role (..) )
import Cardano.Wallet.Primitive.AddressDerivation.Byron
Expand All @@ -195,8 +197,6 @@ import Cardano.Wallet.Shelley.Compatibility
( inspectAddress, rewardAccountFromAddress )
import Cardano.Wallet.Shelley.Network.Discriminant
( HasNetworkId (networkIdVal) )
import Cardano.Wallet.Shelley.Pools
( StakePoolLayer (..) )
import Control.Applicative
( liftA2 )
import Control.Monad
Expand Down Expand Up @@ -338,7 +338,10 @@ server byron icarus shelley multisig spl ntp blockchainSource =

shelleyTransactions :: Server (ShelleyTransactions n)
shelleyTransactions =
constructTransaction shelley (delegationAddress @n) (knownPools spl) (getPoolLifeCycleStatus spl)
constructTransaction shelley
(delegationAddress @n)
(knownPools spl)
(getPoolLifeCycleStatus spl)
:<|> signTransaction @_ @_ @_ @'CredFromKeyK shelley
:<|>
(\wid mMinWithdrawal mStart mEnd mOrder simpleMetadataFlag ->
Expand Down Expand Up @@ -507,7 +510,7 @@ server byron icarus shelley multisig spl ntp blockchainSource =
(icarus, deleteTransaction icarus wid txid)
)
:<|> (\wid tx -> withLegacyLayer wid
(byron , do
(byron, do
let pwd = coerce (getApiT $ tx ^. #passphrase)
genChange <- rndStateChange byron wid pwd
postTransactionOld byron genChange wid tx
Expand All @@ -519,7 +522,7 @@ server byron icarus shelley multisig spl ntp blockchainSource =
)
)
:<|> (\wid tx -> withLegacyLayer wid
(byron , postTransactionFeeOld byron wid tx)
(byron, postTransactionFeeOld byron wid tx)
(icarus, postTransactionFeeOld icarus wid tx)
)

Expand Down
69 changes: 56 additions & 13 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Server/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

-- |
Expand Down Expand Up @@ -73,6 +74,7 @@ import Cardano.Wallet
, ErrWitnessTx (..)
, ErrWritePolicyPublicKey (..)
, ErrWrongPassphrase (..)
, WalletException (..)
)
import Cardano.Wallet.Api.Types
( Iso8601Time (..) )
Expand Down Expand Up @@ -100,7 +102,7 @@ import Cardano.Wallet.Primitive.AddressDiscovery.Shared
( ErrAddCosigner (..), ErrScriptTemplate (..) )
import Cardano.Wallet.Primitive.Slotting
( PastHorizonException )
import Cardano.Wallet.Primitive.Types.TokenBundle
import Cardano.Wallet.Primitive.Types.TokenMap
( Flat (..) )
import Cardano.Wallet.Transaction
( ErrAssignRedeemers (..), ErrSignTx (..) )
Expand Down Expand Up @@ -190,6 +192,43 @@ err425 = ServerError 425 "Too early" "" []
showT :: Show a => a -> Text
showT = T.pack . show

instance IsServerError WalletException where
toServerError = \case
ExceptionSignMetadataWith e -> toServerError e
ExceptionDerivePublicKey e -> toServerError e
ExceptionAddCosignerKey e -> toServerError e
ExceptionConstructSharedWallet e -> toServerError e
ExceptionReadAccountPublicKey e -> toServerError e
ExceptionListUTxOStatistics e -> toServerError e
ExceptionSignPayment e -> toServerError e
ExceptionBalanceTx e -> toServerError e
ExceptionBalanceTxInternalError e -> toServerError e
ExceptionSubmitTransaction e -> toServerError e
ExceptionConstructTx e -> toServerError e
ExceptionGetPolicyId e -> toServerError e
ExceptionWitnessTx e -> toServerError e
ExceptionDecodeTx e -> toServerError e
ExceptionSubmitTx e -> toServerError e
ExceptionUpdatePassphrase e -> toServerError e
ExceptionWithRootKey e -> toServerError e
ExceptionListTransactions e -> toServerError e
ExceptionGetTransaction e -> toServerError e
ExceptionStartTimeLaterThanEndTime e -> toServerError e
ExceptionCreateMigrationPlan e -> toServerError e
ExceptionSelectAssets e -> toServerError e
ExceptionStakePoolDelegation e -> toServerError e
ExceptionFetchRewards e -> toServerError e
ExceptionWalletNotResponding e -> toServerError e
ExceptionCreateRandomAddress e -> toServerError e
ExceptionImportRandomAddress e -> toServerError e
ExceptionNotASequentialWallet e -> toServerError e
ExceptionReadRewardAccount e -> toServerError e
ExceptionWithdrawalNotWorth e -> toServerError e
ExceptionReadPolicyPublicKey e -> toServerError e
ExceptionWritePolicyPublicKey e -> toServerError e
ExceptionSoftDerivationIndex e -> toServerError e
ExceptionHardenedDerivationIndex e -> toServerError e

instance IsServerError ErrNoSuchWallet where
toServerError = \case
ErrNoSuchWallet wid ->
Expand Down Expand Up @@ -447,18 +486,7 @@ instance IsServerError ErrBalanceTx where
, "one or more zero-ada outputs. In the future I might be able"
, "to increase the values to the minimum allowed ada value."
]
ErrBalanceTxInternalError (ErrFailedBalancing v) ->
apiError err500 BalanceTxInternalError $ T.unwords
[ "I have somehow failed to balance the transaction."
, "The balance is"
, T.pack (show v)
]
ErrBalanceTxInternalError (ErrUnderestimatedFee c _) ->
apiError err500 BalanceTxUnderestimatedFee $ T.unwords
[ "I have somehow underestimated the fee of the transaction by"
, pretty c
, "and cannot finish balancing."
]
ErrBalanceTxInternalError e -> toServerError e
ErrBalanceTxMaxSizeLimitExceeded ->
apiError err403 BalanceTxMaxSizeLimitExceeded $ T.unwords
[ "I was not able to balance the transaction without exceeding"
Expand All @@ -481,6 +509,21 @@ instance IsServerError ErrBalanceTx where
, fmt $ blockListF' "-" conflictF conflicts
]

instance IsServerError ErrBalanceTxInternalError where
toServerError = \case
ErrUnderestimatedFee coin _st ->
apiError err500 BalanceTxUnderestimatedFee $ T.unwords
[ "I have somehow underestimated the fee of the transaction by"
, pretty coin
, "and cannot finish balancing."
]
ErrFailedBalancing v ->
apiError err500 BalanceTxInternalError $ T.unwords
[ "I have somehow failed to balance the transaction."
, "The balance is"
, T.pack (show v)
]

instance IsServerError ErrRemoveTx where
toServerError = \case
ErrRemoveTxNoSuchWallet wid -> toServerError wid
Expand Down

This file was deleted.

Loading