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

Commit 68ddd2e

Browse files
authored
Merge pull request #3462 from input-output-hk/develop-new
Make develop great again
2 parents afbf364 + 768e5b7 commit 68ddd2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1982
-387
lines changed

cardano-sl-wallet-new.cabal

+13-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ library
1919
Cardano.Wallet.API.Indices
2020
Cardano.Wallet.API.Internal
2121
Cardano.Wallet.API.Internal.Handlers
22+
Cardano.Wallet.API.Internal.LegacyHandlers
2223
Cardano.Wallet.API.Request
2324
Cardano.Wallet.API.Request.Filter
2425
Cardano.Wallet.API.Request.Pagination
@@ -97,6 +98,7 @@ library
9798
Cardano.Wallet.Kernel.DB.Sqlite
9899
Cardano.Wallet.Kernel.DB.TxMeta
99100
Cardano.Wallet.Kernel.DB.TxMeta.Types
101+
Cardano.Wallet.Kernel.DB.Updates
100102
Cardano.Wallet.Kernel.DB.Util.AcidState
101103
Cardano.Wallet.Kernel.DB.Util.IxSet
102104
Cardano.Wallet.Kernel.Diffusion
@@ -114,6 +116,8 @@ library
114116
Cardano.Wallet.Kernel.Types
115117
Cardano.Wallet.Kernel.Util
116118
Cardano.Wallet.Kernel.Util.Core
119+
Cardano.Wallet.Kernel.Util.StrictList
120+
Cardano.Wallet.Kernel.Util.StrictNonEmpty
117121
Cardano.Wallet.Kernel.Util.StrictStateT
118122
Cardano.Wallet.Kernel.Wallets
119123
Cardano.Wallet.LegacyServer
@@ -137,11 +141,11 @@ library
137141
Cardano.Wallet.WalletLayer.Kernel.Addresses
138142
Cardano.Wallet.WalletLayer.Kernel.Conv
139143
Cardano.Wallet.WalletLayer.Kernel.Info
144+
Cardano.Wallet.WalletLayer.Kernel.Internal
140145
Cardano.Wallet.WalletLayer.Kernel.Settings
141146
Cardano.Wallet.WalletLayer.Kernel.Transactions
142147
Cardano.Wallet.WalletLayer.Kernel.Wallets
143148
Cardano.Wallet.WalletLayer.Kernel
144-
Cardano.Wallet.WalletLayer.Error
145149

146150
other-modules: Paths_cardano_sl_wallet_new
147151
ghc-options: -Wall
@@ -172,13 +176,15 @@ library
172176
, cardano-sl-util
173177
, cardano-sl-wallet
174178
, cardano-sl-wallet-test
179+
, cereal
175180
, conduit
176181
, connection
177182
, containers
178183
, cryptonite
179184
, data-default
180185
, data-default-class
181186
, directory
187+
, ed25519
182188
, exceptions
183189
, formatting
184190
, formatting
@@ -390,7 +396,7 @@ executable wal-integr-test
390396
MonadFailDesugaring
391397

392398
test-suite wallet-unit-tests
393-
ghc-options: -Wall
399+
ghc-options: -Wall -O2
394400
type: exitcode-stdio-1.0
395401
main-is: WalletUnitTest.hs
396402
other-modules: InputSelection.Evaluation
@@ -523,7 +529,7 @@ test-suite wallet-unit-tests
523529
, time
524530

525531
test-suite wallet-new-specs
526-
ghc-options: -Wall
532+
ghc-options: -Wall -O2 -threaded -rtsopts
527533
type: exitcode-stdio-1.0
528534
main-is: Spec.hs
529535
hs-source-dirs: test test/unit
@@ -567,17 +573,20 @@ test-suite wallet-new-specs
567573
build-depends: base
568574
, aeson
569575
, bytestring
576+
, cardano-crypto
570577
, cardano-sl
571578
, cardano-sl-binary-test
572579
, cardano-sl-client
573580
, cardano-sl-client
581+
, cardano-sl-chain-test
574582
, cardano-sl-core
575583
, cardano-sl-core-test
576584
, cardano-sl-crypto
577585
, cardano-sl-chain
578586
, cardano-sl-util-test
579587
, cardano-sl-wallet
580588
, cardano-sl-wallet-new
589+
, cereal
581590
, data-default
582591
, directory
583592
, directory
@@ -587,6 +596,7 @@ test-suite wallet-new-specs
587596
, lens
588597
, QuickCheck
589598
, quickcheck-instances
599+
, safecopy
590600
, safe-exceptions
591601
, servant
592602
, servant-server

server/Main.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import Pos.Launcher.Configuration (AssetLockPath (..),
2929
import Pos.Util (logException)
3030
import Pos.Util.CompileInfo (HasCompileInfo, withCompileInfo)
3131
import Pos.Util.UserSecret (usVss)
32-
import Pos.Wallet.Web (bracketWalletWS, bracketWalletWebDB, getSKById,
33-
getWalletAddresses, runWRealMode)
32+
import Pos.Wallet.Web (bracketWalletWS, bracketWalletWebDB,
33+
getKeyById, getWalletAddresses, runWRealMode)
3434
import Pos.Wallet.Web.Mode (WalletWebMode)
3535
import Pos.Wallet.Web.State (askWalletDB, askWalletSnapshot,
3636
flushWalletStorage)
37-
import Pos.Wallet.Web.Tracking.Decrypt (eskToWalletDecrCredentials)
37+
import Pos.Wallet.Web.Tracking.Decrypt (keyToWalletDecrCredentials)
3838
import Pos.Wallet.Web.Tracking.Sync (syncWallet)
3939
import System.Wlog (LoggerName, Severity (..), logInfo, logMessage,
4040
usingLoggerName)
@@ -100,8 +100,8 @@ actionWithWallet pm txpConfig sscParams nodeParams ntpConfig wArgs@WalletBackend
100100
syncWallets :: WalletWebMode ()
101101
syncWallets = do
102102
addrs <- getWalletAddresses <$> askWalletSnapshot
103-
sks <- mapM getSKById addrs
104-
forM_ sks (syncWallet . eskToWalletDecrCredentials)
103+
keys' <- mapM getKeyById addrs
104+
forM_ keys' (syncWallet . keyToWalletDecrCredentials)
105105

106106
plugins :: TVar NtpStatus -> Plugins.Plugin WalletWebMode
107107
plugins ntpStatus =

src/Cardano/Wallet/API/Internal.hs

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
-- Daedalus client, and aren't useful for wallets, exchanges, and other users.
44
module Cardano.Wallet.API.Internal where
55

6+
import Pos.Core.Update (SoftwareVersion)
7+
8+
import Servant
9+
610
import Cardano.Wallet.API.Response (ValidJSON)
711
import Cardano.Wallet.API.Types (Tags)
8-
import Servant ((:<|>), (:>), DeleteNoContent, NoContent, Post,
9-
Summary)
12+
import Cardano.Wallet.API.V1.Types (V1)
1013

1114
type API = Tags '["Internal"] :>
12-
( "apply-update"
15+
( "next-update"
16+
:> Summary "Version of the next update (404 if none)"
17+
:> Get '[ValidJSON] (V1 SoftwareVersion)
18+
19+
:<|> "apply-update"
1320
:> Summary "Apply the next available update"
1421
:> Post '[ValidJSON] NoContent
1522

+27-43
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,34 @@
1-
{-# LANGUAGE DataKinds #-}
2-
{-# LANGUAGE FlexibleInstances #-}
3-
{-# LANGUAGE MultiParamTypeClasses #-}
4-
{-# LANGUAGE PolyKinds #-}
5-
{-# LANGUAGE RankNTypes #-}
6-
{-# LANGUAGE TypeFamilies #-}
7-
8-
module Cardano.Wallet.API.Internal.Handlers where
1+
module Cardano.Wallet.API.Internal.Handlers (handlers) where
92

103
import Universum
114

12-
import Control.Monad.Catch (MonadThrow)
135
import Servant
146

15-
import Cardano.Wallet.API.V1.Migration
16-
import Cardano.Wallet.Server.CLI (RunMode (..), isDebugMode)
7+
import Pos.Core.Update (SoftwareVersion)
178

189
import qualified Cardano.Wallet.API.Internal as Internal
19-
import qualified Pos.Client.KeyStorage as V0
20-
import qualified Pos.Wallet.Web.Methods.Misc as V0
21-
import qualified Pos.Wallet.Web.State as V0
22-
23-
24-
-- | Until we depend from V0 logic to implement the each 'Handler' we
25-
-- still need the natural transformation here.
26-
handlers
27-
:: (forall a. MonadV1 a -> Handler a)
28-
-> RunMode
29-
-> Server Internal.API
30-
handlers naturalTransformation runMode =
31-
let
32-
handlers' =
33-
V0.applyUpdate
34-
:<|> V0.postponeUpdate
35-
:<|> resetWalletState runMode
36-
in
37-
hoistServer (Proxy @Internal.API) naturalTransformation handlers'
38-
39-
40-
resetWalletState
41-
:: (V0.WalletDbReader ctx m, V0.MonadKeys m, MonadThrow m, MonadIO m)
42-
=> RunMode
43-
-> m NoContent
44-
resetWalletState runMode
45-
| isDebugMode runMode = do
46-
V0.deleteAllSecretKeys
47-
void (V0.askWalletDB >>= V0.testReset)
48-
return NoContent
49-
| otherwise =
50-
throwM err403
10+
import Cardano.Wallet.API.V1.Types (V1)
11+
import Cardano.Wallet.WalletLayer (PassiveWalletLayer)
12+
import qualified Cardano.Wallet.WalletLayer as WalletLayer
13+
14+
handlers :: PassiveWalletLayer IO -> ServerT Internal.API Handler
15+
handlers w = nextUpdate w
16+
:<|> applyUpdate w
17+
:<|> postponeUpdate w
18+
:<|> resetWalletState w
19+
20+
nextUpdate :: PassiveWalletLayer IO -> Handler (V1 SoftwareVersion)
21+
nextUpdate w = do
22+
mUpd <- liftIO $ WalletLayer.nextUpdate w
23+
case mUpd of
24+
Just upd -> return upd
25+
Nothing -> throwError err404
26+
27+
applyUpdate :: PassiveWalletLayer IO -> Handler NoContent
28+
applyUpdate w = liftIO (WalletLayer.applyUpdate w) >> return NoContent
29+
30+
postponeUpdate :: PassiveWalletLayer IO -> Handler NoContent
31+
postponeUpdate w = liftIO (WalletLayer.postponeUpdate w) >> return NoContent
32+
33+
resetWalletState :: PassiveWalletLayer IO -> Handler NoContent
34+
resetWalletState w = liftIO (WalletLayer.resetWalletState w) >> return NoContent
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE FlexibleInstances #-}
3+
{-# LANGUAGE MultiParamTypeClasses #-}
4+
{-# LANGUAGE PolyKinds #-}
5+
{-# LANGUAGE RankNTypes #-}
6+
{-# LANGUAGE TypeFamilies #-}
7+
8+
module Cardano.Wallet.API.Internal.LegacyHandlers where
9+
10+
import Universum
11+
12+
import Control.Monad.Catch (MonadThrow)
13+
14+
import Servant
15+
16+
import qualified Pos.Client.KeyStorage as V0
17+
import Pos.Core.Update (SoftwareVersion)
18+
import qualified Pos.Wallet.Web.ClientTypes as V0
19+
import qualified Pos.Wallet.Web.Methods.Misc as V0
20+
import qualified Pos.Wallet.Web.State as V0
21+
22+
import qualified Cardano.Wallet.API.Internal as Internal
23+
import Cardano.Wallet.API.V1.Migration
24+
import Cardano.Wallet.API.V1.Types (V1 (..))
25+
import Cardano.Wallet.Server.CLI (RunMode (..), isDebugMode)
26+
27+
-- | Until we depend from V0 logic to implement the each 'Handler' we
28+
-- still need the natural transformation here.
29+
handlers
30+
:: (HasConfiguration, HasUpdateConfiguration)
31+
=> (forall a. MonadV1 a -> Handler a)
32+
-> RunMode
33+
-> Server Internal.API
34+
handlers naturalTransformation runMode =
35+
let
36+
handlers' =
37+
nextUpdate
38+
:<|> V0.applyUpdate
39+
:<|> V0.postponeUpdate
40+
:<|> resetWalletState runMode
41+
in
42+
hoistServer (Proxy @Internal.API) naturalTransformation handlers'
43+
44+
nextUpdate :: ( MonadIO m
45+
, HasConfiguration
46+
, MonadThrow m
47+
, V0.WalletDbReader ctx m
48+
, HasUpdateConfiguration
49+
)
50+
=> m (V1 SoftwareVersion)
51+
nextUpdate = (V1 . V0.cuiSoftwareVersion) <$> V0.nextUpdate
52+
53+
resetWalletState
54+
:: (V0.WalletDbReader ctx m, V0.MonadKeys m, MonadThrow m, MonadIO m)
55+
=> RunMode
56+
-> m NoContent
57+
resetWalletState runMode
58+
| isDebugMode runMode = do
59+
V0.deleteAllSecretKeys
60+
void (V0.askWalletDB >>= V0.testReset)
61+
return NoContent
62+
| otherwise =
63+
throwM err403

src/Cardano/Wallet/API/Request/Pagination.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ instance Buildable PaginationMetadata where
153153
-- | `PaginationParams` is datatype which combines request params related
154154
-- to pagination together.
155155
data PaginationParams = PaginationParams
156-
{ ppPage :: Page
156+
{ ppPage :: Page -- ^ Greater than 0.
157157
, ppPerPage :: PerPage
158158
} deriving (Show, Eq, Generic)
159159

src/Cardano/Wallet/API/V1/Handlers/Transactions.hs

+8-27
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import Data.Coerce (coerce)
1717
import Pos.Client.Txp.Util (InputSelectionPolicy (..),
1818
defaultInputSelectionPolicy)
1919
import Pos.Core (Address, Timestamp)
20-
import Pos.Core.Txp (Tx (..), TxId, TxOut (..))
21-
import Pos.Crypto (hash)
20+
import Pos.Core.Txp (TxId)
2221

2322
import Cardano.Wallet.API.Request
2423
import Cardano.Wallet.API.Response
@@ -28,8 +27,7 @@ import Cardano.Wallet.Kernel.CoinSelection.FromGeneric
2827
(ExpenseRegulation (..), InputGrouping (..))
2928
import Cardano.Wallet.Kernel.DB.HdWallet (UnknownHdAccount)
3029
import Cardano.Wallet.Kernel.DB.TxMeta (TxMeta)
31-
import Cardano.Wallet.Kernel.Util.Core (getCurrentTimestamp,
32-
paymentAmount)
30+
import qualified Cardano.Wallet.Kernel.Transactions as Kernel
3331
import Cardano.Wallet.WalletLayer (ActiveWalletLayer,
3432
NewPaymentError (..), PassiveWalletLayer)
3533
import qualified Cardano.Wallet.WalletLayer as WalletLayer
@@ -109,28 +107,11 @@ estimateFees aw payment@Payment{..} = do
109107
redeemAda :: ActiveWalletLayer IO
110108
-> Redemption
111109
-> Handler (WalletResponse Transaction)
112-
redeemAda layer redemption = do
113-
res <- liftIO $ WalletLayer.redeemAda layer redemption
110+
redeemAda aw redemption = liftIO $ do
111+
res <- WalletLayer.redeemAda aw redemption
114112
case res of
115-
Left e -> throwM e
116-
Right tx -> do
117-
-- TODO: This is a straight copy and paste from 'newTransaction' in
118-
-- "Cardano.Wallet.API.V1.Handlers.Transactions". Once [CBR-239]
119-
-- is fixed, we should fix both instances.
120-
now <- liftIO getCurrentTimestamp
121-
-- NOTE(adn) As part of [CBR-239], we could simply fetch the
122-
-- entire 'Transaction' as part of the TxMeta.
123-
return $ single Transaction {
124-
txId = V1 (hash tx)
125-
, txConfirmations = 0
126-
, txAmount = V1 (paymentAmount $ _txOutputs tx)
127-
, txInputs = error "TODO, see [CBR-324]"
128-
, txOutputs = fmap outputsToDistribution (_txOutputs tx)
129-
, txType = error "TODO, see [CBR-324]"
130-
, txDirection = OutgoingTransaction
131-
, txCreationTime = V1 now
132-
, txStatus = Creating
133-
}
113+
Left err -> throwM err
114+
Right (_, meta) -> txFromMeta aw embedErr meta
134115
where
135-
outputsToDistribution :: TxOut -> PaymentDistribution
136-
outputsToDistribution (TxOut addr amount) = PaymentDistribution (V1 addr) (V1 amount)
116+
embedErr :: UnknownHdAccount -> WalletLayer.RedeemAdaError
117+
embedErr = WalletLayer.RedeemAdaError . Kernel.RedeemAdaUnknownAccountId

src/Cardano/Wallet/API/V1/LegacyHandlers/Addresses.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import qualified Pos.Wallet.Web.State.State as V0State
2727
import Pos.Wallet.Web.State.Storage (getWalletAddresses)
2828
import qualified Pos.Wallet.Web.State.Storage as V0
2929
import qualified Pos.Wallet.Web.Tracking as V0 (txMempoolToModifier)
30-
import Pos.Wallet.Web.Tracking.Decrypt (eskToWalletDecrCredentials)
30+
import Pos.Wallet.Web.Tracking.Decrypt (keyToWalletDecrCredentials)
3131

3232
import Cardano.Wallet.API.Indices (IxSet)
3333
import Cardano.Wallet.API.Request
@@ -126,6 +126,6 @@ getAddress addrText = do
126126
Just (_walletMeta, V0.AddressInfo{..}) -> do
127127
let accId = adiWAddressMeta ^. V0.wamAccount
128128
mps <- V0.withTxpLocalData V0.getMempoolSnapshot
129-
accMod <- V0.txMempoolToModifier ws mps . eskToWalletDecrCredentials =<< V0.findKey accId
129+
accMod <- V0.txMempoolToModifier ws mps . keyToWalletDecrCredentials =<< V0.findKey accId
130130
let caddr = V0.getWAddress ws accMod adiWAddressMeta
131131
single <$> migrate caddr

0 commit comments

Comments
 (0)