Skip to content

Commit

Permalink
Merge #3332
Browse files Browse the repository at this point in the history
3332: move db checkpoints modules into their own namespace r=paolino a=paolino



- I have moved CheckpointsOld Checkpoints and Addressbook into Checkpoints namespace


### Issue Number

ADP-1784


Co-authored-by: Paolo Veronelli <[email protected]>
Co-authored-by: paolo veronelli <[email protected]>
  • Loading branch information
3 people authored Jun 20, 2022
2 parents 0cdd1b7 + df5cc8a commit 69ce334
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ lib/shelley/test/data/balanceTx/**/actual

## local ignored space
ignore-me
ignore-us
6 changes: 3 additions & 3 deletions lib/core/cardano-wallet-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ library
Cardano.Pool.Rank
Cardano.Pool.Rank.Likelihood
Cardano.Wallet
Cardano.Wallet.Address.Book
Cardano.Wallet.Address.Pool
Cardano.Wallet.Api
Cardano.Wallet.Api.Aeson.Variant
Expand All @@ -191,23 +192,22 @@ library
Cardano.Wallet.Api.Types
Cardano.Wallet.Api.Types.SchemaMetadata
Cardano.Wallet.Checkpoints.Policy
Cardano.Wallet.Checkpoints
Cardano.Wallet.CoinSelection
Cardano.Wallet.CoinSelection.Internal
Cardano.Wallet.CoinSelection.Internal.Balance
Cardano.Wallet.CoinSelection.Internal.Collateral
Cardano.Wallet.CoinSelection.Internal.Context
Cardano.Wallet.Compat
Cardano.Wallet.DB
Cardano.Wallet.DB.Checkpoints
Cardano.Wallet.DB.Pure.Implementation
Cardano.Wallet.DB.Pure.Layer
Cardano.Wallet.DB.Sqlite.AddressBook
Cardano.Wallet.DB.Sqlite.CheckpointsOld
Cardano.Wallet.DB.Layer
Cardano.Wallet.DB.Sqlite.Migration
Cardano.Wallet.DB.Sqlite.Schema
Cardano.Wallet.DB.Sqlite.Stores
Cardano.Wallet.DB.Sqlite.Types
Cardano.Wallet.DB.Store.Checkpoints
Cardano.Wallet.DB.WalletState
Cardano.Wallet.Logging
Cardano.Wallet.Network
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ import Cardano.Crypto.Wallet
( toXPub )
import Cardano.Slotting.Slot
( SlotNo (..) )
import Cardano.Wallet.Address.Book
( AddressBookIso, Prologue (..), getPrologue )
import Cardano.Wallet.Checkpoints
( DeltaCheckpoints (..) )
import Cardano.Wallet.CoinSelection
( Selection
, SelectionBalanceError (..)
Expand Down Expand Up @@ -259,10 +263,6 @@ import Cardano.Wallet.DB
, defaultSparseCheckpointsConfig
, sparseCheckpoints
)
import Cardano.Wallet.DB.Checkpoints
( DeltaCheckpoints (..) )
import Cardano.Wallet.DB.Sqlite.AddressBook
( AddressBookIso, Prologue (..), getPrologue )
import Cardano.Wallet.DB.WalletState
( DeltaMap (..), DeltaWalletState1 (..), fromWallet, getLatest, getSlot )
import Cardano.Wallet.Logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
--
-- Address books consist of a 'Prologue'
-- and discovered addresses ('Discoveries').
module Cardano.Wallet.DB.Sqlite.AddressBook
module Cardano.Wallet.Address.Book
( AddressBookIso (..)
, Prologue (..)
, Discoveries (..)
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ import Cardano.Wallet
, manageRewardBalance
, networkLayer
)
import Cardano.Wallet.Address.Book
( AddressBookIso )
import Cardano.Wallet.Api
( ApiLayer (..)
, HasDBFactory
Expand Down Expand Up @@ -352,8 +354,6 @@ import Cardano.Wallet.Compat
( (^?) )
import Cardano.Wallet.DB
( DBFactory (..) )
import Cardano.Wallet.DB.Sqlite.AddressBook
( AddressBookIso )
import Cardano.Wallet.Network
( NetworkLayer, fetchRewardAccountBalances, timeInterpreter )
import Cardano.Wallet.Primitive.AddressDerivation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-- Data type that represents a collection of checkpoints.
-- Each checkpoints is associated with a 'Slot'.

module Cardano.Wallet.DB.Checkpoints
module Cardano.Wallet.Checkpoints
( -- * Checkpoints
Checkpoints
, checkpoints
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/Cardano/Wallet/DB/Layer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ import Cardano.DB.Sqlite.Delete
, waitForFree
, withRef
)
import Cardano.Wallet.Checkpoints
( DeltaCheckpoints (..) )
import Cardano.Wallet.DB
( DBFactory (..)
, DBLayer (..)
Expand All @@ -88,10 +90,6 @@ import Cardano.Wallet.DB
, defaultSparseCheckpointsConfig
, sparseCheckpoints
)
import Cardano.Wallet.DB.Checkpoints
( DeltaCheckpoints (..) )
import Cardano.Wallet.DB.Sqlite.CheckpointsOld
( PersistAddressBook (..), blockHeaderFromEntity, mkStoreWallets )
import Cardano.Wallet.DB.Sqlite.Migration
( DefaultFieldValues (..), migrateManually )
import Cardano.Wallet.DB.Sqlite.Schema
Expand All @@ -116,6 +114,8 @@ import Cardano.Wallet.DB.Sqlite.Schema
)
import Cardano.Wallet.DB.Sqlite.Types
( BlockId (..), TxId (..) )
import Cardano.Wallet.DB.Store.Checkpoints
( PersistAddressBook (..), blockHeaderFromEntity, mkStoreWallets )
import Cardano.Wallet.DB.WalletState
( DeltaMap (..)
, DeltaWalletState1 (..)
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/DB/Sqlite/Stores.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ module Cardano.Wallet.DB.Sqlite.Stores
)
where

import Cardano.Wallet.DB.Sqlite.CheckpointsOld
import Cardano.Wallet.DB.Store.Checkpoints
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
-- * Inline the contents of this module into its new name
-- "Cardano.Wallet.DB.Sqlite.Stores"

module Cardano.Wallet.DB.Sqlite.CheckpointsOld
module Cardano.Wallet.DB.Store.Checkpoints
( mkStoreWallets
, PersistAddressBook (..)
, blockHeaderFromEntity
Expand All @@ -45,16 +45,16 @@ import Cardano.Address.Script
( Cosigner (..), ScriptTemplate (..) )
import Cardano.DB.Sqlite
( dbChunked )
import Cardano.Wallet.DB
( ErrBadFormat (..) )
import Cardano.Wallet.DB.Checkpoints
( DeltaCheckpoints (..), loadCheckpoints )
import Cardano.Wallet.DB.Sqlite.AddressBook
import Cardano.Wallet.Address.Book
( AddressBookIso (..)
, Discoveries (..)
, Prologue (..)
, SeqAddressMap (..)
)
import Cardano.Wallet.Checkpoints
( DeltaCheckpoints (..), loadCheckpoints )
import Cardano.Wallet.DB
( ErrBadFormat (..) )
import Cardano.Wallet.DB.Sqlite.Schema
( Checkpoint (..)
, CosignerKey (..)
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/Cardano/Wallet/DB/WalletState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ module Cardano.Wallet.DB.WalletState

import Prelude

import Cardano.Wallet.DB.Checkpoints
( Checkpoints )
import Cardano.Wallet.DB.Sqlite.AddressBook
import Cardano.Wallet.Address.Book
( AddressBookIso (..), Discoveries, Prologue )
import Cardano.Wallet.Checkpoints
( Checkpoints )
import Cardano.Wallet.Primitive.Types
( BlockHeader )
import Cardano.Wallet.Primitive.Types.UTxO
Expand All @@ -59,7 +59,7 @@ import Fmt
import GHC.Generics
( Generic )

import qualified Cardano.Wallet.DB.Checkpoints as CPS
import qualified Cardano.Wallet.Checkpoints as CPS
import qualified Cardano.Wallet.Primitive.Model as W
import qualified Cardano.Wallet.Primitive.Types as W

Expand Down
4 changes: 2 additions & 2 deletions lib/core/test/unit/Cardano/Wallet/DB/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ import Cardano.Crypto.Wallet
( unXPrv )
import Cardano.Mnemonic
( SomeMnemonic (..) )
import Cardano.Wallet.Address.Book
( AddressBookIso (..) )
import Cardano.Wallet.DB.Pure.Implementation
( TxHistory, filterTxHistory )
import Cardano.Wallet.DB.Sqlite.AddressBook
( AddressBookIso (..) )
import Cardano.Wallet.DummyTarget.Primitive.Types as DummyTarget
( block0, mkTx )
import Cardano.Wallet.Gen
Expand Down
12 changes: 6 additions & 6 deletions lib/core/test/unit/Cardano/Wallet/DB/Sqlite/StoresSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import Prelude

import Cardano.DB.Sqlite
( SqliteContext (runQuery), newInMemorySqliteContext )
import Cardano.Wallet.Address.Book
( AddressBookIso (..), Prologue, getPrologue )
import Cardano.Wallet.Checkpoints
( DeltaCheckpoints (..) )
import Cardano.Wallet.DB.Arbitrary
( GenState, InitialCheckpoint (..) )
import Cardano.Wallet.DB.Checkpoints
( DeltaCheckpoints (..) )
import Cardano.Wallet.DB.Sqlite.AddressBook
( AddressBookIso (..), Prologue, getPrologue )
import Cardano.Wallet.DB.Sqlite.Schema
( Wallet (..), migrateAll )
import Cardano.Wallet.DB.Sqlite.Stores
Expand Down Expand Up @@ -102,7 +102,7 @@ spec = around withDBInMemory $ do

it "loadPrologue . insertPrologue = id for RndState" $
property . prop_prologue_load_write @(RndState 'Mainnet) id

it "loadPrologue . insertPrologue = id for SharedState" $
property . prop_prologue_load_write @(SharedState 'Mainnet SharedKey)
(\s -> s { ready = Pending })
Expand Down Expand Up @@ -194,7 +194,7 @@ genDeltaWalletState wallet = frequency . map (second updateCheckpoints) $
slot <- genSlotNo
cp <- over (#currentTip . #slotNo) (const slot) <$> arbitrary
pure $ PutCheckpoint (At slot) (snd $ fromWallet cp)

genFilteredSlots = do
let slots = Map.keys $ wallet ^. (#checkpoints . #checkpoints)
keeps <- vectorOf (length slots) arbitrary
Expand Down
14 changes: 7 additions & 7 deletions lib/core/test/unit/Cardano/WalletSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ import UnliftIO.Concurrent

import qualified Cardano.Crypto.Wallet as CC
import qualified Cardano.Wallet as W
import qualified Cardano.Wallet.Address.Book as Sqlite
import qualified Cardano.Wallet.DB.Layer as Sqlite
import qualified Cardano.Wallet.DB.Pure.Layer as PureLayer
import qualified Cardano.Wallet.DB.Sqlite.AddressBook as Sqlite
import qualified Cardano.Wallet.Primitive.Migration as Migration
import qualified Cardano.Wallet.Primitive.Types.Coin as Coin
import qualified Cardano.Wallet.Primitive.Types.TokenBundle as TokenBundle
Expand Down Expand Up @@ -568,14 +568,14 @@ walletUpdatePassphrase wallet new mxprv = monadicIO $ do
Just (xprv, pwd) -> prop_withPrivateKey wl wid (xprv, pwd)
where
prop_withoutPrivateKey wl wid = do
attempt <- run $ runExceptT
attempt <- run $ runExceptT
$ W.updateWalletPassphraseWithOldPassphrase wl wid (new, new)
let err = ErrUpdatePassphraseWithRootKey $ ErrWithRootKeyNoRootKey wid
assert (attempt == Left err)

prop_withPrivateKey wl wid (xprv, pwd) = do
run $ unsafeRunExceptT $ W.attachPrivateKeyFromPwd wl wid (xprv, pwd)
attempt <- run $ runExceptT
attempt <- run $ runExceptT
$ W.updateWalletPassphraseWithOldPassphrase wl wid (coerce pwd, new)
assert (attempt == Right ())

Expand All @@ -589,7 +589,7 @@ walletUpdatePassphraseWrong wallet (xprv, pwd) (old, new) =
WalletLayerFixture _ wl [wid] _ <- run $ setupFixture wallet
attempt <- run $ do
unsafeRunExceptT $ W.attachPrivateKeyFromPwd wl wid (xprv, pwd)
runExceptT
runExceptT
$ W.updateWalletPassphraseWithOldPassphrase wl wid (old, new)
let err = ErrUpdatePassphraseWithRootKey
$ ErrWithRootKeyWrongPassphrase wid
Expand All @@ -604,7 +604,7 @@ walletUpdatePassphraseNoSuchWallet
walletUpdatePassphraseNoSuchWallet wallet@(wid', _, _) wid (old, new) =
wid /= wid' ==> monadicIO $ do
WalletLayerFixture _ wl _ _ <- run $ setupFixture wallet
attempt <- run $ runExceptT
attempt <- run $ runExceptT
$ W.updateWalletPassphraseWithOldPassphrase wl wid (old, new)
let err = ErrUpdatePassphraseWithRootKey $ ErrWithRootKeyNoRootKey wid
assert (attempt == Left err)
Expand All @@ -625,8 +625,8 @@ walletUpdatePassphraseDate wallet (xprv, pwd) = monadicIO $ liftIO $ do
unsafeRunExceptT $ W.attachPrivateKeyFromPwd wl wid (xprv, pwd)
info <- infoShouldSatisfy isJust
pause
unsafeRunExceptT
$ W.updateWalletPassphraseWithOldPassphrase wl wid
unsafeRunExceptT
$ W.updateWalletPassphraseWithOldPassphrase wl wid
(coerce pwd, coerce pwd)
void $ infoShouldSatisfy (\info' -> isJust info' && info' > info)
where
Expand Down
4 changes: 2 additions & 2 deletions lib/shelley/src/Cardano/Wallet/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import Cardano.Wallet.Api.Types
, EncodeAddress
, EncodeStakeAddress
)
import Cardano.Wallet.DB.Sqlite.CheckpointsOld
( PersistAddressBook )
import Cardano.Wallet.DB.Sqlite.Migration
( DefaultFieldValues (..) )
import Cardano.Wallet.DB.Store.Checkpoints
( PersistAddressBook )
import Cardano.Wallet.Network
( NetworkLayer (..) )
import Cardano.Wallet.Primitive.AddressDerivation
Expand Down
6 changes: 3 additions & 3 deletions nix/materialized/stack-nix/cardano-wallet-core.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 69ce334

Please sign in to comment.