Skip to content
Permalink
Browse files

extend API with 'forceResync' operation

- Added a 'forceResync' link
- Extended the servant Client
- Provide an initial straightforward implementation re-using 'rollbackBlocks'
  • Loading branch information
KtorZ committed Jan 14, 2020
1 parent 2b8b98c commit 1a710729aefd0421955d909dfabfd86e9440eda3
@@ -74,6 +74,7 @@ module Cardano.Wallet
, updateWalletPassphrase
, walletSyncProgress
, fetchRewardBalance
, rollbackBlocks
, ErrWalletAlreadyExists (..)
, ErrNoSuchWallet (..)
, ErrListUTxOStatistics (..)
@@ -24,6 +24,7 @@ module Cardano.Wallet.Api
, PutWallet
, PutWalletPassphrase
, GetUTxOsStatistics
, ForceResyncWallet

, Addresses
, ListAddresses
@@ -49,6 +50,7 @@ module Cardano.Wallet.Api
, GetByronWallet
, ListByronWallets
, PostByronWallet
, ForceResyncByronWallet

, ByronTransactions
, ListByronTransactions
@@ -192,6 +194,7 @@ type Wallets =
:<|> PutWallet
:<|> PutWalletPassphrase
:<|> GetUTxOsStatistics
:<|> ForceResyncWallet

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/deleteWallet
type DeleteWallet = "wallets"
@@ -232,6 +235,12 @@ type GetUTxOsStatistics = "wallets"
:> "utxos"
:> Get '[JSON] ApiUtxoStatistics

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/forceResync
type ForceResyncWallet = "wallets"
:> Capture "walletId" (ApiT WalletId)
:> "utxos"
:> DeleteNoContent '[Any] NoContent

{-------------------------------------------------------------------------------
Addresses
@@ -362,6 +371,7 @@ type ByronWallets =
:<|> DeleteByronWallet
:<|> GetByronWallet
:<|> ListByronWallets
:<|> ForceResyncByronWallet

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/postByronWallet
type PostByronWallet (style :: ByronWalletStyle) = "byron-wallets"
@@ -383,6 +393,12 @@ type GetByronWallet = "byron-wallets"
type ListByronWallets = "byron-wallets"
:> Get '[JSON] [ApiByronWallet]

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/forceResyncByron
type ForceResyncByronWallet = "byron-wallets"
:> Capture "walletId" (ApiT WalletId)
:> "utxos"
:> DeleteNoContent '[Any] NoContent

{-------------------------------------------------------------------------------
Byron Transactions
@@ -103,6 +103,9 @@ data WalletClient t = WalletClient
:: ApiT WalletId
-> WalletPutPassphraseData
-> ClientM NoContent
, forceResyncWallet
:: ApiT WalletId
-> ClientM NoContent
, listTransactions
:: ApiT WalletId
-> Maybe Iso8601Time
@@ -167,6 +170,7 @@ walletClient =
:<|> _putWallet
:<|> _putWalletPassphrase
:<|> _getWalletUtxoStatistics
:<|> _forceResyncWallet
= wallets

_listAddresses =
@@ -200,6 +204,7 @@ walletClient =
, postWallet = _postWallet
, putWallet = _putWallet
, putWalletPassphrase = _putWalletPassphrase
, forceResyncWallet = _forceResyncWallet
, listTransactions = _listTransactions
, postTransaction = _postTransaction
, postExternalTransaction = _postExternalTransaction
@@ -48,6 +48,7 @@ module Cardano.Wallet.Api.Link
, getUTxOsStatistics
, getMigrationInfo
, migrateWallet
, forceResyncWallet

-- * Addresses
, listAddresses
@@ -241,6 +242,19 @@ getMigrationInfo w =
where
wid = w ^. typed @(ApiT WalletId)

forceResyncWallet
:: forall style w.
( HasType (ApiT WalletId) w
, Discriminate style
)
=> w
-> (Method, Text)
forceResyncWallet w = discriminate @style
(endpoint @Api.ForceResyncWallet (wid &))
(endpoint @Api.ForceResyncByronWallet (wid &))
where
wid = w ^. typed @(ApiT WalletId)

--
-- Addresses
--
@@ -458,6 +458,7 @@ server byron icarus shelley spl =
:<|> putWallet shelley mkShelleyWallet
:<|> putWalletPassphrase shelley
:<|> getUTxOsStatistics shelley
:<|> forceResyncWallet shelley

addresses :: Server (Addresses n)
addresses = listAddresses shelley
@@ -495,6 +496,10 @@ server byron icarus shelley spl =
:<|> liftA2 (\xs ys -> fmap fst $ sortOn snd $ xs ++ ys)
(listWallets byron mkLegacyWallet)
(listWallets icarus mkLegacyWallet)
:<|> (\wid -> withLegacyLayer wid
(byron , forceResyncWallet byron wid)
(icarus, forceResyncWallet icarus wid)
)

byronTransactions :: Server (ByronTransactions n)
byronTransactions =
@@ -877,6 +882,17 @@ getUTxOsStatistics ctx (ApiT wid) = do
where
liftE = throwE . ErrListUTxOStatisticsNoSuchWallet

forceResyncWallet
:: forall ctx s t k.
( ctx ~ ApiLayer s t k
)
=> ctx
-> ApiT WalletId
-> Handler NoContent
forceResyncWallet ctx (ApiT wid) = do
liftHandler $ withWorkerCtx ctx wid throwE $ \wrk ->
W.rollbackBlocks wrk wid W.slotMinBound
pure NoContent

{-------------------------------------------------------------------------------
Coin Selections

0 comments on commit 1a71072

Please sign in to comment.
You can’t perform that action at this time.