Skip to content
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

Add TxMeta type #114

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as proposed by @KtorZ , we are going to try to use generic-lens and light lensing as described here https://hackage.haskell.org/package/generic-lens with as little as possible:

  • ^.
  • .~
  • %~

This is experimental

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RankNTypes #-}
Expand Down Expand Up @@ -29,6 +30,7 @@ module Cardano.Wallet.Primitive.Types
, Tx(..)
, TxIn(..)
, TxOut(..)
, TxMeta(..)
, txIns
, updatePending

Expand Down Expand Up @@ -74,8 +76,12 @@ import Data.ByteString.Base58
( bitcoinAlphabet, encodeBase58 )
import Data.Map.Strict
( Map )
import Data.Quantity
( Quantity (..) )
import Data.Set
( Set )
import Data.Time
( UTCTime )
import Data.Word
( Word16, Word32, Word64 )
import Fmt
Expand All @@ -93,6 +99,8 @@ import GHC.Generics
( Generic )
import GHC.TypeLits
( Symbol )
import Numeric.Natural
( Natural )

import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
Expand Down Expand Up @@ -212,6 +220,29 @@ instance Buildable TxOut where
instance Buildable (TxIn, TxOut) where
build (txin, txout) = build txin <> " ==> " <> build txout

data TxMeta = TxMeta
{ txId :: !(Hash "Tx")
, depth :: !(Quantity "block" Natural)
Copy link
Contributor Author

@akegalj akegalj Mar 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to keep types in Primitives in their optimized form , thus opting for a bit more performant type like Word64?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimizations between Natural vs Word64 is pointless at this stage. Writing an algorithm that goes in O(n²) will cause us some trouble. Using Natural instead of Word64 won't probably have any noticeable effects on a wallet.

If so, we should measure it first and have a baseline to compare with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave it to Natural then because its a safer type. If there will be some evidence that this should be optimized more we can then measure and optimize

, status :: !TxStatus
, direction :: !Direction
, timestamp :: !Timestamp
, slotId :: !SlotId
} deriving (Show, Eq, Generic)

data TxStatus
= Pending
| InLedger
| Invalidated
deriving (Show, Eq, Generic)

data Direction
= Outgoing
| Incoming
deriving (Show, Eq, Generic)

newtype Timestamp = Timestamp
{ getTimestamp :: UTCTime
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the old wallet we used Microsecond which at this point seems like not needed.

} deriving (Show, Generic, Eq, Ord)

-- * Address

Expand Down