Skip to content

Commit

Permalink
improve the swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Apr 15, 2021
1 parent 1fecbfa commit 17552a4
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 119 deletions.
18 changes: 14 additions & 4 deletions lib/core/src/Cardano/Wallet/Api.hs
Expand Up @@ -118,7 +118,8 @@ module Cardano.Wallet.Api
, SharedWallets
, PostSharedWallet
, GetSharedWallet
, PatchSharedWallet
, PatchSharedWalletInPayment
, PatchSharedWalletInDelegation

, Proxy_
, PostExternalTransaction
Expand Down Expand Up @@ -845,7 +846,8 @@ type GetCurrentSMASHHealth = "smash"
type SharedWallets =
PostSharedWallet
:<|> GetSharedWallet
:<|> PatchSharedWallet
:<|> PatchSharedWalletInPayment
:<|> PatchSharedWalletInDelegation
:<|> DeleteSharedWallet

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/postSharedWallet
Expand All @@ -858,9 +860,17 @@ type GetSharedWallet = "shared-wallets"
:> Capture "walletId" (ApiT WalletId)
:> Get '[JSON] ApiSharedWallet

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/patchSharedWallet
type PatchSharedWallet = "shared-wallets"
-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/patchSharedWalletInPayment
type PatchSharedWalletInPayment = "shared-wallets"
:> Capture "walletId" (ApiT WalletId)
:> "payment-script-template"
:> ReqBody '[JSON] ApiSharedWalletPatchData
:> Patch '[JSON] ApiSharedWallet

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/patchSharedWalletInDelegation
type PatchSharedWalletInDelegation = "shared-wallets"
:> Capture "walletId" (ApiT WalletId)
:> "delegation-script-template"
:> ReqBody '[JSON] ApiSharedWalletPatchData
:> Patch '[JSON] ApiSharedWallet

Expand Down
43 changes: 6 additions & 37 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Expand Up @@ -155,7 +155,6 @@ module Cardano.Wallet.Api.Types
, ApiActiveSharedWallet (..)
, ApiSharedWalletPostData (..)
, ApiSharedWalletPatchData (..)
, ApiScriptTemplateUpdate (..)

-- * Polymorphic Types
, ApiT (..)
Expand Down Expand Up @@ -1049,25 +1048,23 @@ data ApiAccountKey = ApiAccountKey
deriving anyclass NFData

data ApiSharedWalletPostData = ApiSharedWalletPostData
{ name :: !(ApiT WalletName)
, accountPublicKey :: !ApiAccountPublicKey
, accountIx :: !(ApiT DerivationIndex)
, addressPoolGap :: !(ApiT AddressPoolGap)
{ retrieveMethod :: WalletOrAccountPostData
, accountIndex :: !(ApiT DerivationIndex)
, paymentScriptTemplate :: !ScriptTemplate
, delegationScriptTemplate :: !(Maybe ScriptTemplate)
} deriving (Eq, Generic, Show)
deriving anyclass NFData

data ApiActiveSharedWallet = ApiActiveSharedWallet
{ id :: !(ApiT WalletId)
, name :: !(ApiT WalletName)
, accountPublicKey :: !ApiAccountPublicKey
, accountIx :: !(ApiT DerivationIndex)
, accountIndex :: !(ApiT DerivationIndex)
, addressPoolGap :: !(ApiT AddressPoolGap)
, passphrase :: !(Maybe ApiWalletPassphraseInfo)
, paymentScriptTemplate :: !ScriptTemplate
, delegationScriptTemplate :: !(Maybe ScriptTemplate)
, delegation :: !ApiWalletDelegation
, balance :: !ApiWalletBalance
, assets :: !ApiWalletAssetsBalance
, state :: !(ApiT SyncProgress)
, tip :: !ApiBlockReference
} deriving (Eq, Generic, Show)
Expand All @@ -1076,8 +1073,7 @@ data ApiActiveSharedWallet = ApiActiveSharedWallet
data ApiPendingSharedWallet = ApiPendingSharedWallet
{ id :: !(ApiT WalletId)
, name :: !(ApiT WalletName)
, accountPublicKey :: !ApiAccountPublicKey
, accountIx :: !(ApiT DerivationIndex)
, accountIndex :: !(ApiT DerivationIndex)
, addressPoolGap :: !(ApiT AddressPoolGap)
, paymentScriptTemplate :: !ScriptTemplate
, delegationScriptTemplate :: !(Maybe ScriptTemplate)
Expand All @@ -1089,15 +1085,9 @@ newtype ApiSharedWallet = ApiSharedWallet
} deriving (Eq, Generic, Show)
deriving anyclass NFData

data ApiScriptTemplateUpdate =
PaymentScriptTemplate | DelegationScriptTemplate | BothScriptTemplates
deriving (Eq, Generic, Show, Bounded, Enum)
deriving anyclass NFData

data ApiSharedWalletPatchData = ApiSharedWalletPatchData
{ cosigner :: !(ApiT Cosigner)
, accountPublicKey :: !ApiAccountPublicKey
, scriptTemplateUpdate :: !ApiScriptTemplateUpdate
} deriving (Eq, Generic, Show)
deriving anyclass NFData

Expand Down Expand Up @@ -2297,12 +2287,6 @@ instance FromJSON (ApiT Cosigner) where
instance ToJSON (ApiT Cosigner) where
toJSON = toJSON . toText

instance FromJSON ApiScriptTemplateUpdate where
parseJSON =
parseJSON >=> eitherToParser . first ShowFmt . fromText
instance ToJSON ApiScriptTemplateUpdate where
toJSON = toJSON . toText

instance FromJSON ApiSharedWalletPatchData where
parseJSON = genericParseJSON defaultRecordTypeOptions
instance ToJSON ApiSharedWalletPatchData where
Expand Down Expand Up @@ -2438,21 +2422,6 @@ instance FromText AnyAddress where
_ -> Left $ TextDecodingError "AnyAddress is not correctly prefixed."
_ -> Left $ TextDecodingError "AnyAddress must be must be encoded as Bech32."

instance ToText ApiScriptTemplateUpdate where
toText PaymentScriptTemplate = "payment"
toText DelegationScriptTemplate = "delegation"
toText BothScriptTemplates = "both"

instance FromText ApiScriptTemplateUpdate where
fromText = \case
"payment" -> Right PaymentScriptTemplate
"delegation" -> Right DelegationScriptTemplate
"both" -> Right BothScriptTemplates
_ -> Left $ TextDecodingError $ unwords
[ "Invalid script template update. The following values expected:"
, "'payment', 'delegation', 'both'."
]

instance ToText (ApiT Cosigner) where
toText (ApiT (Cosigner ix)) = "cosigner#"<> T.pack (show ix)

Expand Down
9 changes: 7 additions & 2 deletions lib/shelley/src/Cardano/Wallet/Shelley/Api/Server.hs
Expand Up @@ -488,11 +488,16 @@ server byron icarus shelley spl ntp =

sharedWallets :: Server SharedWallets
sharedWallets =
postSharedWallet :<|> getSharedWallet :<|> patchSharedWallet :<|> deleteSharedWallet
postSharedWallet
:<|> getSharedWallet
:<|> patchSharedWalletInPayment
:<|> patchSharedWalletInDelegation
:<|> deleteSharedWallet
where
postSharedWallet = pure $ throwError err501
getSharedWallet = pure $ throwError err501
patchSharedWallet _ = pure $ throwError err501
patchSharedWalletInPayment _ = pure $ throwError err501
patchSharedWalletInDelegation _ = pure $ throwError err501
deleteSharedWallet = pure $ throwError err501

postAnyAddress
Expand Down

0 comments on commit 17552a4

Please sign in to comment.