Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

[CBR-390] Fixes TxMeta fields and tests #3473

Merged
merged 1 commit into from
Aug 24, 2018
Merged

[CBR-390] Fixes TxMeta fields and tests #3473

merged 1 commit into from
Aug 24, 2018

Conversation

kderme
Copy link
Member

@kderme kderme commented Aug 24, 2018

Description

This fixes all TxMeta field and adds tests.

Linked issue

CBR-390

Type of change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🛠 New feature (non-breaking change which adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
  • 🏭 Refactoring that does not change existing functionality but does improve things like code readability, structure etc
  • 🔨 New or improved tests for existing code
  • ⛑ git-flow chore (backport, hotfix, etc)

Developer checklist

  • I have read the style guide document, and my code follows the code style of this project.
  • If my code deals with exceptions, it follows the guidelines.
  • I have updated any documentation accordingly, if needed. Documentation changes can be reflected in opening a PR on cardanodocs.com, amending the inline Haddock comments, any relevant README file or one of the document listed in the docs directory.
  • CHANGELOG entry has been added and is linked to the correct PR on GitHub.

Testing checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.

QA Steps

Screenshots (if available)

@kderme kderme requested review from edsko and uroboros August 24, 2018 11:20
@edsko edsko mentioned this pull request Aug 24, 2018
12 tasks
Copy link
Contributor

@edsko edsko left a comment

Choose a reason for hiding this comment

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

Looking good, I'd just like a few clarifications in one or two places.

, _txMetaIsLocal = False
, _txMetaIsOutgoing = False
, _txMetaIsLocal = allOurs
, _txMetaIsOutgoing = outCoin < inCoin
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this definition very confusing. At first glance it looks like this says: "a transaction is considered outgoing if there's less going out than coming in". It doesn't say that, of course, and I do think the definition is right, but I had to read it 10 times before I was convinced. I think it's confusing because inCoin suggests this is "incoming" -- but that's actually the outgoing part ("in" not for "incoming" but for "input"), and outCoin suggests this is "outgoing" -- but is actually the incoming part ("out" not for "outgoing" but rather for "output"). I would suggest renaming. Perhaps reducedAccBalance and increasedAccBalance or something like that? Not sure what the best names are, but I think as is it's just too confusing.

Copy link
Member Author

@kderme kderme Aug 24, 2018

Choose a reason for hiding this comment

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

you're right, I rename them to spentInputCoins and gainedOutputsCoins.

@@ -38,6 +41,9 @@ import Pos.Wallet.Web.Tracking.Decrypt (WalletDecrCredentialsKey (..),
Submit pending transactions
-------------------------------------------------------------------------------}


type PartialTxMeta = Bool -> Coin -> IO TxMeta
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a comment explaining what it's for and what the arguments are. Does it really need to live in IO?

metaForNewTx :: Monad m => Core.Timestamp ->
HdAccountId -> TxId -> NonEmpty (TxIn, TxOutAux) -> NonEmpty TxOut -> Bool -> Coin -> Bool -> Coin -> m TxMeta
metaForNewTx time accountId txId inputs outputs allInpOurs inCoin allOutOurs outCoin =
return $ TxMeta {
Copy link
Contributor

Choose a reason for hiding this comment

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

This duplicates the logic from above, it would be nice if they shared some code, especially because some of these definitions are a bit confusing.

metas = map (\acc -> resolvedToTxMeta tx
(nothingToZero acc prefInCoins)
(nothingToZero acc prefOutCoins)
(onlyOurInps && onlyOurOuts) acc) allAccounts

-- | Prefilter inputs of a transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this whole prefiltering code needs a tidying pass, comments added, naming changed, etc. but we can take a look at that another time.

@edsko
Copy link
Contributor

edsko commented Aug 24, 2018

Going to merge this as-is because we need the results in the wallet restoration work. @kderme will submit a follow up PR addressing the above.

@edsko edsko merged commit 830b316 into develop Aug 24, 2018
@edsko edsko deleted the kderme/CBR-390 branch August 24, 2018 13:20
KtorZ pushed a commit that referenced this pull request Nov 9, 2018
[CBR-390] Fixes TxMeta fields and tests
KtorZ pushed a commit to input-output-hk/cardano-wallet-legacy that referenced this pull request Nov 9, 2018
…hk/kderme/CBR-390

[CBR-390] Fixes TxMeta fields and tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants