Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
An implementation of the wallet database using only pure functions.
These functions and types model the behaviour of the SQLite database backend, and are used for QuickCheck state machine testing, and the MVar database backend.
Synopsis
- data Database wid s xprv = Database { }
-
data
WalletDatabase
s xprv =
WalletDatabase
{
- checkpoints :: !( Map SlotNo ( Wallet s))
- certificates :: !( Map SlotNo ( Maybe PoolId ))
- stakeKeys :: !( Map SlotNo StakeKeyCertificate )
- metadata :: ! WalletMetadata
- txHistory :: !( Map ( Hash "Tx") TxMeta )
- xprv :: !( Maybe xprv)
- genesisParameters :: ! GenesisParameters
- rewardAccountBalance :: ! Coin
- submittedTxs :: !( Map ( Hash "Tx") ( SealedTx , SlotNo ))
- emptyDatabase :: Ord wid => Database wid s xprv
- type TxHistory = [( Tx , TxMeta )]
- type TxHistoryMap = Map ( Hash "Tx") ( Tx , TxMeta )
- filterTxHistory :: Maybe Coin -> SortOrder -> Range SlotNo -> TxHistory -> TxHistory
- type ModelOp wid s xprv a = Database wid s xprv -> ( Either ( Err wid) a, Database wid s xprv)
-
data
Err
wid
- = NoSuchWallet wid
- | WalletAlreadyExists wid
- | NoSuchTx wid ( Hash "Tx")
- | CantRemoveTxInLedger wid ( Hash "Tx")
- mCleanDB :: Ord wid => ModelOp wid s xprv ()
- mInitializeWallet :: forall wid s xprv. Ord wid => wid -> Wallet s -> WalletMetadata -> TxHistory -> GenesisParameters -> ModelOp wid s xprv ()
- mRemoveWallet :: Ord wid => wid -> ModelOp wid s xprv ()
- mListWallets :: Ord wid => ModelOp wid s xprv [wid]
- mPutCheckpoint :: Ord wid => wid -> Wallet s -> ModelOp wid s xprv ()
- mReadCheckpoint :: Ord wid => wid -> ModelOp wid s xprv ( Maybe ( Wallet s))
- mListCheckpoints :: Ord wid => wid -> ModelOp wid s xprv [ ChainPoint ]
- mRollbackTo :: Ord wid => wid -> Slot -> ModelOp wid s xprv ChainPoint
- mPutWalletMeta :: Ord wid => wid -> WalletMetadata -> ModelOp wid s xprv ()
- mReadWalletMeta :: Ord wid => TimeInterpreter Identity -> wid -> ModelOp wid s xprv ( Maybe WalletMetadata )
- mPutDelegationCertificate :: Ord wid => wid -> DelegationCertificate -> SlotNo -> ModelOp wid s xprv ()
- mIsStakeKeyRegistered :: Ord wid => wid -> ModelOp wid s xprv Bool
- mPutTxHistory :: forall wid s xprv. Ord wid => wid -> TxHistory -> ModelOp wid s xprv ()
- mReadTxHistory :: forall wid s xprv. Ord wid => TimeInterpreter Identity -> wid -> Maybe Coin -> SortOrder -> Range SlotNo -> Maybe TxStatus -> ModelOp wid s xprv [ TransactionInfo ]
- mPutLocalTxSubmission :: Ord wid => wid -> Hash "Tx" -> SealedTx -> SlotNo -> ModelOp wid s xprv ()
- mReadLocalTxSubmissionPending :: Ord wid => wid -> ModelOp wid s xprv [ LocalTxSubmissionStatus SealedTx ]
- mUpdatePendingTxForExpiry :: Ord wid => wid -> SlotNo -> ModelOp wid s xprv ()
- mRemovePendingOrExpiredTx :: Ord wid => wid -> Hash "Tx" -> ModelOp wid s xprv ()
- mPutPrivateKey :: Ord wid => wid -> xprv -> ModelOp wid s xprv ()
- mReadPrivateKey :: Ord wid => wid -> ModelOp wid s xprv ( Maybe xprv)
- mReadGenesisParameters :: Ord wid => wid -> ModelOp wid s xprv ( Maybe GenesisParameters )
- mPutDelegationRewardBalance :: Ord wid => wid -> Coin -> ModelOp wid s xprv ()
- mReadDelegationRewardBalance :: Ord wid => wid -> ModelOp wid s xprv Coin
- mCheckWallet :: Ord wid => wid -> ModelOp wid s xprv ()
Model Types
data Database wid s xprv Source #
Model database, parameterised by the wallet ID type, the wallet AD state type, the target backend, and the private key type.
Tne type parameters exist so that simpler mock types can be used in place of actual wallet types.
Instances
( Eq wid, Eq xprv, Eq s) => Eq ( Database wid s xprv) Source # | |
( Show wid, Show s, Show xprv) => Show ( Database wid s xprv) Source # | |
Generic ( Database wid s xprv) Source # | |
( NFData wid, NFData s, NFData xprv) => NFData ( Database wid s xprv) Source # | |
Defined in Cardano.Wallet.DB.Pure.Implementation |
|
type Rep ( Database wid s xprv) Source # | |
Defined in Cardano.Wallet.DB.Pure.Implementation
type
Rep
(
Database
wid s xprv) =
D1
('
MetaData
"Database" "Cardano.Wallet.DB.Pure.Implementation" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" '
False
) (
C1
('
MetaCons
"Database" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"wallets") '
NoSourceUnpackedness
'
SourceStrict
'
DecidedStrict
) (
Rec0
(
Map
wid (
WalletDatabase
s xprv)))
:*:
S1
('
MetaSel
('
Just
"txs") '
NoSourceUnpackedness
'
SourceStrict
'
DecidedStrict
) (
Rec0
(
Map
(
Hash
"Tx")
Tx
))))
|
data WalletDatabase s xprv Source #
Model database record for a single wallet.
WalletDatabase | |
|
Instances
emptyDatabase :: Ord wid => Database wid s xprv Source #
Produces an empty model database.
type TxHistoryMap = Map ( Hash "Tx") ( Tx , TxMeta ) Source #
Shorthand for the putTxHistory argument type.
filterTxHistory :: Maybe Coin -> SortOrder -> Range SlotNo -> TxHistory -> TxHistory Source #
Apply optional filters on slotNo and sort using the default sort order
(first time/slotNo, then by TxId) to a
TxHistory
.
Model Operation Types
type ModelOp wid s xprv a = Database wid s xprv -> ( Either ( Err wid) a, Database wid s xprv) Source #
A database model operation, which is a function that takes a database and returns: * a value, which is a query of the database, or an error; and * a (possibly) modified database.
All of the possible errors that any of the model database functions might return.
NoSuchWallet wid | |
WalletAlreadyExists wid | |
NoSuchTx wid ( Hash "Tx") | |
CantRemoveTxInLedger wid ( Hash "Tx") |
Instances
Functor Err Source # | |
Foldable Err Source # | |
Defined in Cardano.Wallet.DB.Pure.Implementation fold :: Monoid m => Err m -> m Source # foldMap :: Monoid m => (a -> m) -> Err a -> m Source # foldMap' :: Monoid m => (a -> m) -> Err a -> m Source # foldr :: (a -> b -> b) -> b -> Err a -> b Source # foldr' :: (a -> b -> b) -> b -> Err a -> b Source # foldl :: (b -> a -> b) -> b -> Err a -> b Source # foldl' :: (b -> a -> b) -> b -> Err a -> b Source # foldr1 :: (a -> a -> a) -> Err a -> a Source # foldl1 :: (a -> a -> a) -> Err a -> a Source # toList :: Err a -> [a] Source # null :: Err a -> Bool Source # length :: Err a -> Int Source # elem :: Eq a => a -> Err a -> Bool Source # maximum :: Ord a => Err a -> a Source # minimum :: Ord a => Err a -> a Source # |
|
Traversable Err Source # | |
Defined in Cardano.Wallet.DB.Pure.Implementation |
|
Eq wid => Eq ( Err wid) Source # | |
Show wid => Show ( Err wid) Source # | |
Model database functions
mInitializeWallet :: forall wid s xprv. Ord wid => wid -> Wallet s -> WalletMetadata -> TxHistory -> GenesisParameters -> ModelOp wid s xprv () Source #
mRemoveWallet :: Ord wid => wid -> ModelOp wid s xprv () Source #
mListWallets :: Ord wid => ModelOp wid s xprv [wid] Source #
mListCheckpoints :: Ord wid => wid -> ModelOp wid s xprv [ ChainPoint ] Source #
mRollbackTo :: Ord wid => wid -> Slot -> ModelOp wid s xprv ChainPoint Source #
mPutWalletMeta :: Ord wid => wid -> WalletMetadata -> ModelOp wid s xprv () Source #
mReadWalletMeta :: Ord wid => TimeInterpreter Identity -> wid -> ModelOp wid s xprv ( Maybe WalletMetadata ) Source #
mPutDelegationCertificate :: Ord wid => wid -> DelegationCertificate -> SlotNo -> ModelOp wid s xprv () Source #
mReadTxHistory :: forall wid s xprv. Ord wid => TimeInterpreter Identity -> wid -> Maybe Coin -> SortOrder -> Range SlotNo -> Maybe TxStatus -> ModelOp wid s xprv [ TransactionInfo ] Source #
mPutLocalTxSubmission :: Ord wid => wid -> Hash "Tx" -> SealedTx -> SlotNo -> ModelOp wid s xprv () Source #
mReadLocalTxSubmissionPending :: Ord wid => wid -> ModelOp wid s xprv [ LocalTxSubmissionStatus SealedTx ] Source #
mPutPrivateKey :: Ord wid => wid -> xprv -> ModelOp wid s xprv () Source #
mReadGenesisParameters :: Ord wid => wid -> ModelOp wid s xprv ( Maybe GenesisParameters ) Source #
mCheckWallet :: Ord wid => wid -> ModelOp wid s xprv () Source #