Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
Database / Persistence layer for the wallet backend. This is where we define the interface allowing us to store and fetch various data on our wallets.
Synopsis
-
data
DBLayer
m s k =
forall
stm.(
MonadIO
stm,
MonadFail
stm) =>
DBLayer
{
- initializeWallet :: WalletId -> Wallet s -> WalletMetadata -> [( Tx , TxMeta )] -> GenesisParameters -> ExceptT ErrWalletAlreadyExists stm ()
- removeWallet :: WalletId -> ExceptT ErrNoSuchWallet stm ()
- listWallets :: stm [ WalletId ]
- walletsDB :: DBVar stm ( DeltaMap WalletId ( DeltaWalletState s))
- putCheckpoint :: WalletId -> Wallet s -> ExceptT ErrNoSuchWallet stm ()
- readCheckpoint :: WalletId -> stm ( Maybe ( Wallet s))
- listCheckpoints :: WalletId -> stm [ ChainPoint ]
- putWalletMeta :: WalletId -> WalletMetadata -> ExceptT ErrNoSuchWallet stm ()
- readWalletMeta :: WalletId -> stm ( Maybe WalletMetadata )
- isStakeKeyRegistered :: WalletId -> ExceptT ErrNoSuchWallet stm Bool
- putDelegationCertificate :: WalletId -> DelegationCertificate -> SlotNo -> ExceptT ErrNoSuchWallet stm ()
- putDelegationRewardBalance :: WalletId -> Coin -> ExceptT ErrNoSuchWallet stm ()
- readDelegationRewardBalance :: WalletId -> stm Coin
- putTxHistory :: WalletId -> [( Tx , TxMeta )] -> ExceptT ErrNoSuchWallet stm ()
- readTxHistory :: WalletId -> Maybe Coin -> SortOrder -> Range SlotNo -> Maybe TxStatus -> stm [ TransactionInfo ]
- getTx :: WalletId -> Hash "Tx" -> ExceptT ErrNoSuchWallet stm ( Maybe TransactionInfo )
- putLocalTxSubmission :: WalletId -> Hash "Tx" -> SealedTx -> SlotNo -> ExceptT ErrPutLocalTxSubmission stm ()
- readLocalTxSubmissionPending :: WalletId -> stm [ LocalTxSubmissionStatus SealedTx ]
- updatePendingTxForExpiry :: WalletId -> SlotNo -> ExceptT ErrNoSuchWallet stm ()
- removePendingOrExpiredTx :: WalletId -> Hash "Tx" -> ExceptT ErrRemoveTx stm ()
- putPrivateKey :: WalletId -> (k ' RootK XPrv , PassphraseHash ) -> ExceptT ErrNoSuchWallet stm ()
- readPrivateKey :: WalletId -> stm ( Maybe (k ' RootK XPrv , PassphraseHash ))
- readGenesisParameters :: WalletId -> stm ( Maybe GenesisParameters )
- rollbackTo :: WalletId -> Slot -> ExceptT ErrNoSuchWallet stm ChainPoint
- prune :: WalletId -> Quantity "block" Word32 -> ExceptT ErrNoSuchWallet stm ()
- atomically :: forall a. stm a -> m a
-
data
DBFactory
m s k =
DBFactory
{
- withDatabase :: forall a. WalletId -> ( DBLayer m s k -> IO a) -> IO a
- removeDatabase :: WalletId -> IO ()
- listDatabases :: IO [ WalletId ]
- cleanDB :: DBLayer m s k -> m ()
- data ErrBadFormat
- newtype ErrWalletAlreadyExists = ErrWalletAlreadyExists WalletId
- data ErrNoSuchTransaction = ErrNoSuchTransaction WalletId ( Hash "Tx")
- data ErrRemoveTx
- data ErrPutLocalTxSubmission
Interface
A Database interface for storing various things in a DB. In practice,
we'll need some extra constraints on the wallet state that allows us to
serialize and unserialize it (e.g.
forall s. (Serialize s) => ...
)
NOTE:
We can't use record accessors on the DBLayer as it carries an existential
within its constructor. We are forced to pattern-match on the
DBLayer
record type in order to be able to use its methods in any context. With
NamedFieldPuns, or RecordWildCards, this can be quite easy:
myFunction DBLayer{..} = do ... myOtherFunction DBLayer{atomically,initializeWallet} = do ...
Alternatively, in some other context where the database may not be a function argument but come from a different source, it is possible to simply rely on 'Data.Function.(&)' to easily pattern match on it:
myFunction arg0 arg1 = db & DBLayer{..} -> do ... where db = ...
Note that it isn't possible to simply use a
where
clause or a
let
binding
here as the semantic for those are slightly different: we really need a
pattern match here!
forall stm.( MonadIO stm, MonadFail stm) => DBLayer | |
|
Instantiate database layers at will
DBFactory | |
|
Errors
data ErrBadFormat Source #
Can't read the database file because it's in a bad format (corrupted, too old, …)
Instances
Eq ErrBadFormat Source # | |
Defined in Cardano.Wallet.DB (==) :: ErrBadFormat -> ErrBadFormat -> Bool Source # (/=) :: ErrBadFormat -> ErrBadFormat -> Bool Source # |
|
Show ErrBadFormat Source # | |
Defined in Cardano.Wallet.DB |
|
Exception ErrBadFormat Source # | |
Defined in Cardano.Wallet.DB |
newtype ErrWalletAlreadyExists Source #
Forbidden operation was executed on an already existing wallet
Instances
Eq ErrWalletAlreadyExists Source # | |
Defined in Cardano.Wallet.DB |
|
Show ErrWalletAlreadyExists Source # | |
Defined in Cardano.Wallet.DB |
|
IsServerError ErrWalletAlreadyExists Source # | |
Defined in Cardano.Wallet.Api.Server |
data ErrNoSuchTransaction Source #
Indicates that the specified transaction hash is not found in the transaction history of the given wallet.
ErrNoSuchTransaction WalletId ( Hash "Tx") |
Instances
Eq ErrNoSuchTransaction Source # | |
Defined in Cardano.Wallet.DB (==) :: ErrNoSuchTransaction -> ErrNoSuchTransaction -> Bool Source # (/=) :: ErrNoSuchTransaction -> ErrNoSuchTransaction -> Bool Source # |
|
Show ErrNoSuchTransaction Source # | |
Defined in Cardano.Wallet.DB |
|
IsServerError ErrNoSuchTransaction Source # | |
Defined in Cardano.Wallet.Api.Server |
data ErrRemoveTx Source #
Can't remove pending or expired transaction.
ErrRemoveTxNoSuchWallet ErrNoSuchWallet | |
ErrRemoveTxNoSuchTransaction ErrNoSuchTransaction | |
ErrRemoveTxAlreadyInLedger ( Hash "Tx") |
Instances
Eq ErrRemoveTx Source # | |
Defined in Cardano.Wallet.DB (==) :: ErrRemoveTx -> ErrRemoveTx -> Bool Source # (/=) :: ErrRemoveTx -> ErrRemoveTx -> Bool Source # |
|
Show ErrRemoveTx Source # | |
Defined in Cardano.Wallet.DB |
|
IsServerError ErrRemoveTx Source # | |
Defined in Cardano.Wallet.Api.Server |
data ErrPutLocalTxSubmission Source #
Can't add a transaction to the local tx submission pool.
ErrPutLocalTxSubmissionNoSuchWallet ErrNoSuchWallet | |
ErrPutLocalTxSubmissionNoSuchTransaction ErrNoSuchTransaction |
Instances
Eq ErrPutLocalTxSubmission Source # | |
Defined in Cardano.Wallet.DB |
|
Show ErrPutLocalTxSubmission Source # | |
Defined in Cardano.Wallet.DB |