Skip to content

Commit

Permalink
sneaking purpose in postAccountKey
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jun 8, 2021
1 parent 856f43c commit 708dc97
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/core/src/Cardano/Wallet/Api.hs
Expand Up @@ -173,6 +173,7 @@ import Cardano.Wallet.Api.Types
, ApiNetworkParameters
, ApiPoolId
, ApiPostAccountKeyData
, ApiPostAccountKeyDataWithPurpose
, ApiPostRandomAddressData
, ApiPutAddressesDataT
, ApiSelectCoinsDataT
Expand Down Expand Up @@ -396,7 +397,7 @@ type PostAccountKey = "wallets"
:> Capture "walletId" (ApiT WalletId)
:> "keys"
:> Capture "index" (ApiT DerivationIndex)
:> ReqBody '[JSON] ApiPostAccountKeyData
:> ReqBody '[JSON] ApiPostAccountKeyDataWithPurpose
:> PostAccepted '[JSON] ApiAccountKey

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/getAccountKey
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -207,7 +207,7 @@ import Cardano.Wallet.Api.Types
, ApiOurStakeKey (..)
, ApiPendingSharedWallet (..)
, ApiPoolId (..)
, ApiPostAccountKeyData (..)
, ApiPostAccountKeyDataWithPurpose (..)
, ApiPostRandomAddressData (..)
, ApiPutAddressesData (..)
, ApiRawMetadata (..)
Expand Down Expand Up @@ -2488,9 +2488,9 @@ postAccountPublicKey
-> (ByteString -> KeyFormat -> account)
-> ApiT WalletId
-> ApiT DerivationIndex
-> ApiPostAccountKeyData
-> ApiPostAccountKeyDataWithPurpose
-> Handler account
postAccountPublicKey ctx mkAccount (ApiT wid) (ApiT ix) (ApiPostAccountKeyData (ApiT pwd) extd) = do
postAccountPublicKey ctx mkAccount (ApiT wid) (ApiT ix) (ApiPostAccountKeyDataWithPurpose (ApiT pwd) extd _purposeM) = do
withWorkerCtx @_ @s @k ctx wid liftE liftE $ \wrk -> do
k <- liftHandler $ W.getAccountPublicKeyAtIndex @_ @s @k wrk wid pwd ix
pure $ mkAccount (publicKeyToBytes' extd $ getRawKey k) extd
Expand Down
13 changes: 13 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Expand Up @@ -139,6 +139,7 @@ module Cardano.Wallet.Api.Types
, ApiAccountKeyShared (..)
, KeyFormat (..)
, ApiPostAccountKeyData (..)
, ApiPostAccountKeyDataWithPurpose (..)

-- * API Types (Byron)
, ApiByronWallet (..)
Expand Down Expand Up @@ -1140,6 +1141,13 @@ data ApiPostAccountKeyData = ApiPostAccountKeyData
} deriving (Eq, Generic, Show)
deriving anyclass NFData

data ApiPostAccountKeyDataWithPurpose = ApiPostAccountKeyDataWithPurpose
{ passphrase :: ApiT (Passphrase "raw")
, format :: KeyFormat
, purpose :: Maybe (ApiT DerivationIndex)
} deriving (Eq, Generic, Show)
deriving anyclass NFData

data ApiAccountKey = ApiAccountKey
{ getApiAccountKey :: ByteString
, format :: KeyFormat
Expand Down Expand Up @@ -1783,6 +1791,11 @@ instance FromJSON ApiPostAccountKeyData where
instance ToJSON ApiPostAccountKeyData where
toJSON = genericToJSON defaultRecordTypeOptions

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

instance FromJSON ApiEpochInfo where
parseJSON = genericParseJSON defaultRecordTypeOptions
instance ToJSON ApiEpochInfo where
Expand Down
8 changes: 7 additions & 1 deletion lib/shelley/src/Cardano/Wallet/Shelley/Api/Server.hs
Expand Up @@ -132,6 +132,8 @@ import Cardano.Wallet.Api.Types
, ApiHealthCheck (..)
, ApiMaintenanceAction (..)
, ApiMaintenanceActionPostData (..)
, ApiPostAccountKeyData (..)
, ApiPostAccountKeyDataWithPurpose (..)
, ApiSelectCoinsAction (..)
, ApiSelectCoinsData (..)
, ApiStakePool
Expand Down Expand Up @@ -524,8 +526,12 @@ server byron icarus shelley multisig spl ntp =
:: ApiLayer (SharedState n SharedKey) SharedKey
-> Server SharedWalletKeys
sharedWalletKeys apilayer = derivePublicKey apilayer ApiVerificationKeyShared
:<|> postAccountPublicKey apilayer ApiAccountKeyShared
:<|> (\wid ix p -> postAccountPublicKey apilayer ApiAccountKeyShared wid ix (toKeyDataPurpose p) )
:<|> getAccountPublicKey apilayer ApiAccountKeyShared
where
toKeyDataPurpose :: ApiPostAccountKeyData -> ApiPostAccountKeyDataWithPurpose
toKeyDataPurpose (ApiPostAccountKeyData p f) =
ApiPostAccountKeyDataWithPurpose p f Nothing

sharedAddresses
:: ApiLayer (SharedState n SharedKey) SharedKey
Expand Down

0 comments on commit 708dc97

Please sign in to comment.