Skip to content

Commit

Permalink
Add PutWalletPassphrase operation to the Servant API definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Mar 27, 2019
1 parent c20dcf8 commit 52b9fe2
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 15 deletions.
28 changes: 14 additions & 14 deletions specifications/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,19 @@ definitions:
properties:
name: *walletName

WalletPutPassphraseData: &WalletPutPassphraseData
type: object
required:
- old_passphrase
- new_passphrase
properties:
old_passphrase:
<<: *walletPassphrase
description: The current passphrase.
new_passphrase:
<<: *walletPassphrase
description: A master passphrase to lock and protect the wallet for sensitive operation (e.g. sending funds).

#############################################################################
# #
# PARAMETERS #
Expand All @@ -536,19 +549,6 @@ parametersStakePoolId: &parametersStakePoolId
type: string
format: base58

parametersPutWalletPassphrase: &parametersPutWalletPassphrase
type: object
required:
- old_passphrase
- new_passphrase
properties:
old_passphrase:
<<: *walletPassphrase
description: The current passphrase.
new_passphrase:
<<: *walletPassphrase
description: A master passphrase to lock and protect the wallet for sensitive operation (e.g. sending funds).

parametersPostTransaction: &parametersPostTransaction
type: object
required:
Expand Down Expand Up @@ -846,7 +846,7 @@ paths:
parameters:
- *parametersWalletId
- <<: *parametersBody
schema: *parametersPutWalletPassphrase
schema: *WalletPutPassphraseData
responses: *responsesPutWalletPassphrase

/wallets/{walletId}/transactions:
Expand Down
13 changes: 12 additions & 1 deletion src/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
module Cardano.Wallet.Api where

import Cardano.Wallet.Api.Types
( Wallet, WalletId, WalletPostData, WalletPutData )
( Wallet
, WalletId
, WalletPostData
, WalletPutData
, WalletPutPassphraseData
)
import Data.Proxy
( Proxy (..) )
import Servant.API
Expand Down Expand Up @@ -52,3 +57,9 @@ type PutWallet = "wallets"
:> Capture "walletId" WalletId
:> ReqBody '[JSON] WalletPutData
:> Put '[JSON] Wallet

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/putWalletPassphrase
type PutWalletPassphrase = "wallets"
:> Capture "walletId" WalletId
:> ReqBody '[JSON] WalletPutPassphraseData
:> Put '[] NoContent
11 changes: 11 additions & 0 deletions src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Cardano.Wallet.Api.Types
, WalletBalance (..)
, WalletPostData (..)
, WalletPutData (..)
, WalletPutPassphraseData (..)

-- * Re-Export From Primitives
, PoolId (..)
Expand Down Expand Up @@ -124,6 +125,11 @@ newtype WalletPutData = WalletPutData
{ _name :: (Maybe (ApiT WalletName))
} deriving (Eq, Generic, Show)

data WalletPutPassphraseData = WalletPutPassphraseData
{ _oldPassphrase :: !(ApiT (Passphrase "encryption"))
, _newPassphrase :: !(ApiT (Passphrase "encryption"))
} deriving (Eq, Generic, Show)

data WalletBalance = WalletBalance
{ _available :: !(Quantity "lovelace" Natural)
, _total :: !(Quantity "lovelace" Natural)
Expand Down Expand Up @@ -184,6 +190,11 @@ instance FromJSON WalletPutData where
instance ToJSON WalletPutData where
toJSON = genericToJSON defaultRecordTypeOptions

instance FromJSON WalletPutPassphraseData where
parseJSON = genericParseJSON defaultRecordTypeOptions
instance ToJSON WalletPutPassphraseData where
toJSON = genericToJSON defaultRecordTypeOptions

instance FromJSON (ApiT (Passphrase "encryption")) where
parseJSON = parseJSON >=> \case
t | T.length t < 10 ->
Expand Down
21 changes: 21 additions & 0 deletions test/data/Cardano/Wallet/Api/WalletPutPassphraseData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"seed": -4033088551338152747,
"samples": [
{
"old_passphrase": "@^8Q}ja[LAN'),i8<xQ3𨒺b<]}R[r^.m+i@s[Yn~t7谊>$'Nu`a%2Z-kI5ꭘy1`0Qu=FO^c}btzzj}JB1⎹&)𫓘f|𐦵> &7z%wb.^ZS\"睥+3}v'yzZW%\\射2%7|sf4.u?-/pxy?M %&I@Q+SU(c5!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\\@\"C_Bxa@-+a4)=c`HZ'QS!Oe𥨵$Z,.lG1RH[{x@VZ[f\"Lp흪hQ𪭂0𨾶qP洱C2fEQ{=UMM2ak OaOquKTs4Q%tWGUk𡆊9<+𢟢EJ#pPD(\"2[~&j-sI?𣊃뭳..){#>^+i/gN;v(`1yKo#&T]?QuZu0}Y<.iZvzF:𡿔G`PVkY#RI𤏟b,#Sc3qf<;;kGe1B (qb o]O-fg=핂:H3aCJ06pKA𐤀[鑖*]ha^𐐁J"
}
]
}
17 changes: 17 additions & 0 deletions test/unit/Cardano/Wallet/Api/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Cardano.Wallet.Api.Types
, WalletPassphraseInfo (..)
, WalletPostData (..)
, WalletPutData (..)
, WalletPutPassphraseData (..)
, WalletState (..)
)
import Cardano.Wallet.Primitive.Mnemonic
Expand Down Expand Up @@ -130,6 +131,7 @@ spec = do
roundtripAndGolden $ Proxy @ Wallet
roundtripAndGolden $ Proxy @ WalletPostData
roundtripAndGolden $ Proxy @ WalletPutData
roundtripAndGolden $ Proxy @ WalletPutPassphraseData
roundtripAndGolden $ Proxy @ (ApiT AddressPoolGap)
roundtripAndGolden $ Proxy @ (ApiT (WalletDelegation (ApiT PoolId)))
roundtripAndGolden $ Proxy @ (ApiT WalletId)
Expand Down Expand Up @@ -203,6 +205,10 @@ instance Arbitrary WalletPutData where
arbitrary = genericArbitrary
shrink = genericShrink

instance Arbitrary WalletPutPassphraseData where
arbitrary = genericArbitrary
shrink = genericShrink

instance Arbitrary WalletBalance where
arbitrary = genericArbitrary
shrink = genericShrink
Expand Down Expand Up @@ -385,6 +391,17 @@ instance ToSchema WalletPutData where
Just schema ->
return $ NamedSchema (Just "WalletPutData") schema

-- | Ad-hoc 'ToSchema' instance for the 'WalletPutPassphraseData' definition: we
-- simply look it up from the specification.
instance ToSchema WalletPutPassphraseData where
declareNamedSchema _ =
case specification ^. definitions . at "WalletPutPassphraseData" of
Nothing -> error
"unable to find the definition for 'WalletPutPassphraseData' \
\in the spec"
Just schema ->
return $ NamedSchema (Just "WalletPutPassphraseData") schema

-- | Verify that all servant endpoints are present and match the specification
class ValidateEveryPath api where
validateEveryPath :: Proxy api -> Spec
Expand Down

0 comments on commit 52b9fe2

Please sign in to comment.