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

Add very preliminary interface/structure for wallet getter and creation #62

Merged
merged 1 commit into from
Mar 14, 2019

Conversation

paweljakubas
Copy link
Contributor

Issue Number

#23

Overview

  • I have added very preliminary wallet types, error types and createWallet/getWallet signature

Comments

Copy link
Contributor

@rvl rvl left a comment

Choose a reason for hiding this comment

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

Looks promising...

newtype WalletName = WalletName { _getWalletName :: Text }
deriving (Eq, Show)

newtype WalletPassPhrase = WalletPassPhrase ScrubbedBytes
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we instead use Passphrase "generation" defined in AddressDerivation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

definitely!

:: !(Maybe (Mnemonic mw))
, _name
:: !WalletName
, _passphrase
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be a Passphrase "encryption"?
And the mnemonicSentencePassphrase be a Passphrase "generation"?
Also, are the passphrases optional? If so, what value would denote "no passphrase"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced module defined passphrase types with address derivation ones.

I looked into swagger.yaml description of API and it says:

110 wallet2ndFactor: &wallet2ndFactor                                                                                                                                                         
111   description: An optional passphrase used to encrypt the mnemonic sentence.                                                                                                              
112   type: array                                                                                                                                                                             
113   minItems: 9                                                                                                                                                                             
114   maxItems: 12                                                                                                                                                                            
115   items:                                                                                                                                                                                  
116     type: string                                                                                                                                                                          
117     format: bip-0039-mnemonic-word{english}                                                                                                                                               
118   example: ["squirrel", "material", "silly", "twice", "direct", "slush", "pistol", "razor", "become"]

data NewWallet =
forall mw . ValidMnemonicSentence mw => NewWallet
{
_mnemonicSentence
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we settle the decision on how to generate lenses? TH?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good question

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Though, lenses is a topic we have to discuss in our coding standards before we start using them.

Copy link
Member

Choose a reason for hiding this comment

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

If we do...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added Generic derivation to handle generic-lens

Copy link
Member

@KtorZ KtorZ left a comment

Choose a reason for hiding this comment

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

On the right tracks. A few naming suggestion and, also, I'd recommend to draft and expose a WalletLayer interface in a similar fashion to what's done for the network layer (cf: https://github.com/input-output-hk/cardano-wallet/blob/master/src/Cardano/NetworkLayer.hs#L13).

This is in practice, what we'll expose and use from the "outer world"

-- | Module provides internal implementation of
-- | wallet api

module Cardano.Wallet.Kernel.Wallet where
Copy link
Member

Choose a reason for hiding this comment

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

Let's put that in Cardano.WalletLayer 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, also added Cardano.WalletLayer to expose corresponding interface

, name
:: !WalletName
, balance
:: !Coin
Copy link
Member

Choose a reason for hiding this comment

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

This, we compute from the wallet UTxOs directly 👍, no need to store or represent that at this level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the balance field

newtype PassphraseInfo = PassphraseInfo { lastUpdated :: WalletTimestamp }
deriving (Eq, Show)

data WalletState = WalletState {
Copy link
Member

Choose a reason for hiding this comment

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

What about calling this WalletMetadata ? Our "global" state for a wallet is actually the product (Wallet, WalletMetadata), with the Wallet being defined as in Cardano.Wallet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now calling this WalletMetadata



-- | Types
newtype CreateWallet = CreateWallet NewWallet
Copy link
Member

Choose a reason for hiding this comment

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

What's the rational for this newtype 🤔 ?

Copy link
Contributor Author

@paweljakubas paweljakubas Mar 14, 2019

Choose a reason for hiding this comment

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

I started with data but then got :

hlint src/Cardano/WalletLayer/Wallet.hs
src/Cardano/WalletLayer/Wallet.hs:44:1: Suggestion: Use newtype instead of data
Found:
  data CreateWallet = CreateWallet NewWallet
Perhaps:
  newtype CreateWallet = CreateWallet NewWallet
Note: decreases laziness

Copy link
Member

Choose a reason for hiding this comment

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

Haha, got it. I was intrigued by the need for an extra type though (regardless of the syntax used) ? What's wrong with using NewWallet directly? I believe it echoes a previous remark I made about getting a WalletLayer type, and I suspect that this was the premise of it 😅 ?

<> "GetWalletError"

instance Show GetWalletError where
show = fmt . build
Copy link
Member

Choose a reason for hiding this comment

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

tip: When you're grooming an initial interface like this, you can leave this kind of stuff for later and focus on getting the types right first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, just wanted to signal that will be using fmt rather than formatting. Removed that

@paweljakubas paweljakubas force-pushed the paweljakubas/23/sketch-wallet-layer branch from f0d2662 to f3bdf42 Compare March 14, 2019 11:37
data WalletLayer m s = WalletLayer
{ createWallet :: CreateWallet -> ExceptT WalletLayerError m (Wallet s)
, getWallet :: WalletId -> ExceptT WalletLayerError m (Wallet s)
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's have separate error types for the different functions. I am not expecting getWallet to throw anything related to the creation of a wallet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

-- | Errors
data CreateWalletError

data GetWalletError
Copy link
Member

Choose a reason for hiding this comment

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

Oui!

data GetWalletError

-- | Types
data CreateWallet = CreateWallet NewWallet | ImportWallet
Copy link
Member

Choose a reason for hiding this comment

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

This is the same thing in our new backend :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

expanded ImportWallet to ImportWallet (Key 'AccountK XPub)

src/Cardano/WalletLayer/Wallet.hs Outdated Show resolved Hide resolved
src/Cardano/WalletLayer/Wallet.hs Outdated Show resolved Hide resolved
_mnemonicSentence
:: !(Mnemonic 15)
, _mnemonicSentencePassphrase
:: !(Maybe (Passphrase "generation"))
Copy link
Member

Choose a reason for hiding this comment

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

The generation passphrase is represented as a short mnemonic (cf the API swagger spec). So we probably want to keep it the same at this stage and make the conversion later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now using Mnemonic 9

src/Cardano/WalletLayer/Wallet.hs Outdated Show resolved Hide resolved
-- | Module provides internal implementation of
-- | wallet api

module Cardano.WalletLayer.Wallet
Copy link
Member

Choose a reason for hiding this comment

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

Let's have that in the same module as WalletLayer until we see a good reason to move them out :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@paweljakubas paweljakubas force-pushed the paweljakubas/23/sketch-wallet-layer branch from f3bdf42 to c19da65 Compare March 14, 2019 13:24
[23] Add getWallet and types in line with api spec

[23] replace module define passphrase types with address derivation ones

[23] Refining types and cutting superfluous code

[23] Final fixes
@KtorZ KtorZ merged commit 847da46 into master Mar 14, 2019
@paweljakubas paweljakubas deleted the paweljakubas/23/sketch-wallet-layer branch March 19, 2019 09:14
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.

None yet

3 participants