Skip to content

Commit

Permalink
Merge #1387
Browse files Browse the repository at this point in the history
1387: Improve on delegation logging r=paweljakubas a=paweljakubas

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->
#1376 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] I have updated how delegation is logged
- [x] I have formtatted UTXTime in wallet creation, ie., cut milliseconds 

# Comments

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: Pawel Jakubas <pawel.jakubas@iohk.io>
  • Loading branch information
iohk-bors[bot] and paweljakubas committed Feb 26, 2020
2 parents 0fdf956 + d95034c commit c1ab33d
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions lib/core/src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
Expand Down Expand Up @@ -224,6 +223,8 @@ import Data.Text.Class
)
import Data.Time.Clock
( NominalDiffTime, UTCTime, addUTCTime, diffUTCTime )
import Data.Time.Format
( defaultTimeLocale, formatTime )
import Data.Word
( Word16, Word32, Word64 )
import Data.Word.Odd
Expand All @@ -237,6 +238,7 @@ import Fmt
, indentF
, ordinalF
, prefixF
, pretty
, suffixF
, tupleF
)
Expand Down Expand Up @@ -288,10 +290,14 @@ data WalletMetadata = WalletMetadata

instance NFData WalletMetadata

formatUTCTime :: UTCTime -> Text
formatUTCTime =
T.pack . formatTime defaultTimeLocale "%Y-%m-%d %H:%M:%S %Z"

instance Buildable WalletMetadata where
build (WalletMetadata wName wTime _ wDelegation) = mempty
<> build wName <> ", "
<> "created at " <> build wTime <> ", "
<> "created at " <> build (formatUTCTime wTime) <> ", "
<> build wDelegation

-- | Length-restricted name of a wallet
Expand Down Expand Up @@ -358,10 +364,8 @@ instance NFData WalletDelegationStatus

instance Buildable WalletDelegationStatus where
build = \case
NotDelegating ->
"not delegating"
Delegating poolId ->
"delegating to " <> build poolId
NotDelegating -> ""
Delegating poolId -> build poolId

data WalletDelegationNext = WalletDelegationNext
{ changesAt :: !EpochNo
Expand All @@ -370,8 +374,7 @@ data WalletDelegationNext = WalletDelegationNext
instance NFData WalletDelegationNext

instance Buildable WalletDelegationNext where
build (WalletDelegationNext st epoch) =
build st <> " which is expected to happen at epoch number " <> build epoch
build (WalletDelegationNext st _) = build st

data WalletDelegation = WalletDelegation
{ active :: !WalletDelegationStatus
Expand All @@ -381,15 +384,10 @@ instance NFData WalletDelegation

instance Buildable WalletDelegation where
build (WalletDelegation act []) =
"current wallet delegation: " <> build act <> ", awaiting no change"
build (WalletDelegation act [n]) =
"current wallet delegation: " <> build act <> ", awaiting " <> build n
build (WalletDelegation act [n1, n2]) =
"current wallet delegation: " <> build act <> ", awaiting first " <>
build n1 <> " then awaiting " <> build n2
build (WalletDelegation act _) =
"current wallet delegation: " <> build act <>
", something wrong with awaiting"
"delegating to " <> build act
build (WalletDelegation act xs) =
build (WalletDelegation act []) <> ""
<> build (T.intercalate "" $ pretty <$> xs)

class IsDelegatingTo a where
isDelegatingTo :: (PoolId -> Bool) -> a -> Bool
Expand Down

0 comments on commit c1ab33d

Please sign in to comment.