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