Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

[AD-501] Move wallet restore logic to cardano modules #391

Merged
merged 1 commit into from
Dec 6, 2018

Conversation

epicallan
Copy link
Contributor

@epicallan epicallan commented Nov 28, 2018

Description:
Problem: walletRestore and walletRestoreFromFile use a lot of Cardano-related stuff.

solution: move walletRestore logic to passive wallet layer.

Refrences: #385

YT issue: https://issues.serokell.io/issue/AD-501

Checklist:

@epicallan epicallan force-pushed the epicallan/ad501-move-wallet-restore-logic branch from c551e97 to dd169b6 Compare November 28, 2018 11:49
@epicallan epicallan requested review from Hithroc and removed request for dniku November 28, 2018 12:05
@epicallan epicallan force-pushed the epicallan/ad501-move-wallet-restore-logic branch from dd169b6 to 59ecd9e Compare November 28, 2018 12:07
@epicallan epicallan self-assigned this Nov 28, 2018
@gromakovsky
Copy link
Member

Why did you open a new PR instead of closing the existing one (#385)? You should at least provide the reference to the old PR in the description, because the old PR has my comments.

@epicallan
Copy link
Contributor Author

epicallan commented Nov 28, 2018

@gromakovsky its because you mentioned branch name wasn't conventional. I also noticed implementing your changes was close to a total rewrite of what I had done, so I didn't think it would be a big deal to re-do on a properly named branch.
I have added a reference to the old PR in description section

import Ariadne.Wallet.Face (Mnemonic(..))

newtype WrongMnemonic = WrongMnemonic Text
deriving (Eq, Show)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
deriving (Eq, Show)
deriving (Eq, Show)



data WalletToRestore
= WalletToRestore
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that our code style says that constructor should be on the previous line in this case.

-> PassPhrase
-> m EncryptedSecretKey
getKeyFromMnemonic isAriadneMnemonic mnemonicWords pp =
if
Copy link
Contributor

Choose a reason for hiding this comment

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

Guards can be used here.

Right (sk, _) -> pure sk
| otherwise -> throwM $ WrongMnemonic "Unknown mnemonic type"

-- | reads daedalus wallet keys from file for wallet restoration
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
-- | reads daedalus wallet keys from file for wallet restoration
-- | Reads daedalus wallet keys from file for wallet restoration

Copy link
Contributor

@artemohanjanyan artemohanjanyan left a comment

Choose a reason for hiding this comment

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

Just a bit of ranting on formatting for now :)

Just bip44DerPath -> Just ((toHdAddressId bip44DerPath, addr), utxo)
{-------------------------------------------------------------------------------
Utilities
-------------------------------------------------------------------------------}
Copy link
Contributor

Choose a reason for hiding this comment

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

This block can be deleted safely, I believe. The module is small enough.

ariadne/cardano/src/Ariadne/Wallet/Backend/Restore.hs Outdated Show resolved Hide resolved
"Failed to decode " <> path <> ": " <> show txt

data RestoreFrom
= RestoreFromMnemonic !Mnemonic
Copy link
Member

Choose a reason for hiding this comment

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

Hm, now I realized that what I proposed is not exactly what I want. Specifically, I want isAriadneMnemonic logic to still be outside Cardano Kernel. And I see why this type makes it impossible. I propose to change Mnemonic here to Either Mnemonic BackupPhrase.

@epicallan epicallan force-pushed the epicallan/ad501-move-wallet-restore-logic branch 2 times, most recently from 4396063 to f173e0c Compare December 3, 2018 21:53
@epicallan epicallan removed the request for review from Hithroc December 4, 2018 14:14
Copy link
Member

@gromakovsky gromakovsky left a comment

Choose a reason for hiding this comment

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

LGTM except two small things.

getKeyFromMnemonic pp = \case
Left (Mnemonic mnemonic) ->
let mnemonicWords = words mnemonic
seed = mnemonicToSeedNoPassword (unwords $ Unsafe.init mnemonicWords)
Copy link
Member

Choose a reason for hiding this comment

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

I think wallet kernel shouldn't know about this Unsafe.init thing, let's do it outside this module.

Copy link
Member

@gromakovsky gromakovsky left a comment

Choose a reason for hiding this comment

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

Ok. In the end commits should be squashed into one commit with Problem: and Solution:.

@epicallan epicallan force-pushed the epicallan/ad501-move-wallet-restore-logic branch from d639c80 to 845c09f Compare December 6, 2018 14:15
Problem: walletRestore and walletRestoreFromFile use a lot of Cardano-related stuff.

solution: move walletRestore logic to passive wallet layer.
@epicallan epicallan force-pushed the epicallan/ad501-move-wallet-restore-logic branch from 845c09f to 979dac7 Compare December 6, 2018 14:16
@epicallan epicallan merged commit 01b6b90 into master Dec 6, 2018
@serokell-bot serokell-bot deleted the epicallan/ad501-move-wallet-restore-logic branch December 6, 2018 14:27
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.

3 participants