Skip to content

Commit

Permalink
adjusting to Heinrich refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Mar 1, 2024
1 parent 2ef2840 commit bcdbdf5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
18 changes: 9 additions & 9 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ import qualified Cardano.Wallet.Api.Types.Amount as ApiAmount
import qualified Cardano.Wallet.Api.Types.WalletAssets as ApiWalletAssets
import qualified Cardano.Wallet.DB as W
import qualified Cardano.Wallet.Delegation as WD
import qualified Cardano.Wallet.IO.Delegation
import qualified Cardano.Wallet.IO.Delegation as IODeleg
import qualified Cardano.Wallet.Network as NW
import qualified Cardano.Wallet.Primitive.Ledger.Convert as Convert
import qualified Cardano.Wallet.Primitive.Types as W
Expand Down Expand Up @@ -2144,7 +2144,7 @@ selectCoinsForJoin ctx knownPools getPoolStatus poolId walletId = do
poolStatus <- liftIO $ getPoolStatus poolId
pools <- liftIO knownPools
withWorkerCtx ctx walletId liftE liftE $ \workerCtx -> liftIO $ do
W.CoinSelection{..} <- Cardano.Wallet.IO.Delegation.selectCoinsForJoin
W.CoinSelection{..} <- IODeleg.selectCoinsForJoin
workerCtx
pools
poolId
Expand Down Expand Up @@ -2177,7 +2177,7 @@ selectCoinsForQuit
selectCoinsForQuit ctx (ApiT walletId) = do
withWorkerCtx ctx walletId liftE liftE $ \workerCtx -> liftIO $ do
W.CoinSelection{..} <-
Cardano.Wallet.IO.Delegation.selectCoinsForQuit workerCtx
IODeleg.selectCoinsForQuit workerCtx
pure ApiCoinSelection
{ inputs = mkApiCoinSelectionInput <$> inputs
, outputs = mkApiCoinSelectionOutput <$> outputs
Expand Down Expand Up @@ -2736,15 +2736,15 @@ constructTransaction api argGenChange knownPools poolStatus apiWalletId body = d
currentEpochSlotting <- liftIO $ getCurrentEpochSlotting netLayer
optionalDelegationAction <- liftIO $
forM delegationRequest $
Cardano.Wallet.IO.Delegation.handleDelegationRequest
IODeleg.handleDelegationRequest
wrk
currentEpochSlotting knownPools
poolStatus withdrawal

optionalVoteAction <- case (body ^. #vote) of
Just (ApiT action) ->
liftIO $ Just <$>
Cardano.Wallet.IO.Delegation.voteAction wrk action
IODeleg.voteAction wrk action
Nothing ->
pure Nothing

Expand Down Expand Up @@ -3286,13 +3286,13 @@ constructSharedTransaction

optionalDelegationAction <- liftIO $
forM delegationRequest $
Cardano.Wallet.IO.Delegation.handleDelegationRequest
IODeleg.handleDelegationRequest
wrk currentEpochSlotting knownPools
getPoolStatus NoWithdrawal

optionalVoteAction <- case (body ^. #vote) of
Just (ApiT action) -> liftIO $ Just <$>
Cardano.Wallet.IO.Delegation.voteAction wrk action
IODeleg.voteAction wrk action
Nothing -> pure Nothing

let txCtx = defaultTransactionCtx
Expand Down Expand Up @@ -3961,7 +3961,7 @@ joinStakePool

withWorkerCtx ctx walletId liftE liftE $ \wrk -> do
(BuiltTx{..}, txTime) <- liftIO
$ Cardano.Wallet.IO.Delegation.joinStakePool
$ IODeleg.joinStakePool
wrk
walletId
pools
Expand Down Expand Up @@ -4025,7 +4025,7 @@ quitStakePool ctx@ApiLayer{..} (ApiT walletId) body = do

withWorkerCtx ctx walletId liftE liftE $ \wrk -> do
(BuiltTx{..}, txTime) <- liftIO
$ Cardano.Wallet.IO.Delegation.quitStakePool
$ IODeleg.quitStakePool
wrk
walletId
(coerce $ getApiT $ body ^. #passphrase)
Expand Down
23 changes: 15 additions & 8 deletions lib/wallet/src/Cardano/Wallet/Delegation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import Cardano.Wallet.Primitive.Types
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
import Cardano.Wallet.Primitive.Types.DRep
( DRep (..)
)
import Cardano.Wallet.Transaction
( ErrCannotJoin (..)
, Withdrawal (..)
Expand Down Expand Up @@ -81,15 +84,18 @@ joinStakePoolDelegationAction
-> Set PoolId
-> PoolId
-> PoolLifeCycleStatus
-> Either ErrStakePoolDelegation Tx.DelegationAction
-> Bool
-> Either ErrStakePoolDelegation (Tx.DelegationAction, Maybe Tx.VotingAction)
joinStakePoolDelegationAction
wallet currentEpochSlotting knownPools poolId poolStatus
wallet currentEpochSlotting knownPools poolId poolStatus inConway
= case guardJoin knownPools delegation poolId retirementInfo of
Left e -> Left $ ErrStakePoolJoin e
Right () -> Right $
if stakeKeyIsRegistered
then Tx.Join poolId
else Tx.JoinRegisteringKey poolId
Right () ->
Right $ case (inConway, stakeKeyIsRegistered) of
(False, True) -> (Tx.Join poolId, Nothing)
(False, False) -> (Tx.JoinRegisteringKey poolId, Nothing)
(True, True) -> (Tx.Join poolId, Just $ Tx.Vote Abstain)
(True, False) -> (Tx.JoinRegisteringKey poolId, Just $ Tx.Vote Abstain)
where
stakeKeyIsRegistered =
Dlgs.isStakeKeyRegistered
Expand Down Expand Up @@ -136,9 +142,10 @@ quitStakePoolDelegationAction
-- ^ Reward balance of the wallet
-> CurrentEpochSlotting
-> Withdrawal
-> Bool
-> Either ErrStakePoolDelegation Tx.DelegationAction
quitStakePoolDelegationAction wallet rewards currentEpochSlotting withdrawal =
case guardQuit delegation withdrawal rewards of
quitStakePoolDelegationAction wallet rewards currentEpochSlotting withdrawal voting =
case guardQuit delegation withdrawal rewards voting of
Left e -> Left $ ErrStakePoolQuit e
Right () -> Right Tx.Quit
where
Expand Down
27 changes: 15 additions & 12 deletions lib/wallet/src/Cardano/Wallet/IO/Delegation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ handleDelegationRequest
WD.Join poolId -> do
poolStatus <- getPoolStatus poolId
pools <- getKnownPools
joinStakePoolDelegationAction
fst <$> joinStakePoolDelegationAction
ctx
currentEpochSlotting
pools
Expand Down Expand Up @@ -199,17 +199,12 @@ selectCoinsForJoin ctx pools poolId poolStatus = do
<- W.readNodeTipStateForTxWrite netLayer
currentEpochSlotting <- W.getCurrentEpochSlotting netLayer

inConway <- case W.votingEnabledInEra era of
Left _ -> pure False
Right _ -> pure True

action <- joinStakePoolDelegationAction
(action, _) <- joinStakePoolDelegationAction
ctx
currentEpochSlotting
pools
poolId
poolStatus
inConway

let changeAddrGen = W.defaultChangeAddressGen (delegationAddressS @n)

Expand Down Expand Up @@ -298,7 +293,7 @@ joinStakePoolDelegationAction
-> Set PoolId
-> PoolId
-> PoolLifeCycleStatus
-> IO Tx.DelegationAction
-> IO (Tx.DelegationAction, Maybe Tx.VotingAction)
joinStakePoolDelegationAction
ctx currentEpochSlotting knownPools poolId poolStatus
= do
Expand All @@ -310,16 +305,25 @@ joinStakePoolDelegationAction
traceWith tr
$ W.MsgWallet $ W.MsgIsStakeKeyRegistered stakeKeyIsRegistered

(Write.PParamsInAnyRecentEra era _, _)
<- W.readNodeTipStateForTxWrite netLayer

inConway <- case W.votingEnabledInEra era of
Left _ -> pure False
Right _ -> pure True

either (throwIO . ExceptionStakePoolDelegation) pure
$ WD.joinStakePoolDelegationAction
wallet
currentEpochSlotting
knownPools
poolId
poolStatus
inConway
where
db = ctx ^. dbLayer
tr = ctx ^. logger
netLayer = ctx ^. networkLayer

-- | Send a transaction to the network where we join a stake pool.
joinStakePool
Expand All @@ -343,18 +347,15 @@ joinStakePool
-> IO (W.BuiltTx, UTCTime)
joinStakePool ctx wid pools poolId poolStatus passphrase = do
pp <- currentProtocolParameters netLayer
(Write.PParamsInAnyRecentEra era _, _)
<- W.readNodeTipStateForTxWrite netLayer
currentEpochSlotting <- W.getCurrentEpochSlotting netLayer

action <-
(action, _) <-
joinStakePoolDelegationAction
ctx
currentEpochSlotting
pools
poolId
poolStatus
inConway

ttl <- W.transactionExpirySlot ti Nothing
let transactionCtx =
Expand Down Expand Up @@ -393,12 +394,14 @@ quitStakePoolDelegationAction ctx currentEpochSlotting withdrawal = do
wallet <- db & \DBLayer{atomically,walletState} ->
atomically $ readDBVar walletState
rewards <- W.fetchRewardBalance db
voting <- W.haveWeVoted db
either (throwIO . ExceptionStakePoolDelegation) pure
$ WD.quitStakePoolDelegationAction
wallet
rewards
currentEpochSlotting
withdrawal
voting
where
db = ctx ^. dbLayer

Expand Down

0 comments on commit bcdbdf5

Please sign in to comment.