Skip to content

Commit

Permalink
[ADP-3443] Use new TxHistory in address ui page (#4823)
Browse files Browse the repository at this point in the history
- Change the definition of TxHistory in the deposit wallet state
- Use the new definition of TxHistory in the address page of the web UI
- Uses the mock TxHistory value in the UI, as the network sync is not
ready yet
- Re-implement the down-to-earth interfaces over TxHistory used in the
Exchanges scenarios

ADP-3443
  • Loading branch information
paolino authored Oct 28, 2024
2 parents 5b726d9 + f445660 commit 0178bd8
Show file tree
Hide file tree
Showing 15 changed files with 503 additions and 433 deletions.
1 change: 0 additions & 1 deletion lib/customer-deposit-wallet/customer-deposit-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ library rest
, bytestring
, cardano-addresses
, cardano-crypto
, containers
, contra-tracer
, crypto-primitives
, customer-deposit-wallet
Expand Down
56 changes: 27 additions & 29 deletions lib/customer-deposit-wallet/rest/Cardano/Wallet/Deposit/REST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ module Cardano.Wallet.Deposit.REST

-- ** Mapping between customers and addresses
, listCustomers
, customerAddress
, addressToCustomer

-- ** Reading from the blockchain
, getWalletTip
, availableBalance
, getCustomerHistory
, getValueTransfers
, getTxHistoryByCustomer
, getTxHistoryByTime
, WalletIO.ResolveAddress

-- ** Writing to the blockchain
, createPayment
Expand All @@ -46,8 +49,6 @@ module Cardano.Wallet.Deposit.REST
, walletPublicIdentity
, deleteWallet
, deleteTheDepositWalletOnDisk
, customerAddress
, getValueTransfersWithTxIds
) where

import Prelude
Expand All @@ -74,6 +75,10 @@ import Cardano.Wallet.Deposit.Pure
, Word31
, fromXPubAndGenesis
)
import Cardano.Wallet.Deposit.Pure.API.TxHistory
( ByCustomer
, ByTime
)
import Cardano.Wallet.Deposit.Read
( Address
)
Expand Down Expand Up @@ -111,9 +116,6 @@ import Data.ByteArray.Encoding
import Data.List
( isPrefixOf
)
import Data.Map.Strict
( Map
)
import Data.Store
( Store (..)
, newStore
Expand All @@ -128,7 +130,6 @@ import System.FilePath

import qualified Cardano.Wallet.Deposit.IO as WalletIO
import qualified Cardano.Wallet.Deposit.IO.Resource as Resource
import qualified Cardano.Wallet.Deposit.Pure as Wallet
import qualified Cardano.Wallet.Deposit.Read as Read
import qualified Cardano.Wallet.Deposit.Write as Write
import qualified Data.ByteString.Char8 as B8
Expand Down Expand Up @@ -157,7 +158,8 @@ data ErrDatabase
deriving (Show, Eq)

-- | Mutable resource that may hold a 'WalletInstance'.
type WalletResource = Resource.Resource ErrDatabase WalletIO.WalletInstance
type WalletResource =
Resource.Resource ErrDatabase WalletIO.WalletInstance

-- | Error indicating that the 'WalletResource' does not hold a wallet.
data ErrWalletResource
Expand Down Expand Up @@ -185,7 +187,8 @@ instance Show ErrWalletResource where
ErrAlreadyClosing -> "Wallet is already closing"

-- | Monad for acting on a 'WalletResource'.
type WalletResourceM = ReaderT WalletResource (ExceptT ErrWalletResource IO)
type WalletResourceM =
ReaderT WalletResource (ExceptT ErrWalletResource IO)

-- | Run a 'WalletResourceM' action on a 'WalletResource'.
runWalletResourceM
Expand Down Expand Up @@ -290,7 +293,8 @@ loadWallet
-- ^ Path to the wallet database directory
-> WalletResourceM ()
loadWallet bootEnv dir = do
let action :: (WalletIO.WalletInstance -> IO b) -> IO (Either ErrDatabase b)
let action
:: (WalletIO.WalletInstance -> IO b) -> IO (Either ErrDatabase b)
action f = findTheDepositWalletOnDisk dir $ \case
Right wallet ->
Right
Expand Down Expand Up @@ -318,7 +322,8 @@ initXPubWallet
-- ^ Max number of users ?
-> WalletResourceM ()
initXPubWallet tr bootEnv dir xpub users = do
let action :: (WalletIO.WalletInstance -> IO b) -> IO (Either ErrDatabase b)
let action
:: (WalletIO.WalletInstance -> IO b) -> IO (Either ErrDatabase b)
action f = createTheDepositWalletOnDisk tr dir xpub users $ \case
Just wallet -> do
fmap Right
Expand Down Expand Up @@ -369,6 +374,9 @@ listCustomers = onWalletInstance WalletIO.listCustomers
customerAddress :: Customer -> WalletResourceM (Maybe Address)
customerAddress = onWalletInstance . WalletIO.customerAddress

addressToCustomer :: WalletResourceM WalletIO.ResolveAddress
addressToCustomer = onWalletInstance WalletIO.addressToCustomer

{-----------------------------------------------------------------------------
Operations
Reading from the blockchain
Expand All @@ -379,23 +387,13 @@ getWalletTip = onWalletInstance WalletIO.getWalletTip
availableBalance :: WalletResourceM Read.Value
availableBalance = onWalletInstance WalletIO.availableBalance

getCustomerHistory
:: Customer
-> WalletResourceM (Map Read.TxId Wallet.TxSummary)
getCustomerHistory = onWalletInstance . WalletIO.getCustomerHistory

getValueTransfers
:: WalletResourceM (Map Read.Slot (Map Address Wallet.ValueTransfer))
getValueTransfers = onWalletInstance WalletIO.getValueTransfers

getValueTransfersWithTxIds
:: WalletResourceM
( Map
Read.Slot
(Map Address (Map Read.TxId Wallet.ValueTransfer))
)
getValueTransfersWithTxIds =
onWalletInstance WalletIO.getValueTransfersWithTxIds
getTxHistoryByCustomer
:: WalletResourceM ByCustomer
getTxHistoryByCustomer = onWalletInstance WalletIO.getTxHistoryByCustomer

getTxHistoryByTime
:: WalletResourceM ByTime
getTxHistoryByTime = onWalletInstance WalletIO.getTxHistoryByTime

{-----------------------------------------------------------------------------
Operations
Expand Down
59 changes: 42 additions & 17 deletions lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@ module Cardano.Wallet.Deposit.IO
-- ** Mapping between customers and addresses
, listCustomers
, customerAddress
, addressToCustomer
, ResolveAddress

-- ** Reading from the blockchain
, getWalletTip
, availableBalance
, getCustomerHistory
, getValueTransfers
, getTxHistoryByCustomer
, getTxHistoryByTime
, getCustomerDeposits
, getAllDeposits

-- ** Writing to the blockchain
, createPayment
, getBIP32PathsForOwnedInputs
, signTxBody
, WalletStore
, walletPublicIdentity
, getValueTransfersWithTxIds
) where

import Prelude
Expand All @@ -45,15 +48,19 @@ import Cardano.Wallet.Address.BIP32
)
import Cardano.Wallet.Deposit.Pure
( Customer
, TxSummary
, ValueTransfer
, WalletPublicIdentity (..)
, WalletState
, Word31
)
import Cardano.Wallet.Deposit.Pure.API.TxHistory
( ByCustomer
, ByTime
)
import Cardano.Wallet.Deposit.Read
( Address
, Slot
, TxId
, WithOrigin
)
import Cardano.Wallet.Network.Checkpoints.Policy
( defaultPolicy
Expand All @@ -71,6 +78,9 @@ import Data.List.NonEmpty
import Data.Map.Strict
( Map
)
import Data.Time
( UTCTime
)

import qualified Cardano.Wallet.Deposit.IO.Network.Type as Network
import qualified Cardano.Wallet.Deposit.Pure as Wallet
Expand Down Expand Up @@ -217,6 +227,13 @@ walletPublicIdentity w = do
, pubNextUser = Wallet.trackedCustomers state
}

type ResolveAddress = Address -> Maybe Customer

addressToCustomer :: WalletInstance -> IO ResolveAddress
addressToCustomer w = do
state <- readWalletState w
pure $ flip Wallet.addressToCustomer state

{-----------------------------------------------------------------------------
Operations
Reading from the blockchain
Expand All @@ -229,20 +246,27 @@ availableBalance :: WalletInstance -> IO Read.Value
availableBalance w =
Wallet.availableBalance <$> readWalletState w

getCustomerHistory :: Customer -> WalletInstance -> IO (Map Read.TxId TxSummary)
getCustomerHistory c w =
Wallet.getCustomerHistory c <$> readWalletState w
getTxHistoryByCustomer :: WalletInstance -> IO ByCustomer
getTxHistoryByCustomer w =
Wallet.getTxHistoryByCustomer <$> readWalletState w

getTxHistoryByTime :: WalletInstance -> IO ByTime
getTxHistoryByTime w = Wallet.getTxHistoryByTime <$> readWalletState w

getValueTransfers
getCustomerDeposits
:: WalletInstance
-> IO (Map Slot (Map Address ValueTransfer))
getValueTransfers w = Wallet.getValueTransfers <$> readWalletState w
-> Customer
-> Maybe (WithOrigin UTCTime, WithOrigin UTCTime)
-> IO (Map TxId ValueTransfer)
getCustomerDeposits w c i =
Wallet.getCustomerDeposits c i <$> readWalletState w

getValueTransfersWithTxIds
getAllDeposits
:: WalletInstance
-> IO (Map Slot (Map Address (Map Read.TxId ValueTransfer)))
getValueTransfersWithTxIds w =
Wallet.getValueTransfersWithTxIds <$> readWalletState w
-> Maybe (WithOrigin UTCTime, WithOrigin UTCTime)
-> IO (Map Customer ValueTransfer)
getAllDeposits w i =
Wallet.getAllDeposits i <$> readWalletState w

rollForward
:: WalletInstance -> NonEmpty (Read.EraValue Read.Block) -> tip -> IO ()
Expand All @@ -251,7 +275,8 @@ rollForward w blocks _nodeTip =
$ Delta.update
$ Delta.Replace . Wallet.rollForwardMany blocks

rollBackward :: WalletInstance -> Read.ChainPoint -> IO Read.ChainPoint
rollBackward
:: WalletInstance -> Read.ChainPoint -> IO Read.ChainPoint
rollBackward w point =
onWalletState w
$ Delta.updateWithResult
Expand Down Expand Up @@ -280,4 +305,4 @@ signTxBody txbody w = Wallet.signTxBody txbody <$> readWalletState w
------------------------------------------------------------------------------}
data WalletLog
= WalletLogDummy
deriving Show
deriving (Show)
Loading

0 comments on commit 0178bd8

Please sign in to comment.