-
Notifications
You must be signed in to change notification settings - Fork 217
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks promising...
src/Cardano/Wallet/Kernel/Wallet.hs
Outdated
newtype WalletName = WalletName { _getWalletName :: Text } | ||
deriving (Eq, Show) | ||
|
||
newtype WalletPassPhrase = WalletPassPhrase ScrubbedBytes |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely!
src/Cardano/Wallet/Kernel/Wallet.hs
Outdated
:: !(Maybe (Mnemonic mw)) | ||
, _name | ||
:: !WalletName | ||
, _passphrase |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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"]
src/Cardano/Wallet/Kernel/Wallet.hs
Outdated
data NewWallet = | ||
forall mw . ValidMnemonicSentence mw => NewWallet | ||
{ | ||
_mnemonicSentence |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generic
through https://hackage.haskell.org/package/generic-lens 👍
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do...
There was a problem hiding this comment.
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
There was a problem hiding this 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"
src/Cardano/Wallet/Kernel/Wallet.hs
Outdated
-- | Module provides internal implementation of | ||
-- | wallet api | ||
|
||
module Cardano.Wallet.Kernel.Wallet where |
There was a problem hiding this comment.
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
👍
There was a problem hiding this comment.
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
src/Cardano/Wallet/Kernel/Wallet.hs
Outdated
, name | ||
:: !WalletName | ||
, balance | ||
:: !Coin |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the balance
field
src/Cardano/Wallet/Kernel/Wallet.hs
Outdated
newtype PassphraseInfo = PassphraseInfo { lastUpdated :: WalletTimestamp } | ||
deriving (Eq, Show) | ||
|
||
data WalletState = WalletState { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now calling this WalletMetadata
src/Cardano/Wallet/Kernel/Wallet.hs
Outdated
|
||
|
||
-- | Types | ||
newtype CreateWallet = CreateWallet NewWallet |
There was a problem hiding this comment.
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 🤔 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😅 ?
src/Cardano/Wallet/Kernel/Wallet.hs
Outdated
<> "GetWalletError" | ||
|
||
instance Show GetWalletError where | ||
show = fmt . build |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
f0d2662
to
f3bdf42
Compare
data WalletLayer m s = WalletLayer | ||
{ createWallet :: CreateWallet -> ExceptT WalletLayerError m (Wallet s) | ||
, getWallet :: WalletId -> ExceptT WalletLayerError m (Wallet s) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/Cardano/WalletLayer/Wallet.hs
Outdated
-- | Errors | ||
data CreateWalletError | ||
|
||
data GetWalletError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui!
src/Cardano/WalletLayer/Wallet.hs
Outdated
data GetWalletError | ||
|
||
-- | Types | ||
data CreateWallet = CreateWallet NewWallet | ImportWallet |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
_mnemonicSentence | ||
:: !(Mnemonic 15) | ||
, _mnemonicSentencePassphrase | ||
:: !(Maybe (Passphrase "generation")) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
-- | Module provides internal implementation of | ||
-- | wallet api | ||
|
||
module Cardano.WalletLayer.Wallet |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
f3bdf42
to
c19da65
Compare
[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
Issue Number
#23
Overview
Comments