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

Commit cb94388

Browse files
committed
[CO-325] Fix rebase issues
Weirdly, the conflict resolutions during rebase completely cut the end of some files in conflict. I was using a new tool for solving merge-conflict. Gotta be more careful
1 parent a4e4d3d commit cb94388

File tree

7 files changed

+135
-56
lines changed

7 files changed

+135
-56
lines changed

wallet-new/src/Cardano/Wallet/API/Response.hs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@ import Cardano.Wallet.API.V1.Swagger.Example (Example, example)
2020
import Control.Lens
2121
import Data.Aeson
2222
import Data.Aeson.Encode.Pretty (encodePretty)
23-
import qualified Data.Aeson.Options as Serokell
2423
import Data.Aeson.TH
25-
import qualified Data.Char as Char
2624
import Data.Swagger as S hiding (Example, example)
27-
import qualified Data.Text.Buildable
2825
import Data.Typeable
2926
import Formatting (bprint, build, (%))
30-
import qualified Formatting.Buildable
3127
import GHC.Generics (Generic)
3228
import Servant.API.ContentTypes (Accept (..), JSON, MimeRender (..),
3329
MimeUnrender (..), OctetStream)
@@ -45,6 +41,11 @@ import Cardano.Wallet.API.Response.Sort.IxSet as SortBackend
4541
import Cardano.Wallet.API.V1.Errors
4642
(WalletError (JSONValidationFailed))
4743

44+
import qualified Data.Aeson.Options as Serokell
45+
import qualified Data.Char as Char
46+
import qualified Formatting.Buildable
47+
48+
4849
-- | Extra information associated with an HTTP response.
4950
data Metadata = Metadata
5051
{ metaPagination :: PaginationMetadata
@@ -66,6 +67,9 @@ instance Buildable Metadata where
6667
build Metadata{..} =
6768
bprint ("{ pagination="%build%" }") metaPagination
6869

70+
instance Example Metadata
71+
72+
6973
-- | An `WalletResponse` models, unsurprisingly, a response (successful or not)
7074
-- produced by the wallet backend.
7175
-- Includes extra informations like pagination parameters etc.
@@ -112,6 +116,12 @@ instance Buildable a => Buildable (WalletResponse a) where
112116
wrMeta
113117
wrData
114118

119+
instance Example a => Example (WalletResponse a) where
120+
example = WalletResponse <$> example
121+
<*> pure SuccessStatus
122+
<*> example
123+
124+
115125
-- | Inefficient function to build a response out of a @generator@ function. When the data layer will
116126
-- be rewritten the obvious solution is to slice & dice the data as soon as possible (aka out of the DB), in this order:
117127
--
@@ -161,14 +171,28 @@ paginate PaginationParams{..} rawResultSet =
161171
slice = take pp . drop ((cp - 1) * pp)
162172
in (slice rawResultSet, metadata)
163173

164-
instance Example Metadata
165-
instance Example a => Example (WalletResponse a) where
166-
example = WalletResponse <$> example
167-
<*> pure SuccessStatus
168-
<*> example
169-
170174

171175
-- | Creates a 'WalletResponse' with just a single record into it.
172176
single :: a -> WalletResponse a
173177
single theData = WalletResponse {
174178
wrData = theData
179+
, wrStatus = SuccessStatus
180+
, wrMeta = Metadata (PaginationMetadata 1 (Page 1) (PerPage 1) 1)
181+
}
182+
183+
--
184+
-- Creating a better user experience when it comes to errors.
185+
--
186+
187+
data ValidJSON deriving Typeable
188+
189+
instance FromJSON a => MimeUnrender ValidJSON a where
190+
mimeUnrender _ bs = case eitherDecode bs of
191+
Left err -> Left $ decodeUtf8 $ encodePretty (JSONValidationFailed $ toText err)
192+
Right v -> return v
193+
194+
instance Accept ValidJSON where
195+
contentType _ = contentType (Proxy @ JSON)
196+
197+
instance ToJSON a => MimeRender ValidJSON a where
198+
mimeRender _ = mimeRender (Proxy @ JSON)

wallet-new/src/Cardano/Wallet/API/V1/Handlers/Accounts.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ handlers w = deleteAccount w
2424
:<|> newAccount w
2525
:<|> updateAccount w
2626
:<|> redeemAda w
27+
:<|> getAccountAddresses w
28+
:<|> getAccountBalance w
2729

2830
deleteAccount :: PassiveWalletLayer IO
2931
-> WalletId
@@ -92,3 +94,21 @@ redeemAda :: PassiveWalletLayer IO
9294
-> Handler (WalletResponse Transaction)
9395
redeemAda _layer _wId _accIdx _redemption =
9496
error "unimplemented, see [CBR-349]"
97+
98+
getAccountAddresses
99+
:: PassiveWalletLayer IO
100+
-> WalletId
101+
-> AccountIndex
102+
-> RequestParams
103+
-> FilterOperations WalletAddress
104+
-> Handler (WalletResponse AccountAddresses)
105+
getAccountAddresses _layer _wId _accIdx _pagination _filters =
106+
error "unimplemented"
107+
108+
getAccountBalance
109+
:: PassiveWalletLayer IO
110+
-> WalletId
111+
-> AccountIndex
112+
-> Handler (WalletResponse AccountBalance)
113+
getAccountBalance _layer _wId _accIdx =
114+
error "unimplemented"

wallet-new/src/Cardano/Wallet/API/V1/LegacyHandlers/Accounts.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ getAccountAddresses wId accIdx pagination filters = do
127127

128128
getAccountBalance
129129
:: (V0.MonadWalletLogic ctx m)
130-
=> WalletId -> AccountIndex -> m (WalletResponse AccountBalance)
130+
=> WalletId
131+
-> AccountIndex
132+
-> m (WalletResponse AccountBalance)
131133
getAccountBalance wId accIdx = do
132134
resp <- getAccount wId accIdx
133135
return resp { wrData = AccountBalance . accAmount . wrData $ resp }

wallet-new/src/Cardano/Wallet/API/V1/Swagger/Example.hs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@ module Cardano.Wallet.API.V1.Swagger.Example where
22

33
import Universum
44

5-
import Cardano.Wallet.API.Response
6-
import Cardano.Wallet.API.V1.Types
7-
import qualified Cardano.Wallet.Kernel.DB.Util.IxSet as IxSet
8-
import Data.Default (Default (def))
9-
import Node (NodeId (..))
10-
11-
import Pos.Client.Txp.Util (InputSelectionPolicy (..))
125
import Test.QuickCheck (Arbitrary (..), Gen, listOf1)
136

147
import Cardano.Wallet.Orphans.Arbitrary ()
15-
import Pos.Arbitrary.Wallet.Web.ClientTypes ()
168
import Pos.Wallet.Web.ClientTypes (CUpdateInfo)
179
import Pos.Wallet.Web.Methods.Misc (WalletStateSnapshot (..))
18-
import Test.Pos.Wallet.Arbitrary.Web.ClientTypes ()
1910

11+
import qualified Cardano.Wallet.Kernel.DB.Util.IxSet as IxSet
2012
import qualified Data.Map.Strict as Map
2113

2214

wallet-new/src/Cardano/Wallet/API/V1/Types.hs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,37 +1966,7 @@ type CaptureAccountId = Capture "accountId" AccountIndex
19661966
-- Example typeclass instances
19671967
--
19681968

1969-
instance Example (V1 Core.PassPhrase)
1970-
instance Example (V1 Core.Coin)
1971-
1972-
instance Example a => Example (WalletResponse a) where
1973-
example = WalletResponse <$> example
1974-
<*> pure SuccessStatus
1975-
<*> example
1976-
1977-
-- | We have a specific 'Example' instance for @'V1' 'Address'@ because we want
1978-
-- to control the length of the examples. It is possible for the encoded length
1979-
-- to become huge, up to 1000+ bytes, if the 'UnsafeMultiKeyDistr' constructor
1980-
-- is used. We do not use this constructor, which keeps the address between
1981-
-- ~80-150 bytes long.
1982-
instance Example (V1 Address) where
1983-
example = fmap V1 . Core.makeAddress
1984-
<$> arbitrary
1985-
<*> arbitraryAttributes
1986-
where
1987-
arbitraryAttributes =
1988-
Core.AddrAttributes
1989-
<$> arbitrary
1990-
<*> oneof
1991-
[ pure Core.BootstrapEraDistr
1992-
, Core.SingleKeyDistr <$> arbitrary
1993-
]
1994-
1995-
instance Example BackupPhrase where
1996-
example = pure (BackupPhrase def)
1997-
1998-
instance Example Address
1999-
instance Example Metadata
1969+
instance Example Core.Address
20001970
instance Example AccountIndex
20011971
instance Example AccountBalance
20021972
instance Example AccountAddresses
@@ -2021,15 +1991,38 @@ instance Example NewAccount
20211991
instance Example TimeInfo
20221992
instance Example AddressValidity
20231993
instance Example NewAddress
2024-
instance Example CUpdateInfo
20251994
instance Example SubscriptionStatus
20261995
instance Example NodeId
1996+
instance Example ShieldedRedemptionCode
1997+
instance Example (V1 Core.PassPhrase)
1998+
instance Example (V1 Core.Coin)
20271999

2028-
instance Example InputSelectionPolicy where
2029-
example = pure OptimizeForHighThroughput
2000+
-- | We have a specific 'Example' instance for @'V1' 'Address'@ because we want
2001+
-- to control the length of the examples. It is possible for the encoded length
2002+
-- to become huge, up to 1000+ bytes, if the 'UnsafeMultiKeyDistr' constructor
2003+
-- is used. We do not use this constructor, which keeps the address between
2004+
-- ~80-150 bytes long.
2005+
instance Example (V1 Core.Address) where
2006+
example = fmap V1 . Core.makeAddress
2007+
<$> arbitrary
2008+
<*> arbitraryAttributes
2009+
where
2010+
arbitraryAttributes =
2011+
Core.AddrAttributes
2012+
<$> arbitrary
2013+
<*> oneof
2014+
[ pure Core.BootstrapEraDistr
2015+
, Core.SingleKeyDistr <$> arbitrary
2016+
]
20302017

2031-
instance Example (V1 InputSelectionPolicy) where
2032-
example = pure (V1 OptimizeForHighThroughput)
2018+
instance Example BackupPhrase where
2019+
example = pure (BackupPhrase def)
2020+
2021+
instance Example Core.InputSelectionPolicy where
2022+
example = pure Core.OptimizeForHighThroughput
2023+
2024+
instance Example (V1 Core.InputSelectionPolicy) where
2025+
example = pure (V1 Core.OptimizeForHighThroughput)
20332026

20342027
instance Example Account where
20352028
example = Account <$> example
@@ -2061,3 +2054,8 @@ instance Example Payment where
20612054
<*> example
20622055
<*> example -- TODO: will produce `Just groupingPolicy`
20632056
<*> example
2057+
2058+
instance Example Redemption where
2059+
example = Redemption <$> example
2060+
<*> pure Nothing
2061+
<*> example

wallet-new/src/Cardano/Wallet/Client.hs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,38 @@ hoistClient phi wc = WalletClient
244244
-- 'WalletClient' m@.
245245
liftClient :: MonadIO m => WalletClient IO -> WalletClient m
246246
liftClient = hoistClient liftIO
247+
248+
-- | Calls 'getWalletIndexPaged' using the 'Default' values for 'Page' and
249+
-- 'PerPage'.
250+
getWalletIndex :: Monad m => WalletClient m -> Resp m [Wallet]
251+
getWalletIndex = paginateAll . getWalletIndexPaged
252+
253+
254+
-- | A type alias shorthand for the response from the 'WalletClient'.
255+
type Resp m a = m (Either ClientError (WalletResponse a))
256+
257+
-- | The type of errors that the wallet might return.
258+
data ClientError
259+
= ClientWalletError V1Errors.WalletError
260+
-- ^ The 'WalletError' type represents known failures that the API
261+
-- might return.
262+
| ClientHttpError ServantError
263+
-- ^ We directly expose the 'ServantError' type as part of this
264+
| UnknownClientError SomeException
265+
-- ^ This constructor is used when the API client reports an error that
266+
-- isn't represented in either the 'ServantError' HTTP errors or the
267+
-- 'WalletError' for API errors.
268+
deriving (Show, Generic)
269+
270+
-- | General (and naive) equality instance.
271+
instance Eq ClientError where
272+
ClientWalletError e1 == ClientWalletError e2 = e1 == e2
273+
ClientHttpError e1 == ClientHttpError e2 = e1 == e2
274+
UnknownClientError _ == UnknownClientError _ = True
275+
_ == _ = False
276+
277+
-- | General exception instance.
278+
instance Exception ClientError where
279+
toException (ClientWalletError e) = toException e
280+
toException (ClientHttpError e) = toException e
281+
toException (UnknownClientError e) = toException e

wallet-new/src/Cardano/Wallet/Client/Http.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,11 @@ mkHttpClient baseUrl manager = WalletClient
181181
:<|> getTransactionIndexFilterSortsR
182182
:<|> getTransactionFeeR
183183
= transactionsAPI
184+
185+
addressesAPI
186+
:<|> walletsAPI
187+
:<|> accountsAPI
188+
:<|> transactionsAPI
189+
:<|> getNodeSettingsR
190+
:<|> getNodeInfoR
191+
= client (Proxy @("api" :> "v1" :> V1.API))

0 commit comments

Comments
 (0)