@@ -6,7 +6,6 @@ module Cardano.Wallet.API.V1.LegacyHandlers.Wallets (
6
6
, newWallet
7
7
) where
8
8
9
- import Formatting (build , sformat )
10
9
import Universum
11
10
import UnliftIO (MonadUnliftIO )
12
11
@@ -22,11 +21,9 @@ import Cardano.Wallet.API.V1.Types as V1
22
21
import qualified Cardano.Wallet.API.V1.Wallets as Wallets
23
22
import qualified Cardano.Wallet.Kernel.DB.Util.IxSet as IxSet
24
23
import Pos.Chain.Update ()
25
- import Pos.Client.KeyStorage (addPublicKey )
26
24
import qualified Pos.Core as Core
27
25
28
- import Pos.Util (HasLens (.. ), maybeThrow )
29
- import Pos.Util.Servant (encodeCType )
26
+ import Pos.Util (HasLens (.. ))
30
27
import qualified Pos.Wallet.WalletMode as V0
31
28
import Pos.Wallet.Web.Methods.Logic (MonadWalletLogic ,
32
29
MonadWalletLogicRead )
@@ -44,9 +41,6 @@ handlers = newWallet
44
41
:<|> getWallet
45
42
:<|> updateWallet
46
43
:<|> getUtxoStatistics
47
- :<|> checkExternalWallet
48
- :<|> newExternalWallet
49
- :<|> deleteExternalWallet
50
44
51
45
-- | Pure function which returns whether or not the underlying node is
52
46
-- \"synced enough\" to allow wallet creation/restoration. The notion of
@@ -195,127 +189,3 @@ getUtxoStatistics
195
189
-> m (WalletResponse UtxoStatistics )
196
190
getUtxoStatistics _ = do
197
191
return $ single (V1. computeUtxoStatistics V1. log10 [] )
198
-
199
- -- | Check if external wallet is presented in node's wallet db.
200
- checkExternalWallet
201
- :: -- ( V0.MonadWalletLogic ctx m
202
- -- , V0.MonadWalletHistory ctx m
203
- -- , MonadUnliftIO m
204
- -- , HasLens SyncQueue ctx SyncQueue
205
- -- )
206
- -- =>
207
- PublicKeyAsBase58
208
- -> m (WalletResponse WalletAndTxHistory )
209
- checkExternalWallet _encodedRootPK =
210
- error " [CHW-54], Cardano Hardware Wallet, check external wallet, legacy handler, unimplemented yet."
211
-
212
- -- | Creates a new or restores an existing external @wallet@ given a 'NewExternalWallet' payload.
213
- -- Returns to the client the representation of the created or restored wallet in the 'Wallet' type.
214
- newExternalWallet
215
- :: ( MonadThrow m
216
- , MonadUnliftIO m
217
- -- , HasLens SyncQueue ctx SyncQueue
218
- , V0. MonadBlockchainInfo m
219
- , V0. MonadWalletLogic ctx m
220
- )
221
- => NewExternalWallet
222
- -> m (WalletResponse Wallet )
223
- newExternalWallet (NewExternalWallet rootPK assuranceLevel name operation) = do
224
- let newExternalWalletHandler CreateWallet = createNewExternalWallet
225
- newExternalWalletHandler RestoreWallet = restoreExternalWallet
226
- walletMeta <- V0. CWalletMeta <$> pure name
227
- <*> migrate assuranceLevel
228
- <*> pure 0
229
- single <$> do
230
- v0wallet <- newExternalWalletHandler operation walletMeta rootPK
231
- ws <- V0. askWalletSnapshot
232
- migrateWallet ws v0wallet True
233
-
234
- -- | Creates new external wallet.
235
- createNewExternalWallet
236
- :: ( MonadThrow m
237
- , V0. MonadWalletLogic ctx m
238
- )
239
- => V0. CWalletMeta
240
- -> PublicKeyAsBase58
241
- -> m V0. CWallet
242
- createNewExternalWallet walletMeta encodedRootPK = do
243
- rootPK <- case mkPublicKeyFromBase58 encodedRootPK of
244
- Left problem -> throwM (InvalidPublicKey $ sformat build problem)
245
- Right rootPK -> return rootPK
246
-
247
- -- This extended public key will be used during synchronization
248
- -- with the blockchain.
249
- addPublicKey rootPK
250
-
251
- let walletId = encodeCType . Core. makePubKeyAddressBoot $ rootPK
252
- isReady = True -- We don't need to sync new wallet with the blockchain.
253
-
254
- -- Create new external wallet.
255
- -- This is safe: if the client will try to create an external wallet from the same
256
- -- root public key - error will be thrown.
257
- void $ V0. createWalletSafe walletId walletMeta isReady
258
-
259
- addInitAccountInExternalWallet walletId
260
-
261
- V0. getWallet walletId
262
-
263
- -- | Restore external wallet using it's root public key and metadata.
264
- restoreExternalWallet
265
- :: -- ( MonadThrow m
266
- -- , MonadUnliftIO m
267
- -- , HasLens SyncQueue ctx SyncQueue
268
- -- , V0.MonadWalletLogic ctx m
269
- -- )
270
- -- =>
271
- V0. CWalletMeta
272
- -> PublicKeyAsBase58
273
- -> m V0. CWallet
274
- restoreExternalWallet _walletMeta _encodedRootPK =
275
- error " [CHW-54], restore external wallet, unimplemented yet."
276
-
277
- addInitAccountInExternalWallet
278
- :: ( MonadThrow m
279
- , V0. MonadWalletLogic ctx m
280
- )
281
- => V0. CId V0. Wal
282
- -> m ()
283
- addInitAccountInExternalWallet walletId = do
284
- let accountName = " Initial account"
285
- accountMeta = V0. CAccountMeta accountName
286
- accountInit = V0. CAccountInit accountMeta walletId
287
- includeUnready = True
288
- void $ V0. newExternalAccountIncludeUnready includeUnready accountInit
289
-
290
- -- | On the disk, once imported or created, there's so far not much difference
291
- -- between a wallet and an external wallet, except one: node stores a public key
292
- -- for external wallet, there's no secret key.
293
- deleteExternalWallet
294
- :: (V0. MonadWalletLogic ctx m )
295
- => PublicKeyAsBase58
296
- -> m NoContent
297
- deleteExternalWallet encodedRootPK =
298
- case V1. mkPublicKeyFromBase58 encodedRootPK of
299
- Left problem -> throwM (InvalidPublicKey $ sformat build problem)
300
- Right rootPK -> V0. deleteExternalWallet rootPK
301
-
302
- migrateWallet
303
- :: ( V0. MonadWalletLogicRead ctx m
304
- , V0. MonadBlockchainInfo m
305
- )
306
- => V0. WalletSnapshot
307
- -> V0. CWallet
308
- -> Bool
309
- -> m Wallet
310
- migrateWallet snapshot wallet walletIsReady = do
311
- let walletId = V0. cwId wallet
312
- walletInfo <- if walletIsReady
313
- then maybeThrow WalletNotFound $ V0. getWalletInfo walletId snapshot
314
- else
315
- -- Wallet is not ready yet (because of restoring),
316
- -- the only information we can provide is the default one.
317
- pure $ V0. getUnreadyWalletInfo snapshot
318
- walletIsExternal <- V0. isWalletExternal walletId
319
- let walletType = if walletIsExternal then WalletExternal else WalletRegular
320
- currentDepth <- V0. networkChainDifficulty
321
- migrate (wallet, walletInfo, walletType, currentDepth)
0 commit comments