-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Finalize filtering in listTransactions
by converting Range UTCTime
to Range SlotId
#595
Changes from all commits
0753e8b
dbf8d9e
4f44c1f
6a2a407
7f3cc4d
a617827
23b6fe3
d0b97b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,7 @@ import Cardano.Wallet.Primitive.Types | |
, Direction (..) | ||
, EpochLength (..) | ||
, Hash (..) | ||
, Range (..) | ||
, SlotId (..) | ||
, SlotId (..) | ||
, SlotLength (..) | ||
|
@@ -134,6 +135,7 @@ import Cardano.Wallet.Primitive.Types | |
, WalletState (..) | ||
, computeUtxoStatistics | ||
, log10 | ||
, slotAt | ||
, slotDifference | ||
, slotRatio | ||
, slotStartTime | ||
|
@@ -152,7 +154,7 @@ import Control.Concurrent.MVar | |
import Control.DeepSeq | ||
( NFData ) | ||
import Control.Monad | ||
( forM, unless, when ) | ||
( forM, unless ) | ||
import Control.Monad.IO.Class | ||
( MonadIO, liftIO ) | ||
import Control.Monad.Trans.Class | ||
|
@@ -376,8 +378,8 @@ data ErrListTransactions | |
-- | Indicates that the specified start time is later than the specified end | ||
-- time. | ||
data ErrStartTimeLaterThanEndTime = ErrStartTimeLaterThanEndTime | ||
{ startTime :: UTCTime | ||
, endTime :: UTCTime | ||
{ errStartTime :: UTCTime | ||
, errEndTime :: UTCTime | ||
} deriving (Show, Eq) | ||
|
||
{------------------------------------------------------------------------------- | ||
|
@@ -460,10 +462,10 @@ newWalletLayer tracer bp db nw tl = do | |
where | ||
BlockchainParameters | ||
block0 | ||
block0Date | ||
startTime | ||
feePolicy | ||
(SlotLength slotLength) | ||
slotsPerEpoch | ||
slotLength | ||
epochLength | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed for consistency in naming with the Primitive.Types module. |
||
txMaxSize = bp | ||
|
||
logDebugT :: MonadIO m => Text -> m () | ||
|
@@ -616,7 +618,8 @@ newWalletLayer tracer bp db nw tl = do | |
restoreSleep t wid slot = do | ||
-- NOTE: Conversion functions will treat 'NominalDiffTime' as | ||
-- picoseconds | ||
let halfSlotLengthDelay = fromEnum slotLength `div` 2000000 | ||
let (SlotLength s) = slotLength | ||
let halfSlotLengthDelay = fromEnum s `div` 2000000 | ||
threadDelay halfSlotLengthDelay | ||
runExceptT (networkTip nw) >>= \case | ||
Left e -> do | ||
|
@@ -656,7 +659,7 @@ newWalletLayer tracer bp db nw tl = do | |
splitAt (length blocks - 1) blocks | ||
liftIO $ logDebug t $ pretty (h ++ q) | ||
let (txs, cp') = applyBlocks @s @t (h ++ q) cp | ||
let progress = slotRatio slotsPerEpoch sup tip | ||
let progress = slotRatio epochLength sup tip | ||
let status' = if progress == maxBound | ||
then Ready | ||
else Restoring progress | ||
|
@@ -753,17 +756,26 @@ newWalletLayer tracer bp db nw tl = do | |
-> SortOrder | ||
-> ExceptT ErrListTransactions IO [TransactionInfo] | ||
_listTransactions wid mStart mEnd order = do | ||
guardRange (mStart, mEnd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. factored out for readability. |
||
(w, _) <- withExceptT ErrListTransactionsNoSuchWallet $ _readWallet wid | ||
case (mStart, mEnd) of | ||
(Just start, Just end) -> when (start > end) $ throwE $ | ||
ErrListTransactionsStartTimeLaterThanEndTime $ | ||
ErrStartTimeLaterThanEndTime start end | ||
_ -> pure () | ||
let tip = currentTip w ^. #slotId | ||
let range = Range | ||
{ rStart = slotAt epochLength slotLength startTime <$> mStart | ||
, rEnd = slotAt epochLength slotLength startTime <$> mEnd | ||
} | ||
liftIO $ assemble tip | ||
<$> DB.readTxHistory db (PrimaryKey wid) | ||
order wholeRange | ||
<$> DB.readTxHistory db (PrimaryKey wid) order range | ||
where | ||
guardRange | ||
:: (Maybe UTCTime, Maybe UTCTime) | ||
-> ExceptT ErrListTransactions IO () | ||
guardRange = \case | ||
(Just start, Just end) | start > end -> do | ||
let err = ErrStartTimeLaterThanEndTime start end | ||
throwE (ErrListTransactionsStartTimeLaterThanEndTime err) | ||
_ -> | ||
pure () | ||
|
||
-- This relies on DB.readTxHistory returning all necessary transactions | ||
-- to assemble coin selection information for outgoing payments. | ||
-- To reliably provide this information, it should be looked up when | ||
|
@@ -781,7 +793,7 @@ newWalletLayer tracer bp db nw tl = do | |
, txInfoOutputs = W.outputs @t tx | ||
, txInfoMeta = meta | ||
, txInfoDepth = | ||
slotDifference slotsPerEpoch tip (meta ^. #slotId) | ||
slotDifference epochLength tip (meta ^. #slotId) | ||
, txInfoTime = txTime (meta ^. #slotId) | ||
} | ||
txOuts = Map.fromList | ||
|
@@ -796,10 +808,7 @@ newWalletLayer tracer bp db nw tl = do | |
-- assume that the transaction "happens" at the start of the | ||
-- slot. This is purely arbitrary and in practice, any time between | ||
-- the start of a slot and the end could be a validate candidate. | ||
txTime = slotStartTime | ||
slotsPerEpoch | ||
(SlotLength slotLength) | ||
block0Date | ||
txTime = slotStartTime epochLength slotLength startTime | ||
|
||
_signTx | ||
:: (Show s, NFData s, IsOwned s, GenChange s) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to avoid name clash.