Skip to content

Commit

Permalink
Remove isStakeKeyRegistered from DBLayer.
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed May 30, 2023
1 parent 3f32b71 commit 303f6bd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
16 changes: 15 additions & 1 deletion lib/wallet/src/Cardano/Wallet.hs
Expand Up @@ -108,6 +108,7 @@ module Cardano.Wallet
, ErrWritePolicyPublicKey (..)
, ErrGetPolicyId (..)
, readWalletMeta
, isStakeKeyRegistered

-- * Shared Wallet
, updateCosigner
Expand Down Expand Up @@ -640,6 +641,7 @@ import qualified Cardano.Wallet.Address.Discovery.Random as Rnd
import qualified Cardano.Wallet.Address.Discovery.Sequential as Seq
import qualified Cardano.Wallet.Address.Discovery.Shared as Shared
import qualified Cardano.Wallet.Checkpoints.Policy as CP
import qualified Cardano.Wallet.DB.Store.Delegations.Layer as Dlgs
import qualified Cardano.Wallet.DB.Store.Submissions.Layer as Submissions
import qualified Cardano.Wallet.DB.WalletState as WS
import qualified Cardano.Wallet.DB.WalletState as WalletState
Expand Down Expand Up @@ -2768,6 +2770,14 @@ data DelegationFee = DelegationFee

instance NFData DelegationFee

isStakeKeyRegistered
:: Functor stm
=> DBVar stm (DeltaWalletState s)
-> stm Bool
isStakeKeyRegistered walletState =
Dlgs.isStakeKeyRegistered . view #delegations
<$> readDBVar walletState

delegationFee
:: forall s
. ( AddressBookIso s
Expand All @@ -2794,13 +2804,17 @@ delegationFee db@DBLayer{..} netLayer txLayer timeTranslation era
-- previously, and the difference should be negligible.
(PreSelection [])
deposit <- liftIO
$ atomically isStakeKeyRegistered <&> \case
$ atomically (isStakeKeyRegistered walletState) <&> \case
False -> toWallet
$ Write.stakeKeyDeposit recentEra
$ Write.pparamsLedger protocolParams
True -> Coin 0
pure DelegationFee { feePercentiles, deposit }





transactionFee
:: forall s era
. ( AddressBookIso s
Expand Down
3 changes: 0 additions & 3 deletions lib/wallet/src/Cardano/Wallet/DB.hs
Expand Up @@ -230,8 +230,6 @@ data DBLayer m s = forall stm. (MonadIO stm, MonadFail stm) => DBLayer

, readDelegation :: stm WalletDelegation

, isStakeKeyRegistered :: stm Bool

, putDelegationCertificate
:: DelegationCertificate
-> SlotNo
Expand Down Expand Up @@ -412,7 +410,6 @@ mkDBLayerFromParts ti wid_ DBLayerCollection{..} = DBLayer
currentEpoch <- liftIO $
interpretQuery ti (epochOf $ cp ^. #currentTip . #slotNo)
readDelegation_ dbDelegation currentEpoch
, isStakeKeyRegistered = isStakeKeyRegistered_ dbDelegation
, putDelegationCertificate = putDelegationCertificate_ dbDelegation
, putDelegationRewardBalance = putDelegationRewardBalance_ dbDelegation
, readDelegationRewardBalance = readDelegationRewardBalance_ dbDelegation
Expand Down
3 changes: 0 additions & 3 deletions lib/wallet/src/Cardano/Wallet/DB/Pure/Layer.hs
Expand Up @@ -28,7 +28,6 @@ import Cardano.Wallet.DB.Pure.Implementation
, Err (..)
, ModelOp
, mInitializeWallet
, mIsStakeKeyRegistered
, mListCheckpoints
, mPutCheckpoint
, mPutDelegationCertificate
Expand Down Expand Up @@ -124,8 +123,6 @@ newDBFresh timeInterpreter wid = do
, putDelegationCertificate = \cert sl -> noErrorAlterDB db $
mPutDelegationCertificate cert sl

, isStakeKeyRegistered = throwErrorReadDB db mIsStakeKeyRegistered

{-----------------------------------------------------------------------
Tx History
-----------------------------------------------------------------------}
Expand Down
3 changes: 2 additions & 1 deletion lib/wallet/src/Cardano/Wallet/Delegation.hs
Expand Up @@ -33,6 +33,7 @@ import Cardano.Wallet
, WalletException (..)
, WalletLog (..)
, fetchRewardBalance
, isStakeKeyRegistered
, readRewardAccount
, transactionExpirySlot
)
Expand Down Expand Up @@ -122,7 +123,7 @@ joinStakePoolDelegationAction
(walletDelegation, stakeKeyIsRegistered) <-
atomically $
(,) <$> readDelegation
<*> isStakeKeyRegistered
<*> isStakeKeyRegistered walletState

let retirementInfo =
PoolRetirementEpochInfo currentEpoch . view #retirementEpoch <$>
Expand Down
8 changes: 0 additions & 8 deletions lib/wallet/test/unit/Cardano/Wallet/DB/StateMachine.hs
Expand Up @@ -86,7 +86,6 @@ import Cardano.Wallet.DB.Pure.Implementation
, TxHistory
, WalletDatabase (..)
, mInitializeWallet
, mIsStakeKeyRegistered
, mListCheckpoints
, mPutCheckpoint
, mPutDelegationCertificate
Expand Down Expand Up @@ -302,7 +301,6 @@ data Cmd s wid
| ReadGenesisParameters
| RollbackTo wid Slot
| PutDelegationCertificate DelegationCertificate SlotNo
| IsStakeKeyRegistered wid
| PutDelegationRewardBalance wid Coin
| ReadDelegationRewardBalance
deriving stock (Show, Generic1, Eq, Functor, Foldable, Traversable)
Expand Down Expand Up @@ -352,8 +350,6 @@ runMock = \case
first (Resp . fmap Checkpoint) . mReadCheckpoint
PutDelegationCertificate cert sl ->
first (Resp . fmap Unit) . mPutDelegationCertificate cert sl
IsStakeKeyRegistered _wid ->
first (Resp . fmap StakeKeyStatus) . mIsStakeKeyRegistered
PutTxHistory txs ->
first (Resp . fmap Unit) . mPutTxHistory txs
ReadTxHistory minW order range status ->
Expand Down Expand Up @@ -411,8 +407,6 @@ runIO DBLayer{..} = fmap Resp . go
atomically listCheckpoints
PutDelegationCertificate pool sl ->
runDBSuccess atomically Unit $ putDelegationCertificate pool sl
IsStakeKeyRegistered _wid ->
runDBSuccess atomically StakeKeyStatus isStakeKeyRegistered
PutTxHistory txs -> runDBSuccess atomically Unit $ putTxHistory txs
ReadTxHistory minWith order range status ->
fmap (Right . TxHistory) $
Expand Down Expand Up @@ -544,8 +538,6 @@ generatorWithWid wids =
$ pure ListCheckpoints
, declareGenerator "PutDelegationCertificate" 5
$ PutDelegationCertificate <$> arbitrary <*> arbitrary
, declareGenerator "IsStakeKeyRegistered" 1
$ IsStakeKeyRegistered <$> genId
, declareGenerator "PutTxHistory" 5
$ PutTxHistory <$> fmap unGenTxHistory arbitrary
, declareGenerator "ReadTxHistory" 5
Expand Down

0 comments on commit 303f6bd

Please sign in to comment.