Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

[CO-334] Implement remaining V0 endpoints to V1 #3197

Merged
merged 21 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
cc40e11
[CO-334] Stub API endpoints
parsonsmatt Jul 3, 2018
3d7881c
[CO-334] Add comments with request/response types
parsonsmatt Jul 3, 2018
bc174b9
[CO-334] Draft 'Seed' and 'WalletRedemption' types
parsonsmatt Jul 3, 2018
3c96961
[CO-336] Sketch redemption endpoints
parsonsmatt Jul 5, 2018
248d2d9
[CO-334] Rename to internal
parsonsmatt Jul 5, 2018
d24b22d
[CO-336] Finish implementing handler
parsonsmatt Jul 6, 2018
a0254b6
[CO-334] Build success
parsonsmatt Jul 5, 2018
cd0e5d7
[CO-336] Move redemption endpoints under Accounts
parsonsmatt Jul 9, 2018
869e481
[CO-336] Fix bad Swagger spec
parsonsmatt Jul 10, 2018
afd21db
[CO-336] Prevent zero-coin payment test failure
parsonsmatt Jul 11, 2018
6218fdb
[CO-336] Implement type error for conversions
parsonsmatt Jul 11, 2018
f1df250
[CO-336] Newtype the redemption mnemonic
parsonsmatt Jul 17, 2018
2d9c720
[CO-336] Remove redundant pragma
parsonsmatt Jul 18, 2018
0c7e82a
[CO-336] Replace Mnemonic with a newtype
parsonsmatt Jul 18, 2018
9afceb8
[CO-336] Remove mnemonic from the wallet's API types; rely on semanti…
parsonsmatt Jul 19, 2018
0b61b19
[CO-336] Fix tests
parsonsmatt Jul 19, 2018
47fa08c
[CO-335] Implement legacy functionality
parsonsmatt Jul 23, 2018
dd115c3
Merge branch 'CO-336' into Squad1/CO-334/implement-v0-endpoints
KtorZ Jul 25, 2018
4ff8025
[CO-335] Remove dead code
parsonsmatt Jul 23, 2018
39e7d2a
Merge branch 'CO-335' into Squad1/CO-334/implement-v0-endpoints
KtorZ Jul 25, 2018
538f44b
[CO-334] Finalize 'Internal' API
KtorZ Jul 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions wallet-new/cardano-sl-wallet-new.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Cardano.Wallet.API
Cardano.Wallet.API.Development
Cardano.Wallet.API.Development.Handlers
Cardano.Wallet.API.Development.Helpers
Cardano.Wallet.API.Development.LegacyHandlers
Cardano.Wallet.API.Indices
Cardano.Wallet.API.Internal
Cardano.Wallet.API.Internal.Handlers
Cardano.Wallet.API.Request
Cardano.Wallet.API.Request.Filter
Cardano.Wallet.API.Request.Pagination
Expand Down Expand Up @@ -292,6 +290,7 @@ executable cardano-generate-swagger-file
, cardano-sl-core
, cardano-sl-wallet-new
, optparse-applicative
, servant-server
, swagger2
, universum >= 0.1.11

Expand All @@ -302,6 +301,7 @@ executable cardano-generate-swagger-file
ScopedTypeVariables
FlexibleContexts
MonadFailDesugaring
TypeOperators


-- Cryptic executable name to mitigate $PATH limitation
Expand Down Expand Up @@ -506,7 +506,7 @@ test-suite wallet-new-specs
hs-source-dirs: test test/unit

other-modules: APISpec
DevelopmentSpec
InternalAPISpec
MarshallingSpec
SwaggerSpec
RequestSpec
Expand Down
16 changes: 7 additions & 9 deletions wallet-new/generate-swagger-file/Main.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE LambdaCase #-}

module Main where

import Universum

import Data.Swagger (Swagger)
import Options.Applicative
import Servant ((:<|>))

import Cardano.Wallet.API (devAPI, v0API, v1API)
import Cardano.Wallet.API (InternalAPI, V1API, v0API)
import Pos.Core.Update (ApplicationName (..), SoftwareVersion (..))
import Pos.Util.CompileInfo (CompileTimeInfo (CompileTimeInfo),
gitRev)
Expand All @@ -27,7 +27,6 @@ data Command = Command
data TargetAPI
= TargetWalletV1
| TargetWalletV0
| TargetWalletDev
deriving (Show)


Expand All @@ -49,7 +48,7 @@ main =
cmdParser :: Parser Command
cmdParser = Command
<$> targetAPIOption (short 't' <> long "target" <> metavar "API"
<> help "Target API with version (e.g. 'wallet@v1', 'wallet@v0', 'wallet@dev'...)")
<> help "Target API with version (e.g. 'wallet@v1', 'wallet@v0')")

<*> optional (strOption (short 'o' <> long "output-file" <> metavar "FILEPATH"
<> help ("Output file, default to: " <> defaultOutputFilename)))
Expand All @@ -58,7 +57,6 @@ main =
targetAPIOption = option $ maybeReader $ \case
"wallet@v0" -> Just TargetWalletV0
"wallet@v1" -> Just TargetWalletV1
"wallet@dev" -> Just TargetWalletDev
_ -> Nothing
in do
Command{..} <-
Expand All @@ -71,12 +69,12 @@ main =

mkSwagger :: (CompileTimeInfo, SoftwareVersion) -> TargetAPI -> Swagger
mkSwagger details = \case
TargetWalletDev ->
Swagger.api details devAPI Swagger.highLevelShortDescription
TargetWalletV0 ->
Swagger.api details v0API Swagger.highLevelShortDescription
TargetWalletV1 ->
Swagger.api details v1API Swagger.highLevelDescription
Swagger.api details v1API' Swagger.highLevelDescription
where
v1API' = Proxy :: Proxy (V1API :<|> InternalAPI)


-- NOTE The software version is hard-coded here. Do determine the SoftwareVersion,
Expand Down
13 changes: 10 additions & 3 deletions wallet-new/integration/TransactionSpecs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@ transactionSpecs wRef wc = do
, pmtGroupingPolicy = Nothing
, pmtSpendingPassword = Nothing
}
tenthOf (V1 c) = V1 (Core.mkCoin (Core.getCoin c `div` 10))
tenthOf (V1 c) =
V1 (Core.mkCoin (max 1 (Core.getCoin c `div` 10)))

etxn <- postTransaction wc payment

txn <- fmap wrData etxn `shouldPrism` _Right

eresp <- getTransactionIndex wc (Just (walId wallet)) (Just (accIndex toAcct)) Nothing
eresp <- getTransactionIndex
wc
(Just (walId wallet))
(Just (accIndex toAcct))
Nothing
resp <- fmap wrData eresp `shouldPrism` _Right

map txId resp `shouldContain` [txId txn]

it "asset-locked wallets can receive funds and transaction are confirmed in index" $ do
it ( "asset-locked wallets can receive funds and transactions are "
<> "confirmed in index"
) $ do
genesis <- genesisWallet wc
(fromAcct, _) <- firstAccountAndId wc genesis

Expand Down
38 changes: 15 additions & 23 deletions wallet-new/src/Cardano/Wallet/API.hs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
module Cardano.Wallet.API
( V0API
, V0API'
, v0API
, V1API
, v1API
, DevAPI
, devAPI
, InternalAPI
, internalAPI
, WalletAPI
, walletAPI
, WalletDevAPI
, walletDevAPI
, WalletDocAPI
, walletDocAPI
, WalletDevDocAPI
, walletDevDocAPI
) where

import Cardano.Wallet.API.Types (WalletLoggingConfig)
import Pos.Util.Servant (LoggingApi)
import Servant ((:<|>), (:>), Proxy (..))
import Servant.Swagger.UI (SwaggerSchemaUI)

import qualified Cardano.Wallet.API.Development as Dev
import qualified Cardano.Wallet.API.Internal as Internal
import qualified Cardano.Wallet.API.V0 as V0
import qualified Cardano.Wallet.API.V1 as V1

Expand All @@ -38,35 +35,30 @@ import qualified Cardano.Wallet.API.V1 as V1
-- * 'Cardano.Wallet.Server' contains the main server;
-- * 'Cardano.Wallet.API.V0.Handlers' contains all the @Handler@s serving the V0 API;
-- * 'Cardano.Wallet.API.V1.Handlers' contains all the @Handler@s serving the V1 API;
-- * 'Cardano.Wallet.API.Development.Handlers' contains all the @Handler@s serving the Dev API;
-- * 'Cardano.Wallet.API.Internalelopment.Handlers' contains all the @Handler@s serving the Internal API;

type V0Doc = "docs" :> "v0" :> SwaggerSchemaUI "index" "swagger.json"
type V0API = "api" :> V0.API
type V1Doc = "docs" :> "v1" :> SwaggerSchemaUI "index" "swagger.json"


type V0API = "api" :> V0.API
type V0API' = "api" :> "v0" :> V0.API
v0API :: Proxy V0API
v0API = Proxy

type V1Doc = "docs" :> "v1" :> SwaggerSchemaUI "index" "swagger.json"
type V1API = "api" :> "v1" :> V1.API
v1API :: Proxy V1API
v1API = Proxy

type DevDoc = "docs" :> "development" :> SwaggerSchemaUI "index" "swagger.json"
type DevAPI = "api" :> "development" :> Dev.API
devAPI :: Proxy DevAPI
devAPI = Proxy
type InternalAPI = "api" :> "internal" :> Internal.API
internalAPI :: Proxy InternalAPI
internalAPI = Proxy

type WalletAPI = LoggingApi WalletLoggingConfig (V0API :<|> V1API)

type WalletAPI = LoggingApi WalletLoggingConfig (V0API' :<|> V0API :<|> V1API :<|> InternalAPI)
walletAPI :: Proxy WalletAPI
walletAPI = Proxy

type WalletDevAPI = DevAPI :<|> WalletAPI
walletDevAPI :: Proxy WalletDevAPI
walletDevAPI = Proxy

type WalletDocAPI = V0Doc :<|> V1Doc
walletDocAPI :: Proxy WalletDocAPI
walletDocAPI = Proxy

type WalletDevDocAPI = DevDoc :<|> WalletDocAPI
walletDevDocAPI :: Proxy WalletDevDocAPI
walletDevDocAPI = Proxy
36 changes: 0 additions & 36 deletions wallet-new/src/Cardano/Wallet/API/Development.hs

This file was deleted.

15 changes: 0 additions & 15 deletions wallet-new/src/Cardano/Wallet/API/Development/Handlers.hs

This file was deleted.

12 changes: 0 additions & 12 deletions wallet-new/src/Cardano/Wallet/API/Development/Helpers.hs

This file was deleted.

68 changes: 0 additions & 68 deletions wallet-new/src/Cardano/Wallet/API/Development/LegacyHandlers.hs

This file was deleted.

23 changes: 23 additions & 0 deletions wallet-new/src/Cardano/Wallet/API/Internal.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- | This module contains the top level API definition for frontend-related
-- tasks. The API endpoints presented here are intended for use with the
-- Daedalus client, and aren't useful for wallets, exchanges, and other users.
module Cardano.Wallet.API.Internal where

import Cardano.Wallet.API.Response (ValidJSON)
import Cardano.Wallet.API.Types (Tags)
import Servant ((:<|>), (:>), DeleteNoContent, NoContent, Post,
Summary)

type API = Tags '["Internal"] :>
( "apply-update"
:> Summary "Apply the next available update"
:> Post '[ValidJSON] NoContent

:<|> "postpone-update"
:> Summary "Discard and postpone the next available update"
:> Post '[ValidJSON] NoContent

:<|> "reset-wallet-state"
:> Summary "Clear wallet state and all associated secret keys"
:> DeleteNoContent '[ValidJSON] NoContent
)
Loading