Skip to content

Commit

Permalink
Review rework
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed May 25, 2021
1 parent 346a6a2 commit e4a99de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ module Cardano.Wallet
-- ** Root Key
, withRootKey
, derivePublicKey
, readPublicAccountKey
, getPublicAccountKey
, getAccountPublicKeyAtIndex
, readAccountPublicKey
, signMetadataWith
, ErrWithRootKey (..)
, ErrWrongPassphrase (..)
Expand Down Expand Up @@ -2266,15 +2266,15 @@ derivePublicKey ctx wid role_ ix = db & \DBLayer{..} -> do
db = ctx ^. dbLayer @IO @s @k

-- | Retrieve current public account key of a wallet.
getPublicAccountKey
readAccountPublicKey
:: forall ctx s k.
( HasDBLayer IO s k ctx
, GetAccount s k
)
=> ctx
-> WalletId
-> ExceptT ErrReadAccountPublicKey IO (k 'AccountK XPub)
getPublicAccountKey ctx wid = db & \DBLayer{..} -> do
readAccountPublicKey ctx wid = db & \DBLayer{..} -> do
cp <- mapExceptT atomically
$ withExceptT ErrReadAccountPublicKeyNoSuchWallet
$ withNoSuchWallet wid
Expand All @@ -2284,7 +2284,7 @@ getPublicAccountKey ctx wid = db & \DBLayer{..} -> do
db = ctx ^. dbLayer @IO @s @k

-- | Retrieve any public account key of a wallet.
readPublicAccountKey
getAccountPublicKeyAtIndex
:: forall ctx s k.
( HasDBLayer IO s k ctx
, HardDerivation k
Expand All @@ -2295,7 +2295,7 @@ readPublicAccountKey
-> Passphrase "raw"
-> DerivationIndex
-> ExceptT ErrReadAccountPublicKey IO (k 'AccountK XPub)
readPublicAccountKey ctx wid pwd ix = db & \DBLayer{..} -> do
getAccountPublicKeyAtIndex ctx wid pwd ix = db & \DBLayer{..} -> do
acctIx <- withExceptT ErrReadAccountPublicKeyInvalidIndex $ guardHardIndex ix

_cp <- mapExceptT atomically
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ postSharedWalletFromRootXPrv ctx generateKey body = do
dTemplateM = scriptTemplateFromSelf (getRawKey accXPub) <$> body ^. #delegationScriptTemplate
wName = getApiT (body ^. #name)
accXPub = publicKey $ deriveAccountPrivateKey pwd rootXPrv accIx
scriptValidation = fromMaybe RecommendedValidation (getApiT <$> body ^. #scriptValidation)
scriptValidation = maybe RecommendedValidation getApiT (body ^. #scriptValidation)

postSharedWalletFromAccountXPub
:: forall ctx s k n.
Expand Down Expand Up @@ -956,7 +956,7 @@ postSharedWalletFromAccountXPub ctx liftKey body = do
(ApiAccountPublicKey accXPubApiT) = body ^. #accountPublicKey
accXPub = getApiT accXPubApiT
wid = WalletId $ digest (liftKey accXPub)
scriptValidation = fromMaybe RecommendedValidation (getApiT <$> body ^. #scriptValidation)
scriptValidation = maybe RecommendedValidation getApiT (body ^. #scriptValidation)

scriptTemplateFromSelf :: XPub -> ApiScriptTemplateEntry -> ScriptTemplate
scriptTemplateFromSelf xpub (ApiScriptTemplateEntry cosigners' template') =
Expand Down Expand Up @@ -2344,7 +2344,7 @@ postAccountPublicKey
-> Handler account
postAccountPublicKey ctx mkAccount (ApiT wid) (ApiT ix) (ApiPostAccountKeyData (ApiT pwd) extd) = do
withWorkerCtx @_ @s @k ctx wid liftE liftE $ \wrk -> do
k <- liftHandler $ W.readPublicAccountKey @_ @s @k wrk wid pwd ix
k <- liftHandler $ W.getAccountPublicKeyAtIndex @_ @s @k wrk wid pwd ix
pure $ mkAccount (xPubtoBytes extd $ getRawKey k) extd

xPubtoBytes :: KeyFormat -> XPub -> ByteString
Expand All @@ -2365,7 +2365,7 @@ getAccountPublicKey
-> Handler account
getAccountPublicKey ctx mkAccount (ApiT wid) extended = do
withWorkerCtx @_ @s @k ctx wid liftE liftE $ \wrk -> do
k <- liftHandler $ W.getPublicAccountKey @_ @s @k wrk wid
k <- liftHandler $ W.readAccountPublicKey @_ @s @k wrk wid
pure $ mkAccount (xPubtoBytes extd $ getRawKey k) extd
where
extd = case extended of
Expand Down

0 comments on commit e4a99de

Please sign in to comment.