Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cardano.Wallet.DB.Model #660

Merged
merged 1 commit into from
Aug 29, 2019
Merged

Cardano.Wallet.DB.Model #660

merged 1 commit into from
Aug 29, 2019

Conversation

rvl
Copy link
Contributor

@rvl rvl commented Aug 26, 2019

Relates to #641.

Overview

  • Adds Cardano.Wallet.DB.Model module based on both the MVar DBLayer and the QSM tests model.
  • Adjusts MVar DBLayer to use the model.
  • Adjusts the QSM tests to use the model.

@rvl rvl self-assigned this Aug 26, 2019
@rvl rvl mentioned this pull request Aug 27, 2019
4 tasks
@rvl rvl changed the title wip: Initial Cardano.Wallet.DB.Model Cardano.Wallet.DB.Model Aug 27, 2019
@rvl rvl marked this pull request as ready for review August 27, 2019 15:47
Copy link
Member

@Anviking Anviking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like where this is going! lgtm.

-- data store.
-- Dummy implementation of the database-layer, using 'MVar'. This may be good
-- for testing to compare with an implementation on a real data store, or to use
-- when compiling the wallet for targets which don't have SQLite.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

filterTxHistory :: SortOrder -> Range SlotId -> TxHistory t -> TxHistory t
filterTxHistory order range =
filter ((`isWithinRange` range) . slotId . snd . snd)
. (case order of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use sortBy + Down instead of sortOn + reverse to traverse the list one time less, if it matters for performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted this code to be as simple and obvious as possible given that inefficiency doesn't matter in this case (particularly not linear slowdowns). So when I cut & pasted this function I was happy to leave it as it was.

data Database wid s t xprv = Database
{ wallets :: !(Map wid (WalletDatabase s t xprv))
-- ^ Wallet-related information.
, txs :: (Map (Hash "Tx") (Tx t))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need Txs? And why globally? It is not in your sqlite schema diagram.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, it's not in that diagram because it only has tables/columns relevant to rollback.
But in the full schema, a Tx is just all rows of tx_in and tx_out that share a txid. Because transactions are immutable, they are not attached to any wallet.

@rvl rvl merged commit 1778ba1 into master Aug 29, 2019
@rvl rvl deleted the rvl/641/db-model branch August 29, 2019 03:30
@KtorZ KtorZ added this to the Support Rollbacks milestone Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants